void button_que_update(event_queue *queue, button *b, uint8_t ev_base) { uint8_t ev; static queue_element qel; ev = button_update(b); qel.source = ev + ev_base; if (ev!=BUTTON_NO_EVENT) queue_send(queue, &qel); }
void update_all_inputs(void) { button_update(); cmps10_update_all(); gps_update(); odometer_update(); update_all_nav(); return; }
static void button_task (__unused__ void *data) { button_update (); if (button_push_event_p (BUTTON1)) { if (mmelody_active_p (melody)) mmelody_play (melody, 0); else mmelody_play (melody, tune1); } }
void sched_update (void) { t1ms_cnt++; if (t1ms_cnt == 10000) t1ms_cnt = 0; if (t1ms_cnt % 20 == 0) /* each 20 ms */ { wheel_update_ticks_buffers(); } if (t1ms_cnt % pid_interval == 0) /* motor controller update */ { if (pid_enable) wheel_update_pid(); /* update PID motor controller */ else wheel_update_open_loop(); /* update open loop motor controller */ } if (t1ms_cnt % pfbst_interval == 0) /* send $PFBST */ { nmea_tx_status(); } /* each 10 ms */ if (t1ms_cnt % 10 == 0) /* each 10 ms */ { if (t1ms_cnt % 20 == 0) /* each 20 ms */ { } if (t1ms_cnt % 50 == 0) /* each 50 ms */ { } if (t1ms_cnt % 100 == 0) /* each 100 ms */ { if (nmea_wd_timeout) nmea_wd++; /* increase watchdog timeout */ else nmea_wd = 0; voltage = adc_data[0]; /* request voltage measurement */ state_update(); } if (t1ms_cnt % 200 == 0) /* each 200 ms */ { button_update(); led_update(); voltage_update(); } } }
// загрузка данных кнопки kucode_t button_load( gui_obj_t *obj ) { gui_button_t *const widget = (gui_button_t*)obj->widget; pstart(); ku_avoid( obj->status != GUI_NOTLOADED ); // загружаем главное изображение, не может быть NULL ku_avoid( widget->back_nor_name == NULL ); obj->updated = BUTTON_UD_NORM; /* загружаем изображение активной кнопки, если NULL, то используется нормальное изображение */ if ( widget->back_mon_name ) obj->updated |= BUTTON_UD_MON; else widget->back_mon = NULL; /* загружаем изображение нажатой кнопки, если NULL, то используется нормальное изображение */ if ( widget->back_mdn_name ) obj->updated |= BUTTON_UD_MDN; else widget->back_mdn = NULL; /* загружаем шрифт текста кнопки, если NULL, то кнопка не будет иметь текста */ if ( widget->font_name ) { obj->updated |= BUTTON_UD_FONT; // если установлен текст кнопки.. if ( widget->caption ) obj->updated |= BUTTON_UD_CAPTION; else widget->fontface = NULL; } else { widget->font = NULL; widget->fontface = NULL; } if ( button_update(obj) != KE_NONE ) KU_ERRQ_PASS(); button_ch_state(obj, BUTTON_NORM); preturn KE_NONE; }
int main(void) { cli(); /* We need to use a timer to control how long our main loop iterations are. * Experiments showed that the main loop was executing approximately every * 3.2 milliseconds, which is too quick for the sdcard to write a block * of data. Here we are configuring Timer1 because it is a "16-bit" timer * which would allow us to count to values greater than (2^8)-1. For a pre- * scale value of 64, the timer will count up to 16,000,000/64 = 250,000. * This gives us a timer period of 250,000 ticks/sec = 4 microseconds/tick. * Suppose we want the main loop to run 40 times per second (40 Hz), we would * need to restart the loop when Timer1 reaches the value: 250,000/40 = 6250 * See Atmel datasheet for Mega, Section 17.11 */ TCCR1A = 0b00000000; // Normal operation; no waveform generation by default TCCR1B = 0b00000011; // No input capture, waveform gen; prescaler = 64 TCCR1C = 0b00000000; // No output compare TIMSK1 = 0b00000000; // TIMING DEBUG - Digital Pin 4 DDRG |= (1 << 5); char msg[64]; if (button_init() && uwrite_init() && cmps10_init() && sdcard_init()) { uwrite_print_buff("All systems go!\r\n"); return 0; } else { uwrite_print_buff("There was an error during init\r\n"); return 1; } memset(msg, 0, sizeof(msg)); memset(&statevars, 0, sizeof(statevars)); statevars.prefix = 0xDADAFEED; statevars.suffix = 0xCAFEBABE; uint32_t iterations = 0; sei(); TIMSK1 = 0b00000001; while (1) { // TIMING DEBUG FOR OSCILLOSCOPE PORTG |= (1 << 5); TCNT1 = 0; button_update(); cmps10_update_all(); statevars.main_loop_counter = iterations; mainloop_timer_overflow = 0; // TIMING DEBUG FOR OSCILLOSCOPE PORTG &= (0 << 5); if (button_is_pressed()) { uwrite_print_buff("The button is pressed! The LED should be on.\r\n"); led_turn_on(); statevars.mission_started = 1; } else { led_turn_off(); statevars.mission_started = 0; } snprintf(msg, sizeof(msg), "Heading: %u Pitch: %d Roll: %hhd\r\n", cmps10_heading, cmps10_pitch, cmps10_roll); // Needed to cast these values to display negative pitch and roll values //(int8_t) statevars.heading_raw, (int8_t) statevars.pitch_deg, (int8_t) statevars.roll_deg); uwrite_print_buff(msg); sdcard_write_data(); iterations++; if (iterations > 256) { uwrite_print_buff("Finished collecting data!\r\n"); break; } /* Ensure that the main loop period is as long as we want it to be. * This means (1) triggering the main loop to restart we notice it is * running too long, and (2) performing busy waiting if the instructions * above finish before the desired loop duration. */ while (1) { if (mainloop_timer_overflow) { break; } if (TCNT1 >= MAINLOOP_PERIOD_TICKS) { break; } } } return 0; }
void button_init(void) { PB_PULL_UP (PORTD, PD7); /* enable pull-up resistor */ button_update(); }