Skip to content

Commit

Permalink
Update all strings to be stored in constants
Browse files Browse the repository at this point in the history
  • Loading branch information
iansan5653 authored and valerionew committed Jul 11, 2022
1 parent 8f8ec87 commit f2c1d66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
16 changes: 4 additions & 12 deletions src/HT1621.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void HT1621::update(){
wrone(10,_buffer[0]);
}

void HT1621::print(long num, char*flags, int precision){
void HT1621::print(long num, const char* flags, int precision){
if(num > 999999) // basic checks
num = 999999; // clip into 999999
if(num < -99999) // basic checks
Expand Down Expand Up @@ -238,11 +238,7 @@ void HT1621::print(double num, int precision){
if(precision < 0)
precision = 0; // negative precision?!

char * flags = "%6li";

if(precision > 0 && abs(num) < 1){
flags = "%06li";
}
const char* flags = (precision > 0 && abs(num) < 1) ? "%06li" : "%6li";

long integerpart;
integerpart = ((long)(num*pow(10,precision)));
Expand All @@ -267,11 +263,7 @@ void HT1621::printCelsius(double num){
else
precision = 1; // if positive max precision allowed = 1

char * flags = "%4li*C";

if(precision > 0 && abs(num) < 1){
flags = "%04li*C";
}
const char* flags = (precision > 0 && abs(num) < 1) ? "%04li*C" : "%4li*C";

long integerpart;
integerpart = ((long)(num*pow(10,precision)));
Expand All @@ -286,7 +278,7 @@ void HT1621::printCelsius(double num){
update();
}

void HT1621::print(char* str, bool leftPadded){
void HT1621::print(const char* str, bool leftPadded){
int chars = strlen(str);
int padding = 6 - chars;

Expand Down
4 changes: 2 additions & 2 deletions src/HT1621.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class HT1621
void backlight();
void noBacklight();
void setBatteryLevel(int level);
void print(long num, char* flags="%6li", int precision = 0);
void print(long num, const char* flags="%6li", int precision = 0);
void print(double num, int precision = 3);
void printCelsius(double num); // precision is always 1
void print(char* str, bool leftPadded = false);
void print(const char* str, bool leftPadded = false);
void display();
void noDisplay();
private:
Expand Down

0 comments on commit f2c1d66

Please sign in to comment.