void mainTimerTick() { if (s_started) { if (s_timerCounter++ >= 244) { s_timerCounter = 0; ledToggle(); } if (buttonIsPressed()) { if (!s_buttonLock) { s_buttonPressed = 1; s_buttonLock = 1; } } else { s_buttonPressed = 0; s_buttonLock = 0; } } }
bool MouseInput::buttonWasReleased(MouseButton button) { if (buttonIsPressed(button) == false && buttonWasDown(button) == true) { return true; } return false; }
void SW_Button_update() { StopWatchButton id = StartButton; for (id = StartButton; id < NumOfButton; id = static_cast<StopWatchButton>(id + 1)) { button[id].wasPressed = button[id].isPressed; button[id].isPressed = buttonIsPressed(id); } return; }
/* PA0 button interrupt */ ISR(PCINT0_vect, ISR_BLOCK) { switch(opMode) { case DEEPSLEEP: /* Wake the device up, if button is pushed while in deep sleep */ if(buttonIsPressed()) /* Only on button press, not release */ { TCCR0B &= ~0x07; TCCR0B |= 0x04; /* Set Timer0 clock to mainClk/256 */ OCR1A = 10*1000; /* ~10s timeout timer for wait-mode */ TCNT1 = 0x0001; TCCR1B &= ~0x07; TCCR1B |= 0x05; /* Set Timer1 clock to mainClk/1024 */ opMode = WAITING; } break; case WAITING: /* If button is pushed while waiting, initiate roll */ if(buttonIsPressed()) /* Only on button press, not release */ { OCR1A = 0x0001; TCNT1 = 0x0000; /* Reset Timer1 to 0 */ opMode = ROLLING; } break; case ROLLING: /* If rolling and button is released, start slowing the roll */ if(!buttonIsPressed()) /* Only on button release, not press */ opMode = SLOWING; break; case SLOWING: /* If button is pressed again while the die is slowing, speed it up again */ if(buttonIsPressed()) /* Only on button press, not release */ { OCR1A = 0x0001; TCNT1 = 0x0000; /* Reset Timer1 to 0 */ opMode = ROLLING; } break; } }
int main(void) { ledInit(); buttonsInit(); loggerInit(); timerInit(); initMyExtIRQ(); if(buttonIsPressed(BUTTONNEWNOCK) == TRUE){ #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)"\r\r\r goto colibrateDetector \r*", '*'); #endif while(1) colibrateDetector(); } #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)"\r\r\r Starting program \r*", '*'); #endif initNockMachine(); #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)" iRaSeMac \r*", '*'); #endif initSendMachine(); #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)" exit iRaSeMac \r*", '*'); #endif // ledOn(LEDRED2); //timerSet(TIMER_NOCK,0,50); while(1) { //if(timerIsElapsed(TIMER_NOCK) == TRUE){ // timerSet(TIMER_NOCK,0,50); // ledTaggle(LEDRED1); //} //continue; userNewNockCommandMachine_1(); nockMachine_2(); sendMachine_3(); doorSignalMachine_4(); } }
int main() { DDRD =0xf3; // Definition du D2 en sortie DDRC =0xff; state machinePresenteState=INIT; for(;;) { // Appel de la fonction stateMachine, en lui fournissant l'etat present de la machine et l'entree (bouton poussoir presser ou non) machinePresenteState = stateMachine(machinePresenteState, buttonIsPressed()); } return 0; }
int main() { DDRD =0xf3; DDRC =0xff; // Definition du PORTC en entree state machinePresenteState=INIT; for(;;) // Infinite boucle { //Appel de la machine a etat machinePresenteState = stateMachine(machinePresenteState, buttonIsPressed()); } return 0; }
int main() { mainInit(); if (buttonIsPressed()) controllerCalibrate(); ledOn(); s_started = 1; while(1) { mainBluetooth(); mainSensors(); } return 0; }
static uint8_t debounceButtonHold(uint8_t button) { #define BUTTON_DEBOUNCE_HOLD_TIME_MS 5000 // How long to poll the button, total #define BUTTON_POLL_INTERVAL_MS 5 // How long to wait between polling button int16_t time = 0; // The amount of time that has elapsed in the debounce routine int16_t buttonOnCount = 0; // Number of times button was polled and ON int16_t buttonOffCount = 0; // Number of times button was polled and OFF while (time < BUTTON_DEBOUNCE_HOLD_TIME_MS) { if (buttonIsPressed(button)) buttonOnCount++; else buttonOffCount++; time += BUTTON_POLL_INTERVAL_MS; delayMs(BUTTON_POLL_INTERVAL_MS); } return (buttonOnCount > buttonOffCount); }
int main( void ) { halInit(); moduleInit(); printf("\r\n****************************************************\r\n"); printf("Packet Error Rate Tester - ROUTER\r\n"); buttonIsr = &handleButtonPress; #define MODULE_START_DELAY_IF_FAIL_MS 5000 /* Use the default module configuration */ struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER; /* Turn Off nwk status LED if on */ clearLed(ON_NETWORK_LED); /* Loop until module starts */ while ((result = expressStartModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION, MODULE_REGION_NORTH_AMERICA)) != MODULE_SUCCESS) { /* Module startup failed; display error and blink LED */ setLed(NETWORK_FAILURE_LED); printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS/2); clearLed(NETWORK_FAILURE_LED); delayMs(MODULE_START_DELAY_IF_FAIL_MS/2); } printf("On Network!\r\n"); /* Indicate we got on the network */ setLed(ON_NETWORK_LED); /* On network, display info about this network */ #ifdef DISPLAY_NETWORK_INFORMATION displayNetworkConfigurationParameters(); displayDeviceInformation(); #else displayBasicDeviceInformation(); #endif HAL_ENABLE_INTERRUPTS(); /* Now the network is running - send messages to the Coordinator.*/ #define TEST_CLUSTER 0x77 #define MESSAGE_HEADER_LENGTH 13 #define MESSAGE_LENGTH (TEST_MESSAGE_PAYLOAD_LENGTH + MESSAGE_HEADER_LENGTH) /* Here we precompute zmBuf contents so that we don't have to do it in the loop. This is faster. This is the equivalent of afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 10); */ uint8_t testBuf[MESSAGE_LENGTH]; testBuf[0] = MESSAGE_LENGTH; testBuf[1] = MSB(AF_DATA_REQUEST); testBuf[2] = LSB(AF_DATA_REQUEST); testBuf[3] = 0; testBuf[4] = 0; testBuf[5] = DEFAULT_ENDPOINT; testBuf[6] = DEFAULT_ENDPOINT; testBuf[7] = LSB(TEST_CLUSTER); testBuf[8] = MSB(TEST_CLUSTER); testBuf[9] = 0xFF; // Sequence: we don't care testBuf[10] = AF_MAC_ACK; //Could also use AF_APS_ACK; testBuf[11] = DEFAULT_RADIUS; testBuf[12] = TEST_MESSAGE_PAYLOAD_LENGTH; // Datalength //memcpy(testBuf+MESSAGE_HEADER_LENGTH, testMessage, TEST_MESSAGE_PAYLOAD_LENGTH); //testBuf is now loaded with our test message. printf("!! Sending %u messages !!\r\n", NUMBER_OF_PACKETS_TO_SEND); while (1) { uint16_t packetCounter; for (packetCounter = 0; packetCounter<NUMBER_OF_PACKETS_TO_SEND; packetCounter++) { /* Copy our message over to zmBuf because zmBuf gets overwritten when the AF_DATA_CONFIRM is received */ memcpy(zmBuf, testBuf, MESSAGE_LENGTH); /* Now initialize the payload */ int index; for (index = MESSAGE_HEADER_LENGTH; index < (TEST_MESSAGE_PAYLOAD_LENGTH + MESSAGE_HEADER_LENGTH); index++) { testBuf[index] = index; } /* Send the message to the Coordinator */ result = sendMessage(); if (result != MODULE_SUCCESS) { printf("afSendData Error %02X; stopping\r\n", result); while (1); } /* Now, wait for the AF_DATA_CONFIRM to verify that the message was successfully sent*/ while (!(MODULE_HAS_MESSAGE_WAITING())); /* Retrieve the AF_DATA_CONFIRM message */ getMessage(); if (!(IS_AF_DATA_CONFIRM())) { /* Stop if we receive a different message */ printf("Error; stopped after packet %u", packetCounter); } toggleLed(1); /* If you want to slow down the rate of sending packets then add: delayMs(1); which will add a one mSec delay after each packet is sent. */ if (((packetCounter % 100) == 0) && (packetCounter != 0)) { printf("%u\r\n", packetCounter); } } printf("Done! Sent %u packets!\r\nPress button to start again\r\n", NUMBER_OF_PACKETS_TO_SEND); /* Wait until a button is pressed, then send another 1000 */ while (!(buttonIsPressed(ANY_BUTTON))); } }
void colibrateDetector(){ enum {GOTOPAUSE, PAUSE, CHECKEXT, PROCESSBUTTON, PROCESSNOCK}; static char state = GOTOPAUSE; switch (state){ case GOTOPAUSE: #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)" GOTOPAUSE \r*", '*'); #endif ledOff(LEDRED1); ledOff(LEDRED2); ledOff(LEDGREEN1); ledOff(LEDGREEN2); timerSet(TIMER_NOCK, 0, 30); state = PAUSE; break; case PAUSE: if (timerIsElapsed(TIMER_NOCK) == TRUE){ state = CHECKEXT; } break; case CHECKEXT: if(buttonIsPressed(BUTTONDOOR) == TRUE){ #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)" setNextSence \r*", '*'); #endif setNextSence(); changeFlag(FLAG_NOCK, FALSE); ledOn(LEDRED1); ledOn(LEDRED2); _delay_ms(300); ledOff(LEDRED1); ledOff(LEDRED2); state = GOTOPAUSE; return; } if (getFlag(FLAG_NOCK) == TRUE){ state = PROCESSNOCK; } break; case PROCESSNOCK: #ifdef LOGGDEBUG loggerWriteToMarker((LogMesT)" PROCESSNOCK \r*", '*'); #endif ledOn(LEDGREEN1); ledOn(LEDGREEN2); _delay_ms(300); ledOff(LEDGREEN1); ledOff(LEDGREEN2); changeFlag(FLAG_NOCK, FALSE); state = CHECKEXT; break; default: break; } }