diff --git a/UI.hpp b/UI.hpp index 2500178..08d995c 100644 --- a/UI.hpp +++ b/UI.hpp @@ -202,7 +202,7 @@ void UI_function_not_enabled(void); void UI_function_not_implemented(uint8_t param); void lcd_display_int(int16_t var, uint8_t size, bool zeros, bool brackets, bool sign); void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign); -void lcd_display_bar(const char* title, uint32_t value, uint32_t max_value, bool init); +void lcd_display_bar(const char* title, uint32_t value, uint32_t min_value, uint32_t max_value, bool init); void lcd_special_chars(uint8_t mode); // normal menu @@ -2093,15 +2093,8 @@ void UI_func_pb_range(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("PB Range")); -#ifdef DEBUG - Serial.println(F("Entering UI_func_pb_range()")); - Serial.print(F("configuration.dexed[")); - Serial.print(instance_id, DEC); - Serial.print(F("].pb_range=")); - Serial.println(configuration.dexed[instance_id].pb_range, DEC); -#endif + lcd_special_chars(BLOCKBAR); + lcd_display_bar("PB Range", configuration.dexed[instance_id].pb_range, PB_RANGE_MIN, PB_RANGE_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2130,19 +2123,12 @@ void UI_func_pb_range(uint8_t param) MicroDexed[instance_id]->setPBController(configuration.dexed[instance_id].pb_range, configuration.dexed[instance_id].pb_step); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].pb_range, 2, false, true, false); + lcd_display_bar("PB Range", configuration.dexed[instance_id].pb_range, PB_RANGE_MIN, PB_RANGE_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { -#ifdef DEBUG - Serial.println(F("Entering UI_func_pb_range()")); - Serial.print(F("configuration.dexed[")); - Serial.print(instance_id, DEC); - Serial.print(F("].pb_range=")); - Serial.println(configuration.dexed[instance_id].pb_range, DEC); -#endif + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2157,8 +2143,8 @@ void UI_func_pb_step(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("PB Step")); + lcd_special_chars(BLOCKBAR); + lcd_display_bar("PB Step", configuration.dexed[instance_id].pb_step, PB_STEP_MIN, PB_STEP_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2187,13 +2173,13 @@ void UI_func_pb_step(uint8_t param) MicroDexed[instance_id]->setPBController(configuration.dexed[instance_id].pb_range, configuration.dexed[instance_id].pb_step); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].pb_step, 2, false, true, false); + lcd_display_bar("PB Step", configuration.dexed[instance_id].pb_step, PB_STEP_MIN, PB_STEP_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { // you can here reset some global vars or do nothing + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2208,8 +2194,8 @@ void UI_func_mw_range(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("MW Range")); + lcd_special_chars(BLOCKBAR); + lcd_display_bar("MW Range", configuration.dexed[instance_id].mw_range, MW_RANGE_MIN, MW_RANGE_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2238,13 +2224,13 @@ void UI_func_mw_range(uint8_t param) MicroDexed[instance_id]->setMWController(configuration.dexed[instance_id].mw_range, configuration.dexed[instance_id].mw_assign); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].mw_range, 2, false, true, false); + lcd_display_bar("MW Range", configuration.dexed[instance_id].mw_range, MW_RANGE_MIN, MW_RANGE_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { // you can here reset some global vars or do nothing + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2286,7 +2272,6 @@ void UI_func_mw_assign(uint8_t param) } } - MicroDexed[instance_id]->setMWController(configuration.dexed[instance_id].mw_range, configuration.dexed[instance_id].mw_assign); } @@ -2337,8 +2322,8 @@ void UI_func_fc_range(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("FC Range")); + lcd_special_chars(BLOCKBAR); + lcd_display_bar("FC Range", configuration.dexed[instance_id].fc_range, FC_RANGE_MIN, FC_RANGE_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2366,13 +2351,14 @@ void UI_func_fc_range(uint8_t param) MicroDexed[instance_id]->setFCController(configuration.dexed[instance_id].fc_range, configuration.dexed[instance_id].fc_assign); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].fc_range, 2, false, true, false); + + lcd_display_bar("FC Range", configuration.dexed[instance_id].fc_range, FC_RANGE_MIN, FC_RANGE_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { // you can here reset some global vars or do nothing + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2465,8 +2451,8 @@ void UI_func_bc_range(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("BC Range")); + lcd_special_chars(BLOCKBAR); + lcd_display_bar("BC Range", configuration.dexed[instance_id].bc_range, BC_RANGE_MIN, BC_RANGE_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2495,13 +2481,13 @@ void UI_func_bc_range(uint8_t param) MicroDexed[instance_id]->setBCController(configuration.dexed[instance_id].bc_range, configuration.dexed[instance_id].bc_assign); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].bc_range, 2, false, true, false); + lcd_display_bar("BC Range", configuration.dexed[instance_id].bc_range, BC_RANGE_MIN, BC_RANGE_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { // you can here reset some global vars or do nothing + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2593,8 +2579,8 @@ void UI_func_at_range(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { // setup function - lcd.setCursor(0, 0); - lcd.print(F("AT Range")); + lcd_special_chars(BLOCKBAR); + lcd_display_bar("AT Range", configuration.dexed[instance_id].at_range, AT_RANGE_MIN, AT_RANGE_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2623,13 +2609,13 @@ void UI_func_at_range(uint8_t param) MicroDexed[instance_id]->setATController(configuration.dexed[instance_id].at_range, configuration.dexed[instance_id].at_assign); } - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].at_range, 2, false, true, false); + lcd_display_bar("AT Range", configuration.dexed[instance_id].at_range, AT_RANGE_MIN, AT_RANGE_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* { // you can here reset some global vars or do nothing + lcd_special_chars(SCROLLBAR); eeprom_write(); } } @@ -2845,7 +2831,7 @@ void UI_func_portamento_time(uint8_t param) if (LCDML.FUNC_setup()) // ****** SETUP ********* { lcd_special_chars(BLOCKBAR); - lcd_display_bar("Portam. Time", configuration.dexed[instance_id].portamento_time, PORTAMENTO_TIME_MAX, true); + lcd_display_bar("Portam. Time", configuration.dexed[instance_id].portamento_time, PORTAMENTO_TIME_MIN, PORTAMENTO_TIME_MAX, true); } if (LCDML.FUNC_loop()) // ****** LOOP ********* @@ -2873,12 +2859,8 @@ void UI_func_portamento_time(uint8_t param) MicroDexed[instance_id]->setPortamentoMode(configuration.dexed[instance_id].portamento_mode, configuration.dexed[instance_id].portamento_glissando, configuration.dexed[instance_id].portamento_time); } - /* - lcd.setCursor(0, 1); - lcd_display_int(configuration.dexed[instance_id].portamento_time, 2, false, true, false); - */ - lcd_display_bar("Portam. Time", configuration.dexed[instance_id].portamento_time, PORTAMENTO_TIME_MAX, false); + lcd_display_bar("Portam. Time", configuration.dexed[instance_id].portamento_time, PORTAMENTO_TIME_MIN, PORTAMENTO_TIME_MAX, false); } if (LCDML.FUNC_close()) // ****** STABLE END ********* @@ -3147,11 +3129,11 @@ void UI_func_volume(uint8_t param) if (menu_state != MENU_VOLUME) { lcd_special_chars(BLOCKBAR); - lcd_display_bar("Volume", configuration.vol, VOLUME_MAX, true); + lcd_display_bar("Volume", configuration.vol, VOLUME_MIN, VOLUME_MAX, true); menu_state = MENU_VOLUME; } else - lcd_display_bar("Volume", configuration.vol, VOLUME_MAX, false); + lcd_display_bar("Volume", configuration.vol, VOLUME_MIN, VOLUME_MAX, false); set_volume(configuration.vol, configuration.mono); eeprom_write(); @@ -3393,9 +3375,9 @@ void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bo lcd.print(F("]")); } -void lcd_display_bar(const char* title, uint32_t value, uint32_t max_value, bool init) +void lcd_display_bar(const char* title, uint32_t value, uint32_t min_value, uint32_t max_value, bool init) { - float _v = float(value * LCD_cols) / max_value; + float _v = float(value * LCD_cols) / (max_value - min_value); float _vi; uint8_t vf = uint8_t(modff(_v, &_vi) * 10.0); uint8_t vi = uint8_t(_vi); @@ -3407,50 +3389,80 @@ void lcd_display_bar(const char* title, uint32_t value, uint32_t max_value, bool lcd_display_int(value, 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)4); // full block - else - lcd.print(F(" ")); - } - if (vi == 0 && uint8_t(vf / 2) == 0) { lcd.setCursor(0, 1); - lcd.write((uint8_t)0); + lcd.write((uint8_t)0); // minimal block } - else if (vf > 0) + else { - lcd.setCursor(vi + 1, 1); - lcd.write((uint8_t)int(vf / 2) - 1); + for (uint8_t i = 0; i < LCD_cols; i++) + { + if (i < vi) + lcd.write((uint8_t)4); // full block + else + lcd.print(F(" ")); + } + + if (vf > 1) + { + lcd.setCursor(vi - 1, 1); + lcd.write((uint8_t)int(vf / 2) - 1); + } } } else { + uint8_t ca = (float((LCD_cols) / (max_value - min_value)) + 0.5) + 1; + lcd.setCursor(strlen(title) + 1, 0); lcd_display_int(value, 3, true, false, false); - if (vi > 0) + if (vi == 0 && uint8_t(vf / 2) == 0) { - lcd.setCursor(vi - 1, 1); - lcd.write((uint8_t)4); // full block - if (vf > 0) - lcd.write((uint8_t)int(vf / 2) - 1); - lcd.print(F(" ")); + lcd.setCursor(0, 1); + lcd.write((uint8_t)0); // minimal block + for (uint8_t n = 1; n <= ca; n++) + lcd.print(F(" ")); } - else if (uint8_t(vf / 2) == 0) + else if (vi == LCD_cols && uint8_t(vf / 2) == 0) { - lcd.setCursor(0, 1); - lcd.write((uint8_t)0); - lcd.print(F(" ")); + lcd.setCursor(LCD_cols - ca - 1, 1); + lcd.write((uint8_t)4); // full block + for (uint8_t n = LCD_cols - ca; n < LCD_cols; n++) + lcd.write((uint8_t)4); // full block } - - if (uint8_t(vf / 2) != 0) + else { - lcd.setCursor(vi, 1); - lcd.write((uint8_t)int(vf / 2) - 1); - lcd.print(F(" ")); + uint8_t b, e; + + if (vi - ca < 0) + b = 0; + else + b = vi - ca; + if (vi + ca >= LCD_cols) + e = LCD_cols; + else + e = vi + ca; + + Serial.print("ca="); + Serial.print(ca); + Serial.print(" b="); + Serial.print(b); + Serial.print(" e="); + Serial.print(e); + Serial.println(); + + lcd.setCursor(b - 1, 1); + for (uint8_t n = b; n <= e; n++) + { + if (n < vi) + lcd.write((uint8_t)4); // full block + else if (n == vi && uint8_t(vf / 2) != 0) + lcd.write((uint8_t)uint8_t(vf / 2) - 1); + else + lcd.print(F(" ")); + } } } }