Move formatFreq to nano_gui so that both ubitx_ui and setup can use the single function

This commit is contained in:
Reed Nightingale 2020-01-14 23:33:11 -08:00
parent d62ff59c90
commit afeb056667
4 changed files with 32 additions and 56 deletions

View File

@ -8,6 +8,33 @@
struct Point ts_point; struct Point ts_point;
/*
* This formats the frequency given in f
*/
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
memset(buff, 0, buff_size);
ultoa(freq, buff, DEC);
uint8_t num_digits = strlen(buff);
const uint8_t num_spacers = (num_digits-1) / 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;
if(0 == num_spacers){
return;
}
buff += num_leading_digits;
num_digits -= num_leading_digits;
for(int i = num_digits-1; i >= 0; --i){
buff[i + (i/3 + 1)] = buff[i];
}
for(unsigned int i = 0; i < num_spacers; ++i){
memcpy_P(buff,F("."),1);
buff += 4;
}
}
void readTouchCalibration(){ void readTouchCalibration(){
LoadSettingsFromEeprom(); LoadSettingsFromEeprom();
/* for debugging /* for debugging

View File

@ -18,6 +18,8 @@ void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t
void displayRawText(char *text, int x1, int y1, int color, int background); void displayRawText(char *text, int x1, int y1, int color, int background);
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);
/* touch functions */ /* touch functions */
boolean readTouch(); boolean readTouch();

View File

@ -73,34 +73,9 @@ void displayDialog(const __FlashStringHelper* title, const __FlashStringHelper*
displayText(c, LAYOUT_INSTRUCTION_TEXT_X, LAYOUT_INSTRUCTION_TEXT_Y, LAYOUT_INSTRUCTION_TEXT_WIDTH, LAYOUT_INSTRUCTION_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); displayText(c, LAYOUT_INSTRUCTION_TEXT_X, LAYOUT_INSTRUCTION_TEXT_Y, LAYOUT_INSTRUCTION_TEXT_WIDTH, LAYOUT_INSTRUCTION_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND);
} }
void printCarrierFreq(unsigned long freq){ void printCarrierFreq(unsigned long freq)
{
memset(c, 0, sizeof(c)); formatFreq(freq,c,sizeof(c));
memset(b, 0, sizeof(b));
ultoa(freq, b, DEC);
unsigned int characters_remaining = strlen(b);
char* destination = c;
char* source = b;
while(characters_remaining > 0){
if(characters_remaining > 3){
unsigned int characters_to_read = characters_remaining % 3;
if(0 == characters_to_read){
characters_to_read = 3;
}
memcpy(destination,source,characters_to_read);
source += characters_to_read;
destination += characters_to_read;
characters_remaining -= characters_to_read;
memcpy_P(destination,(const char*)F("."),1);
destination += 1;
}
else{
memcpy(destination,source,characters_remaining);
characters_remaining -= characters_remaining;
}
}
displayText(c, LAYOUT_SETTING_VALUE_X, LAYOUT_SETTING_VALUE_Y, LAYOUT_SETTING_VALUE_WIDTH, LAYOUT_SETTING_VALUE_HEIGHT, COLOR_TEXT, COLOR_TITLE_BACKGROUND, COLOR_BACKGROUND); displayText(c, LAYOUT_SETTING_VALUE_X, LAYOUT_SETTING_VALUE_Y, LAYOUT_SETTING_VALUE_WIDTH, LAYOUT_SETTING_VALUE_HEIGHT, COLOR_TEXT, COLOR_TITLE_BACKGROUND, COLOR_BACKGROUND);
} }

View File

@ -148,34 +148,6 @@ boolean getButton(btn_set_e index, Button* button){
return true; return true;
} }
/*
* This formats the frequency given in f
*/
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
memset(buff, 0, buff_size);
ultoa(freq, buff, DEC);
uint8_t num_digits = strlen(buff);
const uint8_t num_spacers = (num_digits-1) / 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;
if(0 == num_spacers){
return;
}
buff += num_leading_digits;
num_digits -= num_leading_digits;
for(int i = num_digits-1; i >= 0; --i){
buff[i + (i/3 + 1)] = buff[i];
}
for(unsigned int i = 0; i < num_spacers; ++i){
memcpy_P(buff,F("."),1);
buff += 4;
}
}
inline void drawCommandbar(char* text){ inline void drawCommandbar(char* text){
displayText(text, LAYOUT_MODE_TEXT_X, LAYOUT_MODE_TEXT_Y, LAYOUT_MODE_TEXT_WIDTH, LAYOUT_MODE_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); displayText(text, LAYOUT_MODE_TEXT_X, LAYOUT_MODE_TEXT_Y, LAYOUT_MODE_TEXT_WIDTH, LAYOUT_MODE_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND);
} }