Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:16 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : VAR save and restore(mainly save)...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 08:11pm 18 Nov 2015
Copy link to clipboard 
Print this post

Hi folks.


The VAR SAVE command is very handy, but I have found that there is a situation where you have lots of variables you want to save, and they cannot be fitted on the one command line.

Has any thought been given to allowing more then one VAR SAVE line?

VAR SAVE 1, VAR SAVE 2 kind of thing.
VAR RESTORE could work the same way: VAR RESTORE 1, VAR RESTORE 2 etc.

With the stereo project that jman and I are alpha testing, I am wanting to save all the current settings of the preamp using the likes of VAR SAVE, but there are too many variables to list on the one VAR SAVE command.

Any thoughts?

Perhaps a Cfunction could be written to get around this?
Not sure if Cfunctions can play with the flash memory - they might only be for number-crunching and speed for graphics drivers etc, which probably don't play about with the flash, only the RAM.

I would use an I2C EEPROM, but I forgot to add one, so VAR SAVE is really my only realistic alternative.

I had a light-bulb moment, and thought of copying all the variables into an array, but VAR SAVE won't save arrays(and that's fair enough), so that snookered that one.
Smoke makes things work. When the smoke gets out, it stops!
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 08:39pm 18 Nov 2015
Copy link to clipboard 
Print this post


What about encoding your variables into a number of strings, and a corresponding decode when reading them. Strings can be 255 character long, so 8 strings will let you use all the 2K available, and these 8 variable names should fit on the command line. So each string could be treated as an array of 255 by 8 bit integers or whatever you want(eg. 127 by 16 bit integers) . You should be good at substring(), ASC() and CHR$() when you are finished.

Regards
Gerry
Latest F4 Latest H7 FotS
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:39pm 18 Nov 2015
Copy link to clipboard 
Print this post

Could you put the variables into a string?

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 08:46pm 18 Nov 2015
Copy link to clipboard 
Print this post

Clever idea, fellas - thanks - never thought of that. I will look into this, but that would be a good way to do it, as ALL variables are only one byte each(control bytes for the preamp chip), so I could have a routine to build a single string consisting of the bytes I need, then read that back and decode it at powerup.

Excellent idea, chums!
Smoke makes things work. When the smoke gets out, it stops!
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 09:38pm 18 Nov 2015
Copy link to clipboard 
Print this post

I think the better approach (is it possible, Geoff?) would be to have an optional type word for the variables. Something like this:
DIM SAVED x, y, z
DIM SAVED a(100)
Then VAR SAVE and VAR RESTORE will not have any parameters.

http://rittle.org

--------------
 
Lou

Senior Member

Joined: 01/02/2014
Location: United States
Posts: 229
Posted: 09:55pm 18 Nov 2015
Copy link to clipboard 
Print this post

Grogs Wrote:
The VAR SAVE command is very handy, but I have found that there is a situation where you have lots of
variables you want to save, and they cannot be fitted on the one command line.

Yes, I need to save at least 200 six character numbers in variables - I could use the whole 2k. I thought about packing them into strings, but I'm not sure exactly how to do it. It would be nice to be able store them in variables like Grogs said VAR SAVE 1, VAR SAVE 2 etc. Any ideas would be helpful.

Thanks,

Lou
Microcontrollers - the other white meat
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 10:45pm 18 Nov 2015
Copy link to clipboard 
Print this post

I have just had a light bulb moment regarding how multiple saves could be technically implemented inside the interpreter. I will investigate and if it works out I will put it in the next version.

Geoff
Geoff Graham - http://geoffg.net
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 10:50pm 18 Nov 2015
Copy link to clipboard 
Print this post

Hi I have used strings in a data backup scheme for a recent program. I needed the ability to set some defaults initially (or for a clean install) and also backup to the flash when parameter changes were made within the program. The parameters are loaded on power up or defaults set if the flash has not previously been initialized.
Hope it makes some sense!


'Data Restore on power up
DataRestore 'recover from data backup
If Pin(pinButton)=0 Then backup=0 'force default load @ power up
If backup=0 Then 'if no backup has been saved then set defaults
Print "Store defaults
DM$(1)=""
DM$(2)=" ,Sens1,Thres,500,Norm,0,0,0,0,1,0,0,0,0,0" '14 items Sensor Mode
DM$(3)=" ,0,0,0,0,Secs,0,1" '8 items
DM$(4)="None,100,0,No,No,Auto,Menu" '7 items

DataBackup
End If

Sub DataBackup
backup=1
'copy array into separate strings to store to flash.
DM1$=dm$(1)
dm2$=dm$(2)
dm3$=dm$(3)
dm4$=dm$(4)
dm5$=dm$(5)
dm6$=dm$(6)
dm7$=dm$(7)
dm8$=dm$(8)
dm9$=dm$(9)
dm10$=dm$(10)
Var save backup,dm1$,dm2$,dm3$,dm4$,dm5$,dm6$,dm7$,dm8$,dm9$,dm10$
End Sub

Sub DataRestore
Var Restore
Print "Recover DM strings into DM Array from flash"
'Print "Backup ";backup;" DM1$ ";dm1$
dm$(1)=Dm1$ '
dm$(2)=dm2$
dm$(3)=dm3$
dm$(4)=dm4$
dm$(5)=dm5$
dm$(6)=dm6$
dm$(7)=dm7$
dm$(8)=dm8$
dm$(9)=dm9$
dm$(10)=dm10$
'print backup;" ";dm1$
'clear strings
DM1$=""
dm2$=""
dm3$=""
dm4$=""
dm5$=""
dm6$=""
dm7$=""
dm8$=""
dm9$=""
dm10$=""
End Sub


Mike

Codenquilts
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 11:29pm 18 Nov 2015
Copy link to clipboard 
Print this post

Hopefully Geoff's light bulb is bright.

I still have this same problem from here

http://www.thebackshed.com/forum/forum_posts.asp?TID=7445&KW=var+save
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:36pm 18 Nov 2015
Copy link to clipboard 
Print this post

@ ajkw - I remember that thread. Looks like it is my time to get bitten by this particular issue.
Smoke makes things work. When the smoke gets out, it stops!
 
Lou

Senior Member

Joined: 01/02/2014
Location: United States
Posts: 229
Posted: 05:49am 19 Nov 2015
Copy link to clipboard 
Print this post

ajkw wrote:
Hopefully Geoff's light bulb is bright.

I second that !!

Thanks Geoff, hope your idea works.

Lou
Microcontrollers - the other white meat
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025