So for example, a boolean item would have a lower bound of 0 and an upper bound of 1. Other items have lower bounds of 0 and uppers of 300. Others have -200 to +200, etc.
But for items with a defined upper boundry of over 255 something odd happens. Most of my items have an upper bound of 300 and whenever they increment or decrement to 44 a select case statement incorrectly evaluates it as an upper bound case.
It compares the upper bound value stored in the structure to the "working value" to see if it's an upper bound case. The WorkingVal and UpperBound are both defined as integers. Here is the output: (note the UpperBoundText: 0 is expected/normal since it's undefined)
Code: Select all
Upperbound Case
Upperbound val: 300 Working val: 44
UpperBoundText: 0
Code: Select all
' Generic item handler
Select Case SubMenu.WorkingVal
Case menuItems[MainMenu.Cursor].LowerBound
' See if there is a lower bound text identified
SerOutText("Lowerbound Case ")
If menuItems[MainMenu.Cursor].LowerBoundText = integer(0) Then
' No text defined
DrawVal = TRUE
Else
' Lower limit text defined, so draw it
Lcd_PrintPtr(LCDLine3,menuItems[MainMenu.Cursor].LowerBoundText)
DrawVal = FALSE
End If
Case menuItems[MainMenu.Cursor].UpperBound
' See if there is an upper bound text identified
SerOutTextCRLF("Upperbound Case ")
SerOutText("Upperbound val: ")
SerOutInt(menuItems[MainMenu.Cursor].UpperBound)
SerOutText("Working val: ")
SerOutInt(SubMenu.WorkingVal)
SerOutCRLF()
SerOutText("UpperBoundText: ")
SerOutInt(menuItems[MainMenu.Cursor].UpperBoundText)
SerOutCRLF()
If menuItems[MainMenu.Cursor].UpperBoundText = integer(0) Then
' No text defined
DrawVal = TRUE
Else
' Upperlimit text defined, so draw it
Lcd_PrintPtr(LCDLine3,menuItems[MainMenu.Cursor].UpperBoundText)
DrawVal = FALSE
End If
Case Else
' We're in a non-upper and non-lower bound case
DrawVal = TRUE
End Select
There is an obvious explanation here. The binary representation of 300 is:
0000 0001 0010 1100
And the binary representation of 44 is, you guessed it,
0010 1100
So somehow this is being evaluated as byte values and the upper byte is being cut off, and I don't think I'm inadvertently doing it.
Which bring up another issue.. I ordinarily would never have noticed this because if UpperBoundText = 0, as it clearly is based on the serial output, it should just draw the value like any other number and I would be unaware it even entered this state. However, that IF statement is evaluating to FALSE, causing it to print the contents of the flash address 0 to the LCD. I have also tried
Code: Select all
If menuItems[MainMenu.Cursor].UpperBoundText = 0 Then
Edit: UpperBoundText is a longint and is a pointer to a constant string in ROM, that's why it evaluates it as a number.