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(); }
/** * The main function. It does the logic. * * COMMENT BRANCHER LES FILS: * Del libre + sur PORTA<0> * Del libre - sur PORTA<1> * Output du bread board sur PORTD<2> * N'importe quel vcc et gnd de la carte sur le vcc et gnd du breadboard */ int main() { initialisation(); for(;;) { do { // attendre qu'une des deux variables soit modifiée // par une ou l'autre des interruptions. //(PIND & _BV(PORTD2)) == true if button is not pressed // We want to interate as long as the button is pressed, if it has been pressed (compteur > 1) } while (compteur <= 120 && (!(PIND & _BV(PORTD2)) || compteur == 0)); arreterMinuterie(); // Une interruption s'est produite. Arreter toute // forme d'interruption. Une seule reponse suffit. cli (); // Blink green for 1/2 seconds, at 2 Hz lightOnGreen(); msleep(500); // Wait 2 seconds lightOff(); msleep(2000); // Blink red (counter/2) times at 2 Hz for (uint8_t i = 0; i < compteur/2; i++) { lightOnRed(); msleep(250); lightOff(); msleep(250); } // Turn on green light for a second lightOnGreen(); msleep(1000); lightOff(); compteur = 0; // Réactive les interruptions sei (); } return 0; }
// the previous version of set inline void set(byte pin, boolean state) { if (state) { lightOn(pin); } else { lightOff(pin); } }
/** * The main function. It does the logic. */ int main() { initialisation(); _delay_ms(1000); lightOnRed(); _delay_ms(100); lightOff(); partirMinuterie(7812); //minuterieExpiree = 1; do { // attendre qu'une des deux variables soit modifiée // par une ou l'autre des interruptions. } while ( minuterieExpiree == 0 && boutonPoussoir == 0 ); // Une interruption s'est produite. arreter toute // forme d'interruption. Une seule reponse suffit. cli (); // Verifier la reponse if ( minuterieExpiree == 1 ) { for(;;) { lightOnRed(); } } else { for(;;) { lightOnGreen(); } } return 0; }
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; } }
void LedCube::lightPulse(byte lv, byte col, unsigned int wait) { lightOn(lv, col); if(!bufferEnabled) { delay(wait); lightOff(lv, col); } }
void ICACHE_FLASH_ATTR switchTimerCb(uint32_t *args) { const swOnMax = 100; const swOffMax = 5; static int switchPulseCount; static enum { IDLE, ON, OFF } switchState = IDLE; if (!easygpio_inputGet(SWITCH)) { // Switch is active LOW switch (switchState) { case IDLE: switchState = ON; switchCount++; switchPulseCount = 1; break; case ON: if (++switchCount > swOnMax) switchCount = swOnMax; break; case OFF: switchState = ON; switchCount = 0; switchPulseCount++; break; default: switchState = IDLE; break; } } else { switch (switchState) { case IDLE: break; case ON: switchCount = 0; switchState = OFF; break; case OFF: if (++switchCount > swOffMax) { switchState = IDLE; switchAction(switchPulseCount); INFOP("SW action %d, light %d\n", switchPulseCount, lightCount); switchPulseCount = 0; } break; default: switchState = IDLE; break; } } if (lightCount >= 1) lightCount--; else lightOff(); }
void LedCube::lightsOut(unsigned int wait) { enableBuffer(); fillBuffer(); drawBuffer(25); for(byte w=0, l, c, max = num; w<max; ) { // lower bound is inclusive, upper is exclusive l = random(0, levels); c = random(0, cols); if(getBufferAt(l,c) == HIGH) { lightOff(l,c); drawBuffer(wait); w++; } } enableBuffer(false); }
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 mqttConnectedCb(uint32_t *args) { char topic[100]; MQTT_Client* client = (MQTT_Client*) args; mqttConnected = true; INFOP("MQTT is Connected to %s:%d\n", sysCfg.mqtt_host, sysCfg.mqtt_port); os_sprintf(topic, "/Raw/%s/set/#", sysCfg.device_id); INFOP("Subscribe to: %s\n", topic); MQTT_Subscribe(client, topic, 0); os_sprintf(topic, "/Raw/%s/+/set/filter", sysCfg.device_id); INFOP("Subscribe to: %s\n", topic); MQTT_Subscribe(client, topic, 0); MQTT_Subscribe(client, "/App/#", 0); publishDeviceInfo(client); publishData(client); os_timer_disarm(&switch_timer); os_timer_setfn(&switch_timer, (os_timer_func_t *) switchTimerCb, NULL); os_timer_arm(&switch_timer, 100, true); os_timer_disarm(&display_timer); os_timer_setfn(&display_timer, (os_timer_func_t *) displayCb, NULL); os_timer_arm(&display_timer, 2000, true); os_timer_disarm(&date_timer); os_timer_setfn(&date_timer, (os_timer_func_t *) dateTimerCb, NULL); os_timer_arm(&date_timer, 10 * 60 * 1000, false); //10 minutes os_timer_disarm(&transmit_timer); os_timer_setfn(&transmit_timer, (os_timer_func_t *) transmitCb, (void *) client); os_timer_arm(&transmit_timer, sysCfg.updates * 1000, true); lightOff(); }
/*********************************************************** 函数名称: state_trans() 函数功能: 控制电梯的状态 入口参数: 无 出口参数: 无 备 注: 使用到的全局变量 buttonUp,buttonDown,buttonNumber,currentFloor,state,nextFloor,moveDirection 其中nextFloor,moveDirection为只读 不可修改 使用自动机模型 电梯运行速度2秒每层 电梯停靠时间为4秒 ***********************************************************/ void state_trans() { static int reopen = 0;//电梯关门时按下开门键的标示 switch (state) //根据状态和事件,进行相应的处理 { case IDLE: //电梯空闲状态 if (openbutton == 1) { state = STOP;//电梯按下开门按钮进入停靠状态 } if (moveDirection != STOP) //由control函数发现有不同层响应呼叫 电梯进入运行状态 { state = RUN;//电梯进入运行状态 startIDLE = 1; } else if (currentFloor == nextFloor) //由control函数发现有同层响应呼叫 电梯进入停靠状态 { state = STOP; startIDLE = 1; } else { if (Profile == C) { if (startIDLE == 1) { a = clock(); startIDLE = 0; } else { b = clock(); c = (double) (b - a) / CLOCKS_PER_SEC; if (c > waitTime) //等待waitTime秒 { if (currentFloor != 1) { nextFloor = -1; moveDirection = DOWN; state = RUN; startIDLE = 1; } } } } else { moveDirection = STOP; } } break; case RUN://电梯运行状态 if (currentFloor == ignore)//安全运行结束 { ignore = 0; } if (nextFloor == -1 || profileCfindnextfloor == 1) { if (currentFloor != 1) //未到目标楼层 { if (startRUN == 1)//计时器开始计时 { directa = ar = clock(); startRUN = 0; } else { directb = br = clock(); cr = (double) (br - ar) / CLOCKS_PER_SEC; directc = (double) (directb - directa) / CLOCKS_PER_SEC; elevatorMove((double)cr / velocity);//电梯运行动画 if (directc >= 0.05) { directa = clock(); showDirection_run(0);//指示灯动画 } if (cr > velocity)//时间到velocity秒 { currentFloor--; profileCfindnextfloor = 0; showFloor(); elevatorMove(0); startRUN = 1; } } } if (currentFloor == 1) //电梯到达目标楼层 { nextFloor = 0; state = IDLE; moveDirection = STOP; showDirection_stop(); } } else//profileCfindnextfloor==0 { if (startRun == 1) { staticStart = clock();//统计计时 startRun = 0; } if (currentFloor != nextFloor || profileEFfindnextfloor == 1) //未到目标楼层 { if (startRUN == 1) { directa = ar = clock(); startRUN = 0; profileEFfindnextfloor = 0; } else { if (profileEFfindnextfloor == 1) { static double temptime1, temptime = 0; if (startRUNEF == 1) { br = clock(); temptime = (double) (br - ar) / CLOCKS_PER_SEC; temptime1 = temptime; ar = clock(); startRUNEF = 0; } else { directb = br = clock(); cr = (double) (br - ar) / CLOCKS_PER_SEC; directc = (double) (directb - directa) / CLOCKS_PER_SEC; temptime = temptime1 - cr; if (temptime > 0) { elevatorMove((double)(velocity - temptime) / velocity); } if (directc >= 0.05) { directa = clock(); showDirection_run(0);//指示灯动画 } if (temptime < 0) { showFloor();//显示当前楼层 profileEFfindnextfloor = 0; elevatorMove(0);//电梯运行动画 startRUNEF = 1; startRUN = 1; temptime = 0; } } } else { directb = br = clock(); cr = (double) (br - ar) / CLOCKS_PER_SEC; directc = (double) (directb - directa) / CLOCKS_PER_SEC; if (profileEFfindnextfloor == 0) { elevatorMove((double)cr / velocity);//电梯运行动画 } if (directc >= 0.05) { directa = clock(); showDirection_run(0);//指示灯动画 } if (cr > velocity) { currentFloor += moveDirection; showFloor();//显示当前楼层 if (profileEFfindnextfloor == 0) { elevatorMove(0);//电梯运行动画 } startRUN = 1; } } } } if ((currentFloor == nextFloor) && (profileEFfindnextfloor == 0)) //电梯到达目标楼层 { if (moveDirection == UP) //关闭相应的按钮 电梯进入停靠状态 { if (Profile == B)//B策略单独处理 { if (headPtr != NULL) { closeButton(); eachNumber[previousProfile]++; deleteNode(headPtr->data); } } else//关闭按钮 { if((buttonUp[currentFloor] == 0) && (buttonNumber[currentFloor] == 0)) { buttonDown[currentFloor] = 0; deleteNode(listDown[currentFloor]); lightOff(listDown[currentFloor]); eachNumber[previousProfile]++; } else//关闭按钮 { buttonUp[currentFloor] = 0; buttonNumber[currentFloor] = 0; lightOff(listUp[currentFloor]); lightOff(listNumber[currentFloor]); if (headPtr != NULL) { eachNumber[previousProfile]++; deleteNode(listUp[currentFloor]); deleteNode(listNumber[currentFloor]); } } } state = STOP; startRun = 1; staticStop = clock(); totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间 } if (moveDirection == DOWN) //关闭相应的按钮 电梯进入停靠状态 { if (Profile == B)//B策略需单独处理 { if (headPtr != NULL) { closeButton(); deleteNode(headPtr->data); eachNumber[previousProfile]++; } } else//关闭按钮 { if ((buttonDown[currentFloor] == 0) && (buttonNumber[currentFloor] == 0)) { buttonUp[currentFloor] = 0; lightOff(listUp[currentFloor]); deleteNode(listUp[currentFloor]); eachNumber[previousProfile]++; } else//关闭按钮 { buttonDown[currentFloor] = 0; buttonNumber[currentFloor] = 0; lightOff(listDown[currentFloor]); lightOff(listNumber[currentFloor]); if (headPtr != NULL) { eachNumber[previousProfile]++; deleteNode(listDown[currentFloor]); deleteNode(listNumber[currentFloor]); } } } state = STOP;//进入停靠 startRun = 1; staticStop = clock(); totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间 } if (moveDirection == STOP) //如果电梯无运行方向 电梯进入停靠状态 { state = STOP; startRun = 1; staticStop = clock(); //时间统计 totalTime[previousProfile] += (double) (staticStop - staticStart) / CLOCKS_PER_SEC;//统计时间 } } } break; case STOP: //电梯停靠状态 if (startSTOP == 1)//刚开始停靠 { DWORD ThreadIDa = 1, ThreadIDb = 2; HANDLE hReada, hReadb; as = clock();//计时器初始化 if (reopen == 1)//判断是否开门 { reopen = 0; } else { //开门动画,指示灯动画并且播放语音 hReada = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)arriveSound, NULL, 0, &ThreadIDa); hReadb = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)showDirection_stop, NULL, 0, &ThreadIDb); openDoor(); startSTOP = 0; } } else { if (openbutton == 1)//长按开门键则不关门 { as = clock(); restTime = stopTime; } else { showDirection_stop(); bs = clock(); cs = (double) (bs - as) / CLOCKS_PER_SEC; restTime = stopTime - cs; if (cs > stopTime || Go == 1)//Go指令判断 { startSTOP = 1; } } } if (startSTOP == 1) { if (nextFloor == 0) //如果无目标楼层 电梯进入空闲状态 { if (closeDoor() == 1) { state = STOP; startSTOP = 1; reopen = 1; break; } moveDirection = STOP; state = IDLE; if (Profile == B) { showDirection_stop(); } } else//有目标楼层则电梯进入运行状态 { if (closeDoor()) { state = STOP; startSTOP = 1; reopen = 1; break; } state = RUN; control(); gosound(); } } break; }//end of switch }
/** * The main function. It does the logic. */ int main() { DDRA = 0x03; // Output A DDRD = 0x00; /** * States: * RST_RED: The light is red until button press * AMB_GREEN: The light is green in amber sequence until button release * AMB_RED: The light is red in amber sequence until button release * GREEN1: The light is green until button press * RED: The light is red until button release * OFF: The light is off until button press * GREEN2: The light is green until button release * * Table of truth: * _________________________________________ * |ÉTAT PRÉSENT | A | ÉTAT SUIVANT | SORTIE | * |-----------------------------------------| * | RST_RED | 0 | RST_RED | 01 | * | RST_RED | 1 | AMB_GREEN | 01 | * | AMB_GREEN | 0 | GREEN1 | 10 | * | AMB_GREEN | 1 | AMB_RED | 10 | * | AMB_RED | 0 | GREEN1 | 01 | * | AMB_RED | 1 | AMB_GREEN | 01 | * | GREEN1 | 0 | GREEN1 | 10 | * | GREEN1 | 1 | RED | 10 | * | RED | 0 | OFF | 01 | * | RED | 1 | RED | 01 | * | OFF | 0 | OFF | 00 | * | OFF | 1 | GREEN2 | 00 | * | GREEN2 | 0 | RST_RED | 10 | * | GREEN2 | 1 | GREEN2 | 10 | * |-----------------------------------------| */ enum States { RST_RED, AMB_GREEN, AMB_RED, GREEN1, RED, OFF, GREEN2 }; // Set the initial state States state = RST_RED; for(;;) { // Check the current state, and do what it should do. switch (state) { case RST_RED: lightOnRed(); if (buttonPressed()) state = AMB_GREEN; break; case AMB_GREEN: lightOnGreen(); (buttonPressed() ? state = AMB_RED : state = GREEN1); break; case AMB_RED: lightOnRed(); (buttonPressed() ? state = AMB_GREEN : state = GREEN1); break; case GREEN1: lightOnGreen(); if (buttonPressed()) state = RED; break; case RED: lightOnRed(); if (!buttonPressed()) state = OFF; break; case OFF: lightOff(); if (buttonPressed()) state = GREEN2; break; case GREEN2: lightOnGreen(); if (!buttonPressed()) state = RST_RED; break; default: lightOnRed(); break; }; } return 0; }
void activitySimStop() { TCCR4B = (TCCR4B & 0b11111000); // Preescaler sættes til 0. lightOff(); }
void ICACHE_FLASH_ATTR smartConfigFlash_cb(void) { if (lightCount > 0) lightOff(); else lightOn(); }
void ICACHE_FLASH_ATTR stopFlash(void) { lightOff(); os_timer_disarm(&flash_timer); }