void *opt_uartonoff_init(int init){ frontbuttoncontrol_read(); if(opt_send_data_via_uart_lastvalue != opt_send_data_via_uart){ lcd_gotoxy(0, 2); if(opt_send_data_via_uart == false){ lcd_puts("Uart turned off"); } else { lcd_puts("Uart turned on "); } } if(frontbuttoncontrol_get_button() == BUTTON_BLUE){ LIGHT_ON(LED_RED); opt_send_data_via_uart = !(opt_send_data_via_uart); if(opt_send_data_via_uart){ _delay_ms(300); uart_puts("Starts to send data:\n"); LIGHT_OFF(LED_RED); } _delay_ms(500); LIGHT_OFF(LED_RED); } return ((void*)NULL); }
void handle_switch_frame(uint8_t *frame) { if (frame[1] == REQUEST_MSG) { switch((switch_cmd_t) frame[2]) { case SWITCH_ON: LIGHT_ON(); break; case SWITCH_OFF: LIGHT_OFF(); break; case SWITCH_TOGGLE: LIGHT_TOGGLE(); break; } } }
int main(int argc, char* argv[]) { DDRD |= (1 << LIGHT); LIGHT_OFF(); serial_init(); FILE s=FDEV_SETUP_STREAM(send_char_serial,NULL,_FDEV_SETUP_WRITE); stdout=&s; printf("Test String\n"); while (1) { send_char_serial(receive_char_serial()); LIGHT_ON(); } return 0; }
void *fn_showFastPorts(int init){ // display the application screen lcd_puts("Digi 1 Digit 2"); lcd_gotoxy(0, 2); sprintf(buf_fdi_values, "%3d %3d", value_1, value_2); lcd_puts(buf_fdi_values); if(opt_send_data_via_uart){ LIGHT_ON(LED_RED); sprintf(buf_fdi_values, "%d,%d;\n", value_1, value_2); uart_puts( buf_fdi_values ); uart_puts("\n"); LIGHT_OFF(LED_RED); } // count the ports value_1 = DIGITAL_IN_1_READ; value_2 = DIGITAL_IN_2_READ; return (void *) NULL; }
void *fn_sayHello(int init){ lcd_gotoxy(0, 0); lcd_puts(("hello world.")); lcd_gotoxy(0, 2); lcd_puts((" ")); lcd_gotoxy(hello_position, 2); lcd_puts(" -"); ++hello_position; if(hello_position > 15){ hello_position = 0; } if(opt_send_data_via_uart){ LIGHT_ON(LED_RED); itoa(hello_position, buf, 10); uart_puts( buf ); uart_puts( "\n" ); LIGHT_OFF(LED_RED); } _delay_ms(200); return (void *) NULL; }
int main(void) { //initialize the device device_init(); _delay_ms(1000); // wait for 1sec device_reset(); ui_menu_init(); ui_menu_add("Say Hello", fn_sayHello ); ui_menu_add("Count ext ports", fn_countExtPorts ); ui_menu_add("Edit text", fn_timeoutDemo ); ui_menu_add("Show fast ports", fn_showFastPorts ); ui_menu_add("Show DAC values", fn_showDACValue ); ui_menu_add("Show uptime", fn_uptime ); menuentry_t *optionsMenu = ui_menu_add("Options:\n(Submenu)", dummy ); ui_menu_add_sub(optionsMenu, "Send data via\nUART", opt_uartonoff_init ); ui_menu_add_sub(optionsMenu, "Save Preferences", opt_save_preferences ); ui_menu_show(); // set the lights LIGHT_OFF(LED_RED); LIGHT_OFF(LED_GREEN); frontbuttoncontrol_init(); // mainloop while(1) { frontbuttoncontrol_read(); if(button_pressed && button_listening){ int val = frontbuttoncontrol_get_button(); // pageing if(val == BUTTON_BLUE){ ui_menu_next(); ui_menu_show(); } // execute if(val == BUTTON_GREEN){ // if no submenu is available than run the application, otherwise go into the submenu if(ui_menu_has_submenu()){ ui_menu_enter_submenu(); ui_menu_show(); } else { button_listening = false; isApplicationRunning = true; ui_menu_run(1); continue; } } // leaving submenu if(val == BUTTON_WHITE){ ui_menu_leave_submenu(); ui_menu_show(); } _delay_ms(200); } if(button_pressed && button_value == BUTTON_WHITE && button_listening == false){ // escape sequence isApplicationRunning = false; LIGHT_OFF(LED_GREEN); ui_menu_show(); button_listening = true; } if(isApplicationRunning){ ui_menu_run(0); continue; } } }
void ProcessInput() { if (clock == MORNING) { LIGHT_WELDER(led1) LIGHT_OFF(led2) LIGHT_OFF(led3) LIGHT_OFF(led4) } else if (clock == AFTERNOON) { LIGHT_OFF(led1) LIGHT_WELDER(led2) LIGHT_OFF(led3) LIGHT_OFF(led4) } else if (clock == EVENING) { LIGHT_OFF(led1) LIGHT_OFF(led2) LIGHT_WELDER(led3) LIGHT_OFF(led4) } else if (clock == NIGHT) { LIGHT_OFF(led1) LIGHT_OFF(led2) LIGHT_OFF(led3) LIGHT_WELDER(led4) } }