void HueLight::updateStates(const QVariantMap &statesMap) { // color mode if (statesMap.value("colormode").toString() == "hs") { setColorMode(ColorModeHS); } else if (statesMap.value("colormode").toString() == "ct") { setColorMode(ColorModeCT); } else if (statesMap.value("colormode").toString() == "xy") { setColorMode(ColorModeXY); } // effect (none, colorloop) if (statesMap.value("effect").toString() == "none") { setEffect("none"); } else if (statesMap.value("effect").toString() == "colorloop") { setEffect("color loop"); } setReachable(statesMap.value("reachable").toBool()); // alert (none, select, lselect) setAlert(statesMap.value("alert").toString()); setBrigtness(statesMap.value("bri").toInt()); setCt(statesMap.value("ct").toInt()); setPower(statesMap.value("on").toBool()); setSat(statesMap.value("sat").toInt()); setHue(statesMap.value("hue").toInt()); if (!statesMap.value("xy").toList().isEmpty()) setXy(QPointF(statesMap.value("xy").toList().first().toFloat(), statesMap.value("xy").toList().last().toFloat())); emit stateChanged(); }
void Visualight::wifiReset(){ wifly.close(); VPRINTLN(F("-WIFIRESET-")); colorLED(0,255,0,0); // THIS IS RELEASE DEPENDENT MAKE BETTER!! isServer = true; EEPROM.write(0, 1); setWiFlyLeds(1, false); //turn on, reboot wifly.reboot(); wifly.setSoftAP(); setAlert(0, 600000, 1, 0, 0, 255, 0); }
void ArpListener::waitForResponse(const std::string &ip, const timespec &timeout) { MutexLocker lock( alertMutex_ ); if(!( cache_->lookup(ip) == MACAddress( std::vector< uint8_t >( 6, 0 ) ) ) ) return; //there is a mac in the cache setAlert(ip); std::map< std::string, std::pair< Semaphore*, Condition* > >::iterator itr = alerts_.lower_bound(ip); if( itr != alerts_.end() && !(alerts_.key_comp()(ip, itr->first) ) ) { //exist itr->second.second->timeWait(alertMutex_, timeout ); } removeAlert(ip); //else the alert either already happend or didn't exists }
boolean Visualight::factoryRestore(){ pinMode(resetButton, INPUT); pinMode(resetPin,OUTPUT); digitalWrite(resetButton, HIGH); digitalWrite(resetPin, HIGH); pinMode(_red,OUTPUT); pinMode(_green, OUTPUT); pinMode(_blue, OUTPUT); #if DEBUG Serial.begin(115200); while(!Serial){ ; } #endif colorLED(255, 0, 0,0); Serial1.begin(9600); if (!wifly.begin(&Serial1,&Serial)) { VPRINTLN(F("Failed to start wifly")); } // FACTORY RESTORE WIFLY UNIT if(wifly.factoryRestore()){ wifly.setDeviceID("WiFly"); wifly.save(); VPRINTLN(F("WiFly Factory Restored. Rebooting..")); wifly.reboot(); //reset visualight eeprom EEPROM.write(0, 1); VPRINTLN(F("Visualight Factory Reset Complete !")); setAlert(0, 90000, 1, 0, 255, 0, 0); // setWiFlyLeds(1); // 1 = enable, 0 = disable green and red (GPIO 4 and 6) return true; } else { VPRINTLN(F("Failed to factoryRestore wifly")); return false; } }
/** * Destroys alert icon along with itself; */ Alertable::~Alertable() { setAlert(0); }
void Visualight::setup(char* _URL, uint16_t _PORT, uint8_t _wiflyLedFlag){ VPRINTLN(F("-SETUP-")); wiflyLedFlag = _wiflyLedFlag; URL = _URL; PORT = _PORT; //colorLED(255,255,255); fadeOn(); pinMode(resetButton, INPUT); pinMode(resetPin,OUTPUT); digitalWrite(resetButton, HIGH); digitalWrite(resetPin, HIGH); //attachInterrupt(4, processButton, CHANGE); #if DEBUG Serial.begin(115200); while(!Serial){ ; } #endif VPRINTLN(F("Starting")); VPRINT(F("Free memory: ")); int freeMem = wifly.getFreeMemory(); VPRINTLN(freeMem); Serial1.begin(9600); if (!wifly.begin(&Serial1,&Serial)) { VPRINTLN(F("Failed to start wifly")); //RESET WIFI MODULE -- Toggle reset pin } wifly.getDeviceID(devID,sizeof(devID)); if(strcmp(devID, "Visualight")==0){ VPRINTLN(F("ID SET")); } else{ VPRINTLN(F("ID NOT SET")); EEPROM.write(0,1); configureWifi(); } isServer = EEPROM.read(0); wifly.getMAC(MAC, sizeof(MAC)); VPRINT(F("MAC: ")); VPRINTLN(MAC); VPRINT(F("IP: ")); VPRINTLN(wifly.getIP(buf, sizeof(buf))); VPRINTLN(F("Ready")); if(isServer){ /* Create AP*/ VPRINTLN(F("Creating AP")); setAlert(0, 600000, 1, 0, 0, 255, 0); // Set a server timeout of 10 minutes setWiFlyLeds(1, true); VPRINTLN(F("Create server")); wifly.setSoftAP(); EEPROM.write(0, 1); } else{ VPRINTLN(F("Already Configured")); //isServer = false; if(wiflyLedFlag == 0){ setWiFlyLeds(0, true); //disable wifly LEDs, reboot }else { setWiFlyLeds(1, true); //enable wifly LEDs for debug, reboot } if(!connectToServer()){ reconnectCount++; } } }
// process all incoming server messages void Visualight::processClient(){ int available; if(millis()-lastHeartbeat > heartBeatInterval && reconnectCount == 0){ sendHeartbeat(); } if(millis()-connectTime > connectServerInterval){ VPRINTLN(F("reconnect from timeout")); //reconnect = true; //connectTime = millis(); if(!connectToServer()){ reconnectCount++; } } else { available = wifly.available(); if (available < 0) { VPRINT(F("reconnect from available()")); reconnectCount++; if(!connectToServer()){ //reconnectCount++; } } else if(available > 0){ connectTime = millis(); char thisChar; thisChar = wifly.read(); if( thisChar == 97){ wifly.readBytesUntil('x', serBuf, 31); int duration; int red, green, blue, white; sscanf(serBuf,"%i,%i,%i,%i,%i,%i,%i",&red,&green,&blue,&white,&duration,&_frequency,&_blinkType); // INDIGO v0.1.1 VPRINT("buf: "); VPRINTLN(serBuf); if(duration > 0 && _blinkType <=1){ //we are STARTING AN ALERT _durationTime = duration*1000; _frequency = (_frequency+1); //* 100; //get the right freq out //100 - 1000 setAlert(_blinkType, _durationTime, _frequency, red, green, blue, white); } else if(_blinkType == 2){ // we are setting the start color here saveStartColor(red,green,blue,white); } else if(_blinkType == 3){ // reset WiFi, become a server //this is sent from server when a bulb is deleted from a Visualight account. wifiReset(); //set isServer = true, turn on AP mode } else { //simple set color if(alerting){ _durationTime = 0; // will time out any currently running alert } setColor(red, green, blue, white); } memset(serBuf,0,31); } } } }