From c01d45f6f4aee58f0a0fe3ee1519f8dbc4dacb47 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 2 Mar 2020 14:55:17 +0100 Subject: [PATCH] Volume is now shown as blocks instead of asterisks. --- UI.hpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/UI.hpp b/UI.hpp index 33eef72..af2cf78 100644 --- a/UI.hpp +++ b/UI.hpp @@ -118,6 +118,14 @@ const uint8_t scroll_bar[5][8] = { {B10001, B10001, B10001, B10001, B10001, B10001, B11111, B11111} // scrollbar bottom }; + +const uint8_t block_bar[5][8] = { + {B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000}, + {B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000}, + {B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100}, + {B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110}, + {B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111} +}; enum { ENC_R, ENC_L }; enum { MENU_START, MENU_VOICE, MENU_EDIT, MENU_VOLUME }; enum {MENU_VOICE_BANK, MENU_VOICE_SOUND}; @@ -267,6 +275,12 @@ void setup_ui(void) { lcd.createChar(2, (uint8_t*)scroll_bar[2]); lcd.createChar(3, (uint8_t*)scroll_bar[3]); lcd.createChar(4, (uint8_t*)scroll_bar[4]); + // set special chars for volumeba + lcd.createChar(5, (uint8_t*)block_bar[0]); + lcd.createChar(6, (uint8_t*)block_bar[1]); + lcd.createChar(7, (uint8_t*)block_bar[2]); + lcd.createChar(8, (uint8_t*)block_bar[3]); + lcd.createChar(9, (uint8_t*)block_bar[4]); #else for (int x = 0; x < 5; x++) { flipped_scroll_bar[x] = rotTile(scroll_bar[x]); @@ -3133,29 +3147,81 @@ void UI_func_voice_selection(uint8_t param) void UI_func_volume(uint8_t param) { + uint8_t vi, vf; + float _v, _vi; + #ifdef DEBUG Serial.println(F("UI_func_volume()")); #endif back_from_volume = 0; + _v = float(configuration.vol * LCD_cols) / 100.0; + vf = uint8_t(modff(_v, &_vi) * 10.0); + vi = uint8_t(_vi); + + Serial.print(" ---------------> _v="); + Serial.print(_v, 5); + Serial.print(" ---------------> vi="); + Serial.print(vi); + Serial.print(" ---------------> vf="); + Serial.print(vf); + Serial.println(); + + _v = float(configuration.vol * LCD_cols) / 100.0; + vf = uint8_t(modff(_v, &_vi) * 10.0); + vi = uint8_t(_vi); + if (menu_state != MENU_VOLUME) { - lcd.show(0, 0, LCD_cols, "Volume:"); - lcd.show(1, 0, LCD_cols, "[ ]"); menu_state = MENU_VOLUME; - } - lcd.setCursor(8, 0); - lcd_display_int(configuration.vol, 3, true, false, false); - lcd.setCursor(1, 1); - for (uint8_t i = 0; i < LCD_cols - 2; i++) + lcd.show(0, 0, LCD_cols, "Volume:"); + lcd.setCursor(8, 0); + lcd_display_int(configuration.vol, 3, true, false, false); + + lcd.setCursor(0, 1); + + for (uint8_t i = 0; i < LCD_cols; i++) + { + if (i < uint8_t(vi)) + lcd.write((uint8_t)9); // full block + else + lcd.print(F(" ")); + } + + if (vi == 0 && vf == 0) + { + lcd.setCursor(0, 1); + lcd.write((uint8_t)5); + } + else if (vf > 0) + { + lcd.setCursor(vi, 1); + lcd.write((uint8_t)5 + int(vf / 2)); + } + } + else { - if (i < int(((LCD_cols - 2) * configuration.vol / 100.0) + 0.5)) - lcd.print(F("*")); - else + lcd.setCursor(8, 0); + lcd_display_int(configuration.vol, 3, true, false, false); + + if (vi > 0) + { + lcd.setCursor(vi - 1, 1); + lcd.write((uint8_t)9); // full block + if (vf > 0) + lcd.write((uint8_t)5 + int(vf / 2)); + lcd.print(F(" ")); + } + else if (vi == 0 && vf == 0) + { + lcd.setCursor(0, 1); + lcd.write((uint8_t)5); lcd.print(F(" ")); + } } + set_volume(configuration.vol, configuration.mono); eeprom_write(); }