mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2024-11-10 17:46:05 -05:00
Move formatFreq to utils
This commit is contained in:
parent
5c0ecb087b
commit
61b79ba06a
37
nano_gui.cpp
37
nano_gui.cpp
@ -8,43 +8,6 @@
|
||||
#include <SPI.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
|
||||
|
@ -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 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_INDENT 5
|
||||
|
||||
|
37
utils.cpp
Normal file
37
utils.cpp
Normal 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;
|
||||
}
|
||||
}
|
4
utils.h
4
utils.h
@ -1,3 +1,5 @@
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user