MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / SetMusicMode

Method SetMusicMode

Controllers/YeelightController/YeelightController.cpp:114–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114void YeelightController::SetMusicMode()
115{
116 json command;
117
118 char hostname[256];
119 char* ip_addr;
120 struct hostent* host_entry;
121
122 /*-----------------------------------------------------------------*\
123 | The Yeelight bulb requires this PC's local IP address for music |
124 | mode. Get the first IP address of this computer's hostname, or |
125 | use the one defined |
126 \*-----------------------------------------------------------------*/
127 if(host_ip.empty())
128 {
129 gethostname(hostname, 256);
130 host_entry = gethostbyname(hostname);
131 ip_addr = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0]));
132 }
133 else
134 {
135 ip_addr = &host_ip[0];
136 }
137
138 /*-----------------------------------------------------------------*\
139 | Fill in the set_rgb command with RGB information. |
140 | The bulb will not respond to 0, 0, 0, so if all channels are zero,|
141 | set the state to off. Otherwise, set it to on. |
142 \*-----------------------------------------------------------------*/
143 command["id"] = 1;
144 command["method"] = "set_music";
145 command["params"][0] = 1;
146 command["params"][1] = ip_addr;
147 command["params"][2] = music_mode_port;
148
149 /*-----------------------------------------------------------------*\
150 | Convert the JSON object to a string and write it |
151 \*-----------------------------------------------------------------*/
152 std::string command_str = command.dump().append("\r\n");
153
154 port.tcp_client_connect();
155 port.tcp_client_write((char *)command_str.c_str(), command_str.length() + 1);
156 port.tcp_close();
157}
158
159void YeelightController::SetPower()
160{

Callers

nothing calls this directly

Calls 6

tcp_client_connectMethod · 0.80
tcp_client_writeMethod · 0.80
tcp_closeMethod · 0.80
emptyMethod · 0.45
appendMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected