Add spacers to keep frequency display a fixed width

This commit is contained in:
Reed Nightingale 2020-01-28 02:30:34 -08:00
parent 6313aa5adc
commit 6ddd46a853
2 changed files with 15 additions and 4 deletions

View File

@ -11,7 +11,8 @@ struct Point ts_point;
/* /*
* This formats the frequency given in f * This formats the frequency given in f
*/ */
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) { void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width)
{
memset(buff, 0, buff_size); memset(buff, 0, buff_size);
ultoa(freq, buff, DEC); ultoa(freq, buff, DEC);
@ -20,10 +21,20 @@ void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
const uint8_t num_leading_digits_raw = num_digits % 3; const uint8_t num_leading_digits_raw = num_digits % 3;
const uint8_t num_leading_digits = (0 == num_leading_digits_raw) ? 3 : num_leading_digits_raw; const uint8_t num_leading_digits = (0 == num_leading_digits_raw) ? 3 : num_leading_digits_raw;
if(0 == num_spacers){ if(0 < fixed_width){
return; while(0 < fixed_width - num_digits - num_spacers){
if(0 == fixed_width % 4){
buff[0] = '\x81';//separator size
}
else{
buff[0] = '\x80';//digit size
}
--fixed_width;
++buff;
}
} }
ultoa(freq, buff, DEC);
buff += num_leading_digits; buff += num_leading_digits;
num_digits -= num_leading_digits; num_digits -= num_leading_digits;
for(int i = num_digits-1; i >= 0; --i){ for(int i = num_digits-1; i >= 0; --i){

View File

@ -17,7 +17,7 @@ void displayFillrect(unsigned int x,unsigned int y,unsigned int w,unsigned int h
void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg); void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg);
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border); void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border);
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size); void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width = 0);
/* touch functions */ /* touch functions */
boolean readTouch(); boolean readTouch();