Print Menu on 4x20 LCD?
computer guy
Posts: 1,113
Hi,
I need to store the following data in my code and call it later, does anyone know how I can?
A multidimensional array was my first idea, however this isn't supported in SPIN.
Any other ideas?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Post Edited (computer guy) : 1/15/2010 12:00:35 PM GMT
I need to store the following data in my code and call it later, does anyone know how I can?
Text Function Menu ├─Date/Time goto "Date/Time" menu │ ├─Set Date goto "Set Date" menu │ │ ├─Day goto "Set Day" menu │ │ ├─Month goto "Set Month" menu │ │ └─Year goto "Set Year" menu │ └─Set Time goto "Set Time" menu │ ├─Hour goto "Set Hour" menu │ └─Minute goto "Set Min" menu └─Timer goto "Timer" menu ├─Duration goto "Set Duration" menu └─PreHeat goto "Set PreHeat" menu
A multidimensional array was my first idea, however this isn't supported in SPIN.
Any other ideas?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Post Edited (computer guy) : 1/15/2010 12:00:35 PM GMT
Comments
1 2
3 4
Where the numbers are the element in the 1D array.
You then write a simple function getelement(row, column) which will convert the specified row and column into a 1D index of the 1D array. You can also do the same for 3D matrices.
Graham
Could you please explain this in more detail. I kind of see what you are saying but not entirely and to be honest I think I am just getting more confused every time I try and make sense of it.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3
So the first element is row 1 column 1, the second is row 1 column 2. It is a 1D array representing the following 3X3 array:
r1c1 r1c2 r1c3
r2c1 r2c2 r2c3
r3c1 r3c2 r3c3
Your function would be designed to get a particular element from the 1D array given the specified row and column. In this case which is not very accurate because the first element is 1 not 0 like in spin then you would have
1D_index = (row*3) - 3 + (column - 1)
(row*3)-3 gives you the address of the first element of a particular row to which you add the column to get the particular element
How you use this for your particular application I am not sure but it was you that suggested multidimensional arrays [noparse]:)[/noparse]
Graham
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Graham
If I understand correctly, you want to store pointers to three routines in the MenuFunc array so that later you can invoke one dynamically based on an index into the array. Unfortunately, Spin does not allow this.
But you could store a label that you fed into a case statement, each case being a different function.
Graham
Thats what I was planning to do.
Can you have an array of strings and if so, what datatype would I use?
e.g.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Post Edited (computer guy) : 1/12/2010 10:13:20 PM GMT
but lets say it is C which I can understand but not write.
Don'y you have to define the structure yourself?
I think the way people have been suggesting is to figure out what the structure looks like in memory and then
make arithmetic that converts your indexes into a single index. That requires memory allocated for all possible
array values fields.
The alternative is to have variable length strings which can be null and require 1 or less bytes if they are empty,
like a lot of classic (1980s) BASICs do. In SPIN you would have to manage all elements of all arrays within one
string, and I guess each element would have pointers to other elements to create a tree structure, or whatever
structure works well for you. This method may or may not require "garbage collection" (if the array gets full and
elements are often changing size or being removed)... Perhaps there are newer ways of doing this. I still think like
it's 1980 and need to conserve RAM, which is appropriate for Propeller. If you use an SD card for storage,
different rules apply that I don't yet know well enough to explain, but may be better for your data structure,
because they have gigabytes.
Post Edited (VIRAND) : 1/13/2010 1:44:44 AM GMT
Thank you all for your help though.
I will explain what I am wanting to do.
I have an lcd display (4x20) and 4 buttons (Up, Down, Ok, Back) and I want to build a menu structure and make it possible to go into sub menus.
This entire concept is new to me.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Post Edited (computer guy) : 1/13/2010 12:18:06 AM GMT
This would be a data structure for your problem.
Then you need a function that can print the menu on the LCD display, like
printMenu( menu_address )
and maybe
scrollMenu( start_with_entry )
Next is a input loop, which will react on the user input and a big case statement that is calling the right functions.
With the menu_level_iterator you keep track of the route you used to go to the actual submenu. The main-menu currently can have 16 entries (because I used <<= 4, 4 bits = value 0-15·). So, the first digit of the hexadecimal menu_entry_focus will tell you which entry in the main menu has been selected. The entry selected in the next menu-level will be shown in the second digit of the hexadecimal. For example
$21 means that first submenu 2 has been selected in the main menu and then entry 3 has been selected.
As we have longs in SPIN you can have a menu structure with 8 levels and each submenu can have 16 entries. Should be enough.
So, in the case statement you would add a value for every possible menu and sub-menu entry. And on this level you can decide whether the selected entry directly calls functions or would lead to a deeper level submenu.
Hope that helped more than it confused ;o)
PS: This is not tested code, I just hacked it for this post. I bet there are some minor bugs, but it should show the principle. (For example $0 is a bug. $0 should rather print the main menu and the first submenu can be selected with $1 ;o) So, in fact you only have 15 entries per menu-level, as the $0 of each level is needed for redisplay the submenu·when going up and down in the menu levels.
Post Edited (MagIO2) : 1/13/2010 7:54:02 AM GMT
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Tried a few things, with interesting results but not what it should output.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
output the string contained in mm_entry1?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
For example:
tv.dec( @table )
tv.dec( table_adr )
dat
table_adr word @table
table byte 0[noparse][[/noparse]10]
shows tow different results. Maybe it even get's worse when you use several dat section and that one with the menu is somewhere at the end.
For me it worked to add 16 to the value - possibly the 16 bytes that contain the clock-settings and some SPIN pointers.
It also works to do a
dat
org 16
PS: It's clear where the 16 comes from. It's the·propeller-tool 'internal' dat-section which is used to store the clock-settings and some SPIN pointers.
Post Edited (MagIO2) : 1/16/2010 12:11:32 AM GMT
here's my example of a menu driven 4 button 4X20 LCD code. It's for a hand held diagnostic tool for car. Disregard the PUB PROCESS_ECU , that's not finished in this version of my scantool, but gives an example how the LCD and push buttons work. This was actually ported from the SX forum from a post with me and JonnyMac talking about this same thing but with the SX.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Bad spellers of the world untie!
Edit:
I have this so far and it's printing the menu to the LCD (it only has two items at the moment)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Post Edited (computer guy) : 1/16/2010 1:31:15 AM GMT
LCD.str( mainmenu[noparse][[/noparse]0] )
is correct. mainmenu[noparse][[/noparse]0] only does not contain what we expected ... see my post above.
If you say
LCD.str( mainmenu[noparse][[/noparse]0]+16 )
the calculation is done at runtime, wasting speed and RAM for additional code.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Could you please explain "ORG" to me. I tried putting "ORG 16" at the start of the DAT section and removing the + 16, however this didn't work.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
From the DAT structure that MagIO2 provided.
Please...?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
LCD.str( mainmenu[noparse][[/noparse]0]+16 )
try
LCD.str( @@mainmenu[noparse][[/noparse]0] )
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net
and it's working great.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"powered by Propeller" domed stickers $1.50 - Find them here
Check out my Design and Technology project for my Higher School Certificate www.ecosureblog.net