Skip to content

Instantly share code, notes, and snippets.

@skandragon
Created December 6, 2015 18:04
Show Gist options
  • Save skandragon/f22078c2337db4b3ed18 to your computer and use it in GitHub Desktop.
Save skandragon/f22078c2337db4b3ed18 to your computer and use it in GitHub Desktop.
GE35 driver code
void wifiLoop()
{
if (!client.connected()) {
if (!server.hasClient())
return;
client = server.available();
if (client.connected())
client.setTimeout(200);
}
if (!client.connected()) {
client.stop();
return;
}
int command = client.read();
if (command == -1)
return;
//Serial.print("Command: 0x");
//Serial.println(command, HEX);
if (command == 'S') {
stringId = client.read();
} else if (command == 'L') {
uint8_t buffer[4];
int readlen = client.readBytes(buffer, sizeof buffer);
if (readlen != sizeof(buffer)) {
Serial.printf("Only read %d bytes\n", readlen);
return;
}
uint8_t lightId = buffer[0];
uint8_t brightness = buffer[1];
uint8_t rg = buffer[2];
uint8_t b = buffer[3];
if (brightness > MEOG35::MAX_INTENSITY)
brightness = MEOG35::MAX_INTENSITY;
color_t color = COLOR((rg & 0xf0) >> 4, (rg & 0x0f), b & 0x0f);
//Serial.printf("S %u, L %u, I 0x%02x, C 0x%04x\n", stringId, lightId, brightness, color);
auto string = lights[stringId];
if (string == nullptr)
Serial.println("Invalid string ID");
else
lights[stringId]->set_color(lightId, brightness, color);
} else if (command == 'R') {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment