// Handles different menu selection // // leftRightIndex: index for determining menus // upDownIndex, currDollars, currCents: needed for calling print_menu void select_menu(int *leftRightIndex, int upDownIndex, int currDollars, int currCents) { if (*leftRightIndex == 0) { print_welcome(); } else if (*leftRightIndex == 1) { print_menu(upDownIndex, currDollars, currCents); } else { clear_display(); delay(1000); //1ms LED_toggle(); display_string("Order Confirmed!"); display_string(" "); delay(1000000); //1sec display_string("Preparing Now..."); delay(3000000); //3sec clear_display(); delay(1000); //1ms display_string("Order Ready!"); LED_toggle(); delay(3000000); //3sec *leftRightIndex = 0; clear_display(); delay(1000); //1ms print_welcome(); } }
// --- Stream front-end data in/out the module for read/write commands void stream(void) { uint32_t rateFactor = 0; if (myTrig) { myTrig = 0; if (streamMode == 1) // This module is reading/writing itself { #ifndef TX sprintf(sertemp,"%d\n\r",samplePD()); send(rwComPort, sertemp); if (rwComLED) LED_toggle(); #else writeToFE(rwComPort); if (rwComLED) LED_toggle(); #endif } else if (streamMode == 3) // This module is being read/written by another module { #ifndef TX readOK(readComSrc, rwComLED); #else writeToFE(rwComPort); if (rwComLED) LED_toggle(); #endif } else if (streamMode == 4) // This module is reading all other receiver { // Display previous data readAllDisp(); // Inquire new data rateFactor = floor((48*1000000)/rwComRate); message[0] = _MesID_broadcast; // broadcast command message[1] = _MesID_read; // read command message[2] = (uint8_t)rateFactor; // rwComRate: Low Byte message[3] = (uint8_t)(rateFactor>>8); message[4] = (uint8_t)(rateFactor>>16); message[5] = (uint8_t)(rateFactor>>24); message[6] = rwComLED; // rwComLED broadcast(myID); // Activate the modules stack. Expect response from all receiver modules modStack = numOfRX+1; #ifndef TX modBuf[myID-1] = samplePD(); #endif } else if (streamMode == 5) // This module is writing all other transmitters
__interrupt void timerA_ISR(void) { static int ctr = 0; if(++ctr == SYSTICK_HZ/2) { ctr = 0; LED_toggle(); } }
//Handles toggling the led, and which is adjusted based on the algo //in timer zero. void Timer1IntHandler() { clear_timer1_int(); TIMER1_TAILR_R = period; TIMER0_CTL_R &= ~(0x01); //disable timer 0; //turn off timer0 LED_toggle(); TIMER0_CTL_R |= 0x1; //turn on timer0 }
// Timer 1 event handler. used to decrement the timer1 variable. We use this variable to model a clock to // time events in our menu and game. void Timer1EventHandler(void) { // TIMER1_ICR_R |= 0x01; // clears interrupt status // timer1--; /* Toggles the LED when hovering over the sensor */ //LAB 3 TIMER1_ICR_R |= 0x01; LED_toggle(); }
// --- This module was read --- void readOK(uint16_t originID, uint8_t led) { uint16_t temp = 0; //HAL_Delay(routeDist[originID-1]*10 + rand()%10); temp = samplePD(); message[0] = _MesID_readOK; // readOK command message[1] = (uint8_t)temp; // Low Byte message[2] = (uint8_t)(temp>>8); // High Byte mesSend(myID, originID); if (led) LED_toggle(); }
void LED_init(void) { #ifdef DEBUG os_printf("[debug] LED_init\r\n"); #endif /* initialize GPIO2 as a OUTPUT function (D4) and turn it off */ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); gpio_output_set(0, BIT(2), BIT(2), 0); /* initialize GPIO12 as a OUTPUT function (D6) */ PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); /* turn on the green led */ LED_toggle(GREEN_LED, LED_ON); }
__interrupt void timerB0_ISR(void) { #define DEBUG_INTERRUPT #ifdef DEBUG_INTERRUPT static uint16_t ctr = 0; if(++ctr > (SYSTICK_HZ/2U)) { ctr = 0; LED_toggle(); } #endif //static uint16_t tickISRTime = 0; //uint16_t t1 = TBR; //__low_power_mode_off_on_exit(); QK_ISR_ENTRY(); /* inform QK-nano about ISR entry */ QF_tickISR(); //tickISRTime = TBR - t1; QK_ISR_EXIT(); /* inform QK-nano about ISR exit */ }
void sys_init(void) { // Make sure sys clock is at least 8MHz CLKPR = 0x80; CLKPR = 0x00; io_init(); timer_init(); spi_initialize_master(); // Enable global interrupts for Timer execution sei(); transceiver_initialize(); SS1_set_high(); // SPI Temp Sensor. LED_toggle(LED7); }
/* * The systick Interrupt Service Routine */ void __attribute__ ((interrupt)) systick_handler(void) { static int waiting_prev = 0; /* * Every .5 seconds, toggle the green LED */ if (systemTicks % 20 == 0) { LED_toggle(LED_GREEN); // Test ADC test_flag = 1; } /* * If we're in client mode, we want to account for dropped packets * so we won't wait forever. If we're waiting for two consecutive systicks, * (.2 seconds), reset the waiting_to_recv_packet flag to low */ if (mode_state == CLIENT_S) { update_servos_from_server_f = 1; if (waiting_to_recv_packet == waiting_prev) { waiting_to_recv_packet = 0; } waiting_prev = waiting_to_recv_packet; } /* * If we're in command mode, send an update flag * (to "reset" the sending if we happened to drop a packet) * every second */ if (mode_state == COMMAND_S) { send_update_f = 1; } // global counter of how many systicks we've had systemTicks++; }
static void toggle_connectivity_indicator() { LED_toggle(0); }
static void logging_led_toggle() { LED_toggle(2); }
void LEDTask( void * Parameters ) { uint8_t cycle = 0; LED_activity_desc_t new_cfg; LED_state_rec_t* pLED; uint8_t led_id; /* Task will run every 50ms */ TickType_t xFrequency = 100 / portTICK_PERIOD_MS; TickType_t xLastWakeTime; /* Initialise the xLastWakeTime variable with the current time. */ xLastWakeTime = xTaskGetTickCount(); for (;;) { for (led_id = 0; led_id < LED_CNT; led_id++) { pLED = &LEDstate[led_id]; /* Update the led configuration only after perfoming a full cycle on each action */ if (cycle == 0) { if (xQueueReceive( pLED->queue, &new_cfg, 0 ) == pdTRUE) { /* Save the last config */ memcpy(&(pLED->last_cfg), &(pLED->cur_cfg), sizeof(LED_activity_desc_t)); /* Update the config struct */ memcpy(&(pLED->cur_cfg), &new_cfg, sizeof(LED_activity_desc_t)); LED_set_state(pLED->pin_cfg, pLED->cur_cfg.initstate); pLED->counter = pLED->cur_cfg.delay_init; } } switch (pLED->cur_cfg.action) { case LED_ACTV_ON: LED_on(pLED->pin_cfg); break; case LED_ACTV_OFF: LED_off(pLED->pin_cfg); break; case LED_ACTV_BLINK: if (pLED->counter == 0) { if (pLED->cur_cfg.initstate == LED_get_state(pLED->pin_cfg)) { /* LED is in initial state */ pLED->counter = pLED->cur_cfg.delay_tog; } else { /* LED is in toggled state */ pLED->counter = pLED->cur_cfg.delay_init; } LED_toggle(pLED->pin_cfg); if ( pLED->counter == 0 ) { /* Loaded a zero prescale value--means the activity descriptor is a single-shot descriptor * that has expired--like a lamp test or a pulse. * Revert the LED to the last know state and stay in toggled state until next cycle */ pLED->counter = cycle; memcpy(&(pLED->cur_cfg), &(pLED->last_cfg), sizeof(LED_activity_desc_t)); } } else { (pLED->counter)--; } break; } } if (cycle == 0) { /* Reload the cycle counter */ cycle = LED_CYCLE_COUNTER; } else { cycle--; } vTaskDelayUntil( &xLastWakeTime, xFrequency ); } }
static void ICACHE_FLASH_ATTR scheduler_check_tasks(void) { #ifdef DEBUG os_printf("[debug] scheduler_check_tasks\r\n"); #endif /* if the epoch time is not set, try again the next time when this function is called */ if (sntp_get_current_timestamp() == 0) { os_printf("[error] scheduler_check_tasks: epoch time not set, cannot execute scheduled tasks! retrying in %u secs..\r\n", scheduler_timer_ms / 1000); /* turn on the red led */ LED_toggle(RED_LED, LED_ON); return; } /* turn off the red led */ LED_toggle(RED_LED, LED_OFF); /* get the current time */ date_time_t date_time; epoch_to_date_time(&date_time, sntp_get_current_timestamp()); #ifdef DEBUG os_printf("[debug] scheduler_get_current_date: second: [%u] | minute: [%u] | hour: [%u] | day: [%u] | month: [%u] | year: [%u]\r\n", date_time.second, date_time.minute, date_time.hour, date_time.day, date_time.month, date_time.year); #endif /* * the following code outlines the scheduler every 5 minutes on 0,5,10,15,20,25,30,35,40,45,50,55 */ if (scheduler_timer_ms == 1000) { /* if the seconds are on 0, update the timer to 1 minute */ if (date_time.second == 0) { /* if the the minutes are on 0,5,10,15,20,25,30,35,40,45,50,55 update the timer to 5 minutes */ if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) || (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) || (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) { #ifdef DEBUG os_printf("[debug] scheduler_get_current_date: updating scheduler to every 5 minutes.\r\n"); #endif /* disarm the timer */ os_timer_disarm(&scheduler_timer); /* 5 minutes (300000ms) */ scheduler_timer_ms = 300000; /* re-arm the timer and execute the scheduler every 5 minutes */ os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL); os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1); } else { #ifdef DEBUG os_printf("[debug] scheduler_get_current_date: updating scheduler to every minute.\r\n"); #endif /* disarm the timer */ os_timer_disarm(&scheduler_timer); /* 1 minute (60000ms) */ scheduler_timer_ms = 60000; /* re-arm the timer and execute the scheduler every minute */ os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL); os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1); } } else { /* do nothing */ return; } } else if (scheduler_timer_ms == 60000) { /* check if the timer is outlined correctly, if not reschedule it again */ if (date_time.second != 0) { /* disarm the timer */ os_timer_disarm(&scheduler_timer); /* reset it after 5 secs */ os_timer_disarm(&scheduler_reset_timer); os_timer_setfn(&scheduler_reset_timer, (os_timer_func_t *)scheduler_reset_scheduler_timer, NULL); os_timer_arm(&scheduler_reset_timer, 5000, 0); } /* if the the minutes are on 0,5,10,15,20,25,30,35,40,45,50,55 update the timer to 5 minutes */ if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) || (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) || (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) { #ifdef DEBUG os_printf("[debug] scheduler_get_current_date: updating scheduler to every 5 minutes.\r\n"); #endif /* disarm the timer */ os_timer_disarm(&scheduler_timer); /* 5 minutes (300000ms) */ scheduler_timer_ms = 300000; /* re-arm the timer and execute the scheduler every 5 minutes */ os_timer_setfn(&scheduler_timer, (os_timer_func_t *)scheduler_check_tasks, NULL); os_timer_arm(&scheduler_timer, scheduler_timer_ms, 1); } } else if (scheduler_timer_ms == 300000) { /* check if the timer is outlined correctly, if not reschedule it again */ if (date_time.second != 0) { /* disarm the timer */ os_timer_disarm(&scheduler_timer); /* reset it after 5 secs */ os_timer_disarm(&scheduler_reset_timer); os_timer_setfn(&scheduler_reset_timer, (os_timer_func_t *)scheduler_reset_scheduler_timer, NULL); os_timer_arm(&scheduler_reset_timer, 5000, 0); } } /* if the queue post interval is 5, post the queue every 5 minutes */ if (queue_post_interval == 5) { if ((date_time.minute == 0) || (date_time.minute == 5) || (date_time.minute == 10) || (date_time.minute == 15) || (date_time.minute == 20) || (date_time.minute == 25) || (date_time.minute == 30) || (date_time.minute == 35) || (date_time.minute == 40) || (date_time.minute == 45) || (date_time.minute == 50) || (date_time.minute == 55)) { /* if it's 00:00 reset all counters */ if ((date_time.hour == 0) && (date_time.minute == 0)) { interrupt_reset_total_energy_state(); } /* for some reason it can happen that the energy states are not correctly reset on 00:00, * so for the time being we are gonna do an extra check/reset */ if ((date_time.hour == 0) && (date_time.minute == 5)) { if (interval_pulse_count != pulse_count) { /* reset the pulse_count to the interval_pulse_count */ os_printf("[error] scheduler_check_tasks: pulse_count [%u] not equals interval_pulse_count [%u] at 00:05, syncing values..\r\n", pulse_count, interval_pulse_count); pulse_count = interval_pulse_count; } } /* update the post queue */ queue_update_post_queue(); /* reset the power and interval pulse count variables */ interrupt_reset_power_state(); if (OUTPUT_CLIENT == PVOUTPUT) { /* try to post the queue items and if it's successfull empty the queue */ queue_post_items_to_pvoutput(); } else if (OUTPUT_CLIENT == THINGSPEAK) { /* try to post the queue items and if it's successfull empty the queue */ queue_post_items_to_thingspeak(); } } } else if (queue_post_interval == 15) { /* if the queue post interval is 15, post the queue every 15 minutes */ if ((date_time.minute == 0) || (date_time.minute == 15) || (date_time.minute == 30) || (date_time.minute == 45)) { /* if it's 00:00 reset all counters */ if ((date_time.hour == 0) && (date_time.minute == 0)) { interrupt_reset_total_energy_state(); } /* for some reason it can happen that the energy states are not correctly reset on 00:00, * so for the time being we are gonna do an extra check/reset */ if ((date_time.hour == 0) && (date_time.minute == 15)) { if (interval_pulse_count != pulse_count) { /* reset the pulse_count to the interval_pulse_count */ os_printf("[error] scheduler_check_tasks: pulse_count [%u] not equals interval_pulse_count [%u] at 00:15, syncing values..\r\n", pulse_count, interval_pulse_count); pulse_count = interval_pulse_count; } } /* update the post queue */ queue_update_post_queue(); /* reset the power and interval pulse count variables */ interrupt_reset_power_state(); if (OUTPUT_CLIENT == PVOUTPUT) { /* try to post the queued items and if it's successfull empty the queue */ queue_post_items_to_pvoutput(); } else if (OUTPUT_CLIENT == THINGSPEAK) { /* try to post the queue items and if it's successfull empty the queue */ queue_post_items_to_thingspeak(); } } } }
void putsCell(Serial *serial, const char *data) { LED_toggle(0); serial->put_s(data); pr_debug_str_msg("cellWrite: ", data); }