Better output functions for showing numbers on LCD.

pull/32/head
Holger Wirtz 5 years ago
parent 281e435bfa
commit ae30024c5b
  1. 8
      MicroDexed.ino
  2. 158
      UI.hpp

@ -1672,8 +1672,9 @@ void show_cpu_and_mem_usage(void)
Serial.print(F("|XRUN:")); Serial.print(F("|XRUN:"));
Serial.print(sum_xrun, DEC); Serial.print(sum_xrun, DEC);
Serial.print(F("|OVERLOAD:")); Serial.print(F("|OVERLOAD:"));
Serial.print(sum_overload, DEC); Serial.println(sum_overload, DEC);
Serial.print(F("|PEAKR:"));
Serial.print(F("PEAKR:"));
Serial.print(peak_r, DEC); Serial.print(peak_r, DEC);
Serial.print(F("|PEAKL:")); Serial.print(F("|PEAKL:"));
Serial.print(peak_l, DEC); Serial.print(peak_l, DEC);
@ -1682,7 +1683,8 @@ void show_cpu_and_mem_usage(void)
Serial.print(F("|ACTPEAKMD:")); Serial.print(F("|ACTPEAKMD:"));
Serial.print(peak_dexed_value, 1); Serial.print(peak_dexed_value, 1);
Serial.print(F("|BLOCKSIZE:")); Serial.print(F("|BLOCKSIZE:"));
Serial.print(AUDIO_BLOCK_SAMPLES, DEC); Serial.println(AUDIO_BLOCK_SAMPLES, DEC);
Serial.print(F("|ACTVOICES:")); Serial.print(F("|ACTVOICES:"));
for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++)
{ {

158
UI.hpp

@ -211,6 +211,7 @@ 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_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_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign);
void lcd_display_bar_int(const char* title, uint32_t value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init); void lcd_display_bar_int(const char* title, uint32_t value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init);
void lcd_display_bar_float(const char* title, float value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign, bool init);
void lcd_special_chars(uint8_t mode); void lcd_special_chars(uint8_t mode);
// normal menu // normal menu
@ -966,10 +967,10 @@ void UI_func_chorus_frequency(uint8_t param)
if (LCDML.FUNC_setup()) // ****** SETUP ********* if (LCDML.FUNC_setup()) // ****** SETUP *********
{ {
// setup function // setup function
//lcd_special_chars(BLOCKBAR); lcd_special_chars(BLOCKBAR);
//lcd_display_bar_float("Chorus Frq.", configuration.chorus_frequency, CHORUS_FREQUENCY_MIN, CHORUS_FREQUENCY_MAX, 3, false, false, false, true); lcd_display_bar_float("Chorus Frq.", configuration.chorus_frequency, 0.1, CHORUS_FREQUENCY_MIN, CHORUS_FREQUENCY_MAX, 2, 1, false, false, false, true);
lcd.setCursor(0, 0); /* lcd.setCursor(0, 0);
lcd.print(F("Chorus Frequency")); lcd.print(F("Chorus Frequency")); */
} }
if (LCDML.FUNC_loop()) // ****** LOOP ********* if (LCDML.FUNC_loop()) // ****** LOOP *********
@ -987,16 +988,17 @@ void UI_func_chorus_frequency(uint8_t param)
chorus_modulator.frequency(configuration.chorus_frequency / 10.0); chorus_modulator.frequency(configuration.chorus_frequency / 10.0);
//lcd_display_bar_float("Chorus Frq.", configuration.chorus_frequency, CHORUS_FREQUENCY_MIN, CHORUS_FREQUENCY_MAX, 3, false, false, false, true); lcd_display_bar_float("Chorus Frq.", configuration.chorus_frequency, 0.1, CHORUS_FREQUENCY_MIN, CHORUS_FREQUENCY_MAX, 2, 1, false, false, false, false);
lcd.setCursor(0, 1);
/*lcd.setCursor(0, 1);
lcd_display_float(configuration.chorus_frequency / 10.0, 2, 1, false, true, false); lcd_display_float(configuration.chorus_frequency / 10.0, 2, 1, false, true, false);
lcd.print(F(" Hz")); lcd.print(F(" Hz"));*/
} }
} }
if (LCDML.FUNC_close()) // ****** STABLE END ********* if (LCDML.FUNC_close()) // ****** STABLE END *********
{ {
//lcd_special_chars(SCROLLBAR); lcd_special_chars(SCROLLBAR);
eeprom_write(); eeprom_write();
} }
} }
@ -1409,6 +1411,8 @@ void UI_func_transpose(uint8_t param)
// setup function // setup function
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print(F("Transpose")); lcd.print(F("Transpose"));
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].transpose - 24, 2, true, true, true);
} }
if (LCDML.FUNC_loop()) // ****** LOOP ********* if (LCDML.FUNC_loop()) // ****** LOOP *********
@ -1424,12 +1428,12 @@ void UI_func_transpose(uint8_t param)
else if (LCDML.BT_checkUp()) else if (LCDML.BT_checkUp())
configuration.dexed[instance_id].transpose = constrain(configuration.dexed[instance_id].transpose - ENCODER[ENC_R].speed(), TRANSPOSE_MIN, TRANSPOSE_MAX); configuration.dexed[instance_id].transpose = constrain(configuration.dexed[instance_id].transpose - ENCODER[ENC_R].speed(), TRANSPOSE_MIN, TRANSPOSE_MAX);
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].transpose - 24, 2, true, true, true);
MicroDexed[instance_id]->data[DEXED_VOICE_OFFSET + DEXED_TRANSPOSE] = configuration.dexed[instance_id].transpose; MicroDexed[instance_id]->data[DEXED_VOICE_OFFSET + DEXED_TRANSPOSE] = configuration.dexed[instance_id].transpose;
MicroDexed[instance_id]->notesOff(); MicroDexed[instance_id]->notesOff();
} }
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].transpose - 24, 1, false, true, true);
} }
if (LCDML.FUNC_close()) // ****** STABLE END ********* if (LCDML.FUNC_close()) // ****** STABLE END *********
@ -1453,6 +1457,8 @@ void UI_func_tune(uint8_t param)
lcd.print(F("Tune")); lcd.print(F("Tune"));
lcd.setCursor(6, 1); lcd.setCursor(6, 1);
lcd.print(F("cent")); lcd.print(F("cent"));
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].tune - 100, 3, true, true, true);
} }
if (LCDML.FUNC_loop()) // ****** LOOP ********* if (LCDML.FUNC_loop()) // ****** LOOP *********
@ -1468,12 +1474,12 @@ void UI_func_tune(uint8_t param)
else if (LCDML.BT_checkUp()) else if (LCDML.BT_checkUp())
configuration.dexed[instance_id].tune = constrain(configuration.dexed[instance_id].tune - ENCODER[ENC_R].speed(), TUNE_MIN, TUNE_MAX); configuration.dexed[instance_id].tune = constrain(configuration.dexed[instance_id].tune - ENCODER[ENC_R].speed(), TUNE_MIN, TUNE_MAX);
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].tune - 100, 3, true, true, true);
MicroDexed[instance_id]->controllers.masterTune = (int((configuration.dexed[instance_id].tune - 100) / 100.0 * 0x4000) << 11) * (1.0 / 12); MicroDexed[instance_id]->controllers.masterTune = (int((configuration.dexed[instance_id].tune - 100) / 100.0 * 0x4000) << 11) * (1.0 / 12);
MicroDexed[instance_id]->doRefreshVoice(); MicroDexed[instance_id]->doRefreshVoice();
} }
lcd.setCursor(0, 1);
lcd_display_int(configuration.dexed[instance_id].tune - 100, 1, false, true, true);
} }
if (LCDML.FUNC_close()) // ****** STABLE END ********* if (LCDML.FUNC_close()) // ****** STABLE END *********
@ -3189,111 +3195,79 @@ 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_int(int16_t var, uint8_t size, bool zeros, bool brackets, bool sign)
{ {
int16_t tmp = 0; lcd_display_float(float(var), size, 0, zeros, brackets, sign);
uint16_t p;
bool non_zero_found = false;
if (size < 1)
return;
if (brackets == true)
lcd.print(F("["));
if (sign == true)
{
size++;
if (var < 0)
{
lcd.print(F("-"));
var = abs(var);
}
else if (var > 0)
lcd.print(F("+"));
else
lcd.print(F(" "));
} }
if (var == 0 && zeros == false) void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign)
{
for (int8_t i = size - 1 ; i > 0; i--)
lcd.print(F(" "));
lcd.print(F("0"));
}
else
{
for (int8_t i = size - 1 ; i >= 0; i--)
{ {
p = int(pow(10, i)); char s[LCD_cols + 1];
tmp = int(var / p); char f[LCD_cols + 1];
if (tmp == 0) if (size_fraction > 0)
{ {
if (zeros == true) if (zeros == true && sign == true)
lcd.print(F("0")); sprintf(f, "%%+%0d.%df", size_number + size_fraction + 1, size_fraction);
else else if (zeros == true && sign == true)
{ sprintf(f, "%%+%0d.%df", size_number + size_fraction + 1, size_fraction);
if (non_zero_found == true) else if (zeros == false && sign == true)
lcd.print(F("0")); sprintf(f, "%%+%d.%df", size_number + size_fraction + 1, size_fraction);
else else if (zeros == false && sign == false)
lcd.print(F(" ")); sprintf(f, "%%%d.%df", size_number + size_fraction + 1, size_fraction);
}
sprintf(s, f, var);
} }
else else
{ {
non_zero_found = true; if (zeros == true && sign == true)
lcd.print(tmp); sprintf(f, "%%+0%dd", size_number + 1);
} else if (zeros == true && sign == false)
var -= (tmp * p); sprintf(f, "%%%0dd", size_number);
} else if (zeros == false && sign == true)
} sprintf(f, "%%+%dd", size_number + 1);
else if (zeros == false && sign == false)
sprintf(f, "%%%dd", size_number);
if (brackets == true) sprintf(s, f, int(var));
lcd.print(F("]"));
} }
void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign) if (brackets == true)
{ {
float fraction; char tmp[LCD_cols + 1];
float number;
if (size_number < 1 || size_fraction < 1)
return;
fraction = modff(var, &number);
if (brackets == true) strcpy(tmp, s);
lcd.print(F("[")); sprintf(s, "[%s]", tmp);
}
if (int(number) == 0) lcd.print(s);
{ Serial.println(f);
if (zeros == true) Serial.println(s);
lcd.print(F("00"));
else
lcd.print(F(" 0"));
} }
else
lcd_display_int(int(number), size_number, zeros, false, sign);
lcd.print(F("."));
lcd_display_int(round(fraction * pow(10, size_fraction)), size_fraction, true, false, false);
if (brackets == true) inline void lcd_display_bar_int(const char* title, uint32_t value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init)
lcd.print(F("]")); {
lcd_display_bar_float(title, float(value), factor, min_value, max_value, size, 0, zeros, brackets, sign, init);
} }
void lcd_display_bar_int(const char* title, uint32_t value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init) void lcd_display_bar_float(const char* title, float value, float factor, uint32_t min_value, uint32_t max_value, uint8_t size_number, uint8_t size_fraction, bool zeros, bool brackets, bool sign, bool init)
{ {
float _v = float((value - min_value) * LCD_cols) / (max_value - min_value); float _v = float((value - min_value) * LCD_cols) / (max_value - min_value);
float _vi = 0.0; float _vi = 0.0;
uint8_t vf = uint8_t(modff(_v, &_vi) * 10.0 + 0.5); uint8_t vf = uint8_t(modff(_v, &_vi) * 10.0 + 0.5);
uint8_t vi = uint8_t(_vi + 0.5); uint8_t vi = uint8_t(_vi + 0.5);
uint8_t size = 0;
if (size_fraction == 0)
size = size_number;
else
size = size_number + size_fraction + 1;
if (init == true) if (init == true)
{ {
// show initial title, value and bar // show initial title, value and bar
LCDML.DISP_clear(); LCDML.DISP_clear();
lcd.show(0, 0, LCD_cols - 1, title); lcd.show(0, 0, LCD_cols - 1, title);
lcd.setCursor(LCD_cols - (size + 1) + 1, 0); lcd.setCursor(LCD_cols - size, 0);
lcd_display_int(uint16_t(float(value)*factor + 0.5), size, zeros, brackets, sign); lcd_display_float(value * factor, size_number, size_fraction, zeros, brackets, sign);
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
if (vi == 0 && uint8_t(vf / 2) == 0) if (vi == 0 && uint8_t(vf / 2) == 0)
@ -3323,8 +3297,8 @@ void lcd_display_bar_int(const char* title, uint32_t value, float factor, uint32
// show only changed value and changed part of the bar // show only changed value and changed part of the bar
uint8_t ca = uint8_t (float(LCD_cols - 1) / float(max_value)) + 1; uint8_t ca = uint8_t (float(LCD_cols - 1) / float(max_value)) + 1;
lcd.setCursor(LCD_cols - (size + 1) + 1, 0); lcd.setCursor(LCD_cols - size, 0);
lcd_display_int(uint16_t(float(value)*factor + 0.5), size, zeros, brackets, sign); lcd_display_float(value * factor, size_number, size_fraction, zeros, brackets, sign);
if (vi == 0 && uint8_t(vf / 2) == 0) if (vi == 0 && uint8_t(vf / 2) == 0)
{ {

Loading…
Cancel
Save