static inline void interpret_message (uint16_t sender, uint8_t msglen, uint8_t* msg) { switch (msg[0]) { case eCMD_REQUEST_REG: // fallthrough case eCMD_SET_REG_8BIT: // fallthrough case eCMD_SET_REG_16BIT: // fallthrough case eCMD_SET_REG_32BIT: register_do_command(&g_bus, sender, msglen, msg); break; #ifndef NO_BLOCK_MESSAGE case eCMD_BLOCK_START: block_message_start(&g_bus, sender, msglen, msg); break; case eCMD_BLOCK_DATA: block_message_data (&g_bus, sender, msglen, msg); break; case eCMD_BLOCK_END: block_message_end (&g_bus, sender, msglen, msg); //no break case eCMD_BLOCK_RESET: block_data_reset(); break; #endif case eCMD_SLEEP: activate_wakeup_interrupt(); LED_STATUS_OFF; LED_ERROR_OFF; bus_sleep(&g_bus); deactivate_wakeup_interrupt(); break; case eCMD_RESET: cli(); #ifdef __AVR_ATtiny1634__ //TODO implement reset for attiny1634 #else wdt_enable(WDTO_15MS); while (1); // wait until watchdog resets the controller. #endif break; default: break; } }
// Interpret message static void interpret_message (sBus_t* bus, uint8_t* msg, uint8_t msg_len, uint16_t sender) { if (msg[0] <= eCMD_STATE_DATE_TIME) { // state messages if (msg[0] == eCMD_STATE_BITFIELDS) { if (sender == 0x0B) { g_target_temp += 10; draw_temperatures(); } else { if (msg[2] & 0b00000001) draw_window_opened(); else draw_window_closed(); } } } else if (msg[0] <= eCMD_SET_REG_32BIT) { if (msg[0] == eCMD_SET_REG_16BIT && msg[1] == APP_eReg_CurrentDesiredTemperature) { g_target_temp = msg[2]; g_target_temp <<= 8; g_target_temp |= msg[3]; draw_temperatures(); if (g_target_temp %2) draw_window_opened(); else draw_window_closed(); } // register messages register_do_command(bus, sender, msg_len, msg); } else { // system messages switch (msg[0]) { case eCMD_ACK: g_bus.eModuleState = eMod_Running; break; case eCMD_SLEEP: sleep_pinchange_enable(); bus_sleep(bus); sleep_pinchange_disable(); break; default: break; } } }
bool menu(void) { uint8_t mp = 0; uint8_t my = 0; uint8_t i; uint8_t old_bus; bool action; old_bus = active_bus; bus_sleep(true); menu_select_status(); // disable splash screen if still active set_error(ERROR_OK); for (;;) { set_busy_led(false); set_dirty_led(true); lcd_clear(); for (i = 0; i < LCD_LINES; i++) { lcd_locate(0, i); rom_menu_main(mp - my + i); } lcd_cursor(true); for (;;) { action = false; lcd_locate(0, my); //printf("mp: %u my: %u\r\n", mp, my); //while (!get_key_state(KEY_ANY)); if (get_key_autorepeat(KEY_PREV)) { if (mp > 0) { // Move up --mp; if (my > 0) { --my; // Move within same page } else { mp = LCD_LINES - 1; my = LCD_LINES - 1; // page up break; } } else { // flip down to last menu entry my = MAIN_MENU_LAST_ENTRY % LCD_LINES; mp = MAIN_MENU_LAST_ENTRY; break; } } if (get_key_autorepeat(KEY_NEXT)) { if (mp < MAIN_MENU_LAST_ENTRY) { ++mp; if (my < (LCD_LINES - 1)) { ++my; // Move within same page } else { my = 0; // page down break; } } else { // flip up to first menu entry mp = 0; my = 0; break; } } if (get_key_press(KEY_SEL)) { action = true; break; } } lcd_cursor(false); if (!action) continue; lcd_clear(); if (mp == 1) menu_browse_files(); else if (mp == 2) menu_device_number(); else if (mp == 3) menu_set_clock(); else if (mp == 4) menu_select_bus(); else if (mp == 5) menu_adjust_contrast(); else if (mp == 6) menu_adjust_brightness(); else break; if (current_error != ERROR_OK) break; } bus_sleep(false); lcd_draw_screen(SCRN_STATUS); update_leds(); return old_bus != active_bus; }