Move formatFreq to utils

This commit is contained in:
Reed Nightingale 2020-02-10 00:16:15 -08:00
parent 5c0ecb087b
commit 61b79ba06a
4 changed files with 40 additions and 40 deletions

View File

@ -8,43 +8,6 @@
#include <SPI.h> #include <SPI.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
/*
* This formats the frequency given in f
*/
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width)
{
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 < fixed_width){
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;
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;
}
}
/***************** /*****************
* Begin TFT functions * Begin TFT functions

View File

@ -18,8 +18,6 @@ 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, TextJustification_e justification = TextJustification_e::Center); void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border, TextJustification_e justification = TextJustification_e::Center);
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width = 0);
#define TEXT_LINE_HEIGHT 18 #define TEXT_LINE_HEIGHT 18
#define TEXT_LINE_INDENT 5 #define TEXT_LINE_INDENT 5

37
utils.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
* Formats the frequency given
*/
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width)
{
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 < fixed_width){
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;
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;
}
}

View File

@ -1,3 +1,5 @@
#pragma once #pragma once
#define LIMIT(val,min,max) ((val) < (min)) ? (min) : (((max) < (val)) ? (max) : (val)) #define LIMIT(val,min,max) ((val) < (min)) ? (min) : (((max) < (val)) ? (max) : (val))
void formatFreq(uint32_t freq, char* buff_out, uint16_t buff_size, uint8_t fixed_width = 0);