-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax: [task#value#transformation#justification] #1289
Conversation
Transformations: Special: !: negate (only for 0 or 1) R: RIGHT JUSTIFY V: value O: ON/OFF C: OPEN/CLOSE U: UP/DOWN u: U/D Y: YES/NO y: Y/N X: O/X I: IN/OUT Z: 0/1 1: 1 decimal 2: 2 decimals 3: 3 decimals Dx.y: x digits + y decimals F: floor E: ceiling Justification: P: prefix spaces S: suffix spaces
for the Wiki: Format Transformation: Feature to transform Values from numeric to strings or to format numeric values. Where #transformation is: Adding ! to any of the above formatting inverts the logic. Format of any number value (floats): Examples (value = 3.1415): #R: justifies the latest value to the right according to the number of characters exported by the LCD (tested on LCD). Not tested on other displays. Justification formats applis to the transformed value: Example (value = 1) |
src/Misc.ino
Outdated
} | ||
break; | ||
case 4: //Dx.y | ||
if (tempValueFormat[1]>='0' && tempValueFormat[1]<='9' && tempValueFormat[2]=='.' && tempValueFormat[3]>='0' && tempValueFormat[3]<='9') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the isDigit()
function like described here
src/Misc.ino
Outdated
value = toString(valFloat,y); | ||
int indexDot; | ||
indexDot = value.indexOf('.') > 0 ? value.indexOf('.') : value.length(); | ||
for (byte f = 0; f < x - indexDot; f++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f < x - indexDot
does work like it is intended here, but I always have to look up the C++ operator precedence when I see code like this.
It is more clear when using ()
.
src/Misc.ino
Outdated
} | ||
|
||
// Check Justification syntax | ||
if (valueJust.length() > 0) //do the checks only if a Justification is defined to optimize loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing optimizations, better store the length in a const variable :)
It is being used in the lines below.
src/Misc.ino
Outdated
|
||
String tempValueFormat = valueFormat; | ||
const int invertedIndex = tempValueFormat.indexOf('!'); | ||
const int inverted = invertedIndex >= 0 ? 1 : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inverted
and rightJustify
are boolean expressions here.
src/Misc.ino
Outdated
case '3' : | ||
value = toString(valFloat,3); | ||
break; | ||
case 'D' ://Dx.y min 'x' digits zero filled & 'y' decimal fixed digits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case '1' ... '3' can be done with less code:
case '1' :
case '2' :
case '3' :
value = toString(valFloat, tempValueFormat[0]);
break;
Before the strings (i.e. ON/OFF) were right justified: Now they are left justified: "ON" and "OFF". |
Fixing #1289 for backwards compatibility
Transformations:
Special:
!: negate (only for 0 or 1)
R: RIGHT JUSTIFY
V: value
O: ON/OFF
C: OPEN/CLOSE
U: UP/DOWN
u: U/D
Y: YES/NO
y: Y/N
X: O/X
I: IN/OUT
Z: 0/1
Dx.y: x digits + y decimals
F: floor
E: ceiling
Justification:
Pn: prefix up to n spaces
Sn: suffix up to n spaces