void ICACHE_FLASH_ATTR switchAction(int action) { switch (action) { case 1: nextEntry(); if (lightCount >= 1) lightOn(); // Keep on if already on break; case 2: lightOn(); break; case 3: lightOff(); break; case 4: printAll(); break; case 5: checkSmartConfig(SC_TOGGLE); break; case 6: { int i; for (i = 0; i < FILTER_COUNT; i++) { os_printf("f[%d]->%s\n", i, sysCfg.filters[i]); } } break; } }
// the previous version of set inline void set(byte pin, boolean state) { if (state) { lightOn(pin); } else { lightOff(pin); } }
void process(void *context) { uint8 l = 0; if (SerialUSB.available()) { l = SerialUSB.read(); if (l == 'S') { debug("\'S\' stop Kaa client\r\n"); if (kaa_client) kaa_client_stop(kaa_client); } } if (light_blink_counter >= 0) { if ((millis() - light_blink_time) >= LIGHT_BLINK_TIME) { light_blink_counter++; light_blink_time = millis(); if ((light_blink_counter % 2) == 0) { lightOn(true, true); } else { lightOff(true, true); } } if (light_blink_counter > LIGHT_BLINK_NUMBER) { lightOff(true, true); light_blink_counter = -1; } } readRFID(); }
LOCAL void ICACHE_FLASH_ATTR initDone_cb() { CFG_Load(); os_printf("\n%s starting ...\n", sysCfg.deviceName); MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security); MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); char temp[100]; os_sprintf(temp, "/Raw/%s/offline", sysCfg.device_id); MQTT_InitLWT(&mqttClient, temp, "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnData(&mqttClient, mqttDataCb); os_printf("SDK version is: %s\n", system_get_sdk_version()); os_printf("Smart-Config version is: %s\n", smartconfig_get_version()); system_print_meminfo(); os_printf("Flash size map %d; id %lx\n", system_get_flash_size_map(), spi_flash_get_id()); WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, sysCfg.deviceName, wifiConnectCb); lcdInit(); lightOn(); showString(1, 1, "MQTT Monitor"); }
void activitySimStart() { TCCR4B = (TCCR4B | 0b00000101); // Preescaler sættes til 1024. TCCR4B = (TCCR4B & 0b11111101); // simTime = generateNewSimTime(); lightOn(); activityClockReset(); }
void LedCube::lightPulse(byte lv, byte col, unsigned int wait) { lightOn(lv, col); if(!bufferEnabled) { delay(wait); lightOff(lv, col); } }
void user_init(void) { gpio_init(); stdout_init(); easygpio_pinMode(LCD_Light, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(LCD_SCE, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(LCD_clk, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(LCD_Data, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(LCD_D_C, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(LCD_RST, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(SWITCH, EASYGPIO_PULLUP, EASYGPIO_INPUT); easygpio_outputDisable(SWITCH); lcdReset(); lightOn(); wifi_station_set_auto_connect(false); wifi_station_set_reconnect_policy(true); system_init_done_cb(&initDone_cb); }
void sendRFIDLog(rfid_t rfid) { light_blink_time = millis(); lightOn(true, true); light_blink_counter = 0; kaa_context_t *kaa_context = kaa_client_get_context(kaa_client); kaa_user_log_record_t *log_record = kaa_logging_rfid_log_create(); if (log_record) { log_record->tag = rfid; kaa_error_t error = kaa_logging_add_record(kaa_context->log_collector, log_record); if (error) { debug("Failed to add log record, code %d\r\n", error); } else { debug("Log record sent\r\n"); } log_record->destroy(log_record); } else { debug("Failed to allocate log record\r\n"); } }
// time is overall, gap is in between individual lights void LedCube::lightSequence(byte seq[], byte length, unsigned int time, byte gap) { // should be pairs of coords if(length%2){ return; } if(bufferEnabled){ time = 1; } //Serial.print('{'); for (unsigned int d=0; d<time; d++) { for (byte s=0; s<length; s+=2) { if(bufferEnabled){ lightOn(seq[s], seq[s+1]); } else { lightPulse(seq[s],seq[s+1], gap); } //Serial.print(seq[s],DEC); if(s < length-1) Serial.print(', '); } } //Serial.println('}'); }
void Insteon::switch_callback(RESTContext* context) { RESTParameters* params = context->params; Dumais::JSON::JSON& json = context->returnData; InsteonID id = strtoul(params->getParam("id").c_str(),0,16); unsigned char subdev = 0; if (params->getParam("subdev")!="") { subdev = strtoul(params->getParam("subdev").c_str(),0,10); } if (params->getParam("action")=="on"){ unsigned char level =255; if (params->getParam("level")!="") level = atoi(params->getParam("level").c_str()); if (params->getParam("rate")!="") level = atoi(params->getParam("rate").c_str()); lightOn(id,level,subdev); } else if (params->getParam("action")=="off"){ lightOff(id,subdev); } else if (params->getParam("action")=="toggle"){ lightToggle(id,subdev); } json.addValue("ok","status"); }
void ICACHE_FLASH_ATTR startFlash(int t, int repeat) { lightOn(); os_timer_disarm(&flash_timer); os_timer_setfn(&flash_timer, (os_timer_func_t *) smartConfigFlash_cb, (void *) 0); os_timer_arm(&flash_timer, t, repeat); }
void ICACHE_FLASH_ATTR smartConfigFlash_cb(void) { if (lightCount > 0) lightOff(); else lightOn(); }