void dump_buffer(uint8_t *buffer, int count) { draw_top_bar(0, (CNTRLDISPLAY){0, 0, 0, 0, 1}); int i, xoffset=4, yoffset=34; char hex_buffer[10]; for (i=0; i<count; i++) { memset(hex_buffer, 0, 10); sstring(hex_buffer, "%x", buffer[i]); putstr_small(xoffset, yoffset, hex_buffer, 1); xoffset += 16; if ((i+1)%16==0) { yoffset += 8; xoffset = 4; } } swap_buffers(); uint16_t key; while (1) { key = get_key(); switch (key) { case ESC_PRESSED: return; } } }
int self_test_short() { OS_DRIVE* selected_drive = sf_drive_list_page(0); if (selected_drive->is_active) { IDENTIFY_DEVICE_DATA id; //identify_device((HBA_PORT*)selected_drive->port, &id); SMART_DATA sd; //smart_read_data((HBA_PORT*)selected_drive->port, &sd); draw_top_bar(0, (CNTRLDISPLAY){0, 0, 0, 0, 1}); } }
int menu_page(MENU menu_element, char menu_items[][100], int num_items, CNTRLDISPLAY controls, uint8_t bg, unsigned int selected) { memset(&menu_element, 0, sizeof(MENU)); menu_element.bg = bg; menu_element.vpad = menu_element.hpad = 10; int i; for (i=0; i<num_items; i++) { MENUITEM *item = &menu_element.items[i]; item->size.height = 25; item->fg = 1; item->selectedfg = 2; item->active = 1; item->selected = (i==selected)?1:0; setup_text(&item->header_text, menu_items[i], (POSITION){0,0}, 1, 0); } uint16_t key; while (1) { draw_top_bar(0, controls); draw_menu(&menu_element); swap_buffers(); key = get_key(); switch (key&0xff) { case DOWN_PRESSED: case RIGHT_PRESSED: selected++; break; case UP_PRESSED: case LEFT_PRESSED: selected--; break; case ENTER_PRESSED: return selected; case ESC_PRESSED: if (controls.esc_back || controls.esc_menu) return -1; break; default: continue; } selected = (selected<0)?num_items-1:selected; selected %= num_items; for (i=0;i<num_items;i++) menu_element.items[i].selected = (i==selected); } }
/** * @brief Display the menu (to be called directly, while-loop in side) * @param default_id: Default selected / entered menu ID * @param pre_enter: True for enterring the selected menu item * @retval None */ void menu(u8 default_id, bool pre_enter) { menu_selected = default_id; while (1) { if (ticks_img != get_ticks()) { ticks_img = get_ticks(); /*if (ticks_img % 200 == 1) { battery_adc_update(); if (get_seconds() % 10 == 4 && ticks_img == 1) { battery_regular_check(); } }*/ // if (ticks_img % 50 == 2) { // // Check button input // //button_update(); // // /** Menu item shift **/ // if (button_pressed(BUTTON_JS2_DOWN) == 1 || button_hold(BUTTON_JS2_DOWN, 10, 1)) { // // Go down the list // if (menu_selected < menu_count - 1) { // ++menu_selected; // } else { // menu_selected = 0; // } // } else if (button_pressed(BUTTON_JS2_UP) == 1 || button_hold(BUTTON_JS2_UP, 10, 1)) { // if (menu_selected > 0) { // --menu_selected; // } else { // menu_selected = menu_count - 1; // } // } // // /** Enter menu **/ // if (button_pressed(BUTTON_JS2_CENTER) == 1 || pre_enter) { // if (menu_list[menu_selected].fx == 0) { // // NULL FUNCTION // buzzer_play_song(FAIL_SOUND, 120, 100); // } else { // u16 prev_bg_color = tft_get_bg_color(); // u16 prev_text_color = tft_get_text_color(); // tft_clear(); // CLICK_MUSIC; // menu_list[menu_selected].fx(); // CLICK_MUSIC; // tft_clear(); // tft_set_bg_color(prev_bg_color); // tft_set_text_color(prev_text_color); // pre_enter = false; // } // } // /** Change screen orientation **/ // // if (button_pressed(BUTTON_1) == 1) { // tft_set_orientation((tft_get_orientation() + 1) % 4); // SUCCESSFUL_MUSIC; // } // if (button_pressed(BUTTON_2) == 1) { // tft_set_orientation((tft_get_orientation() + 3) % 4); // SUCCESSFUL_MUSIC; // } // } if (ticks_img % 50 == 7) { u16 prev_bg_color = tft_get_bg_color(); u16 prev_text_color = tft_get_text_color(); tft_clear(); draw_top_bar(); // Menu list const u8 items_per_page = tft_get_max_y_char() - 2; u8 page_count = menu_count ? (menu_count - 1) / items_per_page : 0; // Start from 0 u8 current_page = menu_selected / items_per_page; // Start from 0 for (u8 i = 0 + current_page * items_per_page, y = 0; i < menu_count && y < items_per_page; ++i, ++y) { if (i == menu_selected) { // Highlight the selected item tft_set_bg_color(ticks_img < 500 ? BLACK : DARK_GREY); tft_clear_line(y+1); tft_set_text_color(WHITE); } else { tft_set_bg_color(WHITE); tft_clear_line(y+1); tft_set_text_color(BLACK); } tft_prints(1, y+1, "%s", menu_list[i].title); } // Bottom bar - page number tft_set_text_color(WHITE); tft_set_bg_color(BLUE2); tft_clear_line(tft_get_max_y_char()-1); tft_prints(1, tft_get_max_y_char()-1, "%d/%d", current_page + 1, page_count + 1); // Reset bg and text color tft_set_bg_color(prev_bg_color); tft_set_text_color(prev_text_color); tft_update(); } } } }