Skip to content
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

Merged
merged 2 commits into from
Apr 21, 2018
Merged

Syntax: [task#value#transformation#justification] #1289

merged 2 commits into from
Apr 21, 2018

Conversation

giig1967g
Copy link
Contributor

@giig1967g giig1967g commented Apr 20, 2018

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

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
@giig1967g
Copy link
Contributor Author

giig1967g commented Apr 20, 2018

for the Wiki:

Format Transformation:

Feature to transform Values from numeric to strings or to format numeric values.
Syntax:
[task#value#transformation#justification]

Where #transformation is:
Format of PIN states of GPIO (0 or 1)
#V: value unformatted
#O: 1/0 -> ON/OFF
#C: 1/0 -> OPEN/CLOSE
#U: 1/0 -> UP/DOWN
#u: 1/0 -> U/D
#Y: 1/0 -> YES/NO
#y: 1/0 -> Y/N
#I: 1/0 -> IN/OUT
#X: 1/0 -> X/O
#Z: 1/0 -> 1/0

Adding ! to any of the above formatting inverts the logic.
So for example:
#O! 1/0 -> OFF/ON
#Z! 1/0 -> 0/1
#Y! 1/0 -> NO/YES

Format of any number value (floats):
#Dx.y: x digits + y decimals
#E: convert to ceiling
#F: convert to floor

Examples (value = 3.1415):
#D -> 3
#D3 -> 003
#D.2 -> 3.14
#D3.2 -> 003.14
#E -> 4
#F -> 3

#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:
#Pn: prefix with padding spaces
#Sn suffix with padding spaces

Example (value = 1)
#U#S5 -> UP (+3 spaces)
#U#P5 -> (3 spaces) UP

src/Misc.ino Outdated
}
break;
case 4: //Dx.y
if (tempValueFormat[1]>='0' && tempValueFormat[1]<='9' && tempValueFormat[2]=='.' && tempValueFormat[3]>='0' && tempValueFormat[3]<='9')
Copy link
Member

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++)
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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; 

@giig1967g
Copy link
Contributor Author

Accepted all your comments.
For #1, #2 and #3 I have actually removed them as they can be achieved with #D.1, #D.2 and #D.3 respectively.

@TD-er TD-er merged commit b8fa429 into letscontrolit:mega Apr 21, 2018
@giig1967g
Copy link
Contributor Author

giig1967g commented Apr 21, 2018

Before the strings (i.e. ON/OFF) were right justified:
" ON" and "OFF"

Now they are left justified: "ON" and "OFF".
If you want to right justify them (i.e. " ON" with one prefix space) do the following:
[task#value#O#P3]

TD-er added a commit that referenced this pull request Apr 22, 2018
Fixing #1289 for backwards compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants