Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 20:24 17 May 2024 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 : Debug flags.

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 01:12pm 23 Jan 2017
Copy link to clipboard 
Print this post

Hi all,

I have these code fragments at present:-

[Code] '====================Set Flag bits to indicate status for debug.
Sub SetFlags

StatFlags=0

If SolarVolts>=SolarMin Then StatFlags=&b000001
If SolarVolts>=SolarThres Then StatFlags=StatFlags+&b00000010
If TmpPan-TmpCur>=TmpDifPan Then StatFlags=StatFlags+&b00000100
If TmpOut-TmpInp>=TmpDif Then StatFlags=StatFlags+&b00001000
If PumpStat="Running" Then StatFlags=StatFlags+&b00010000
If PumpRunTime>600 then StatFlags=StatFlags+&b00100000
If Valve1Pos="Solar Mode" Then StatFlags=StatFlags+&b01000000
If Valve1Pos="Heat Pump Mode" Then StatFlags=StatFlags+&b10000000

End Sub

..
..
..

Text MM.HRes/2, MM.VRes*8/10, Bin$(StatFlags,8), CB, 2, 1, RGB(White)
[/code]

Currently its showing 01010111, just gives me feedback on some status.
Only catch is remembering which bit is which at times.

Any suggestions for displaying it as an alpha string that is a bit more informative?

IE 01010111 = StPdPTM

Where
S is valve position (S, H or U)
T is minimum Runtime (t or T)
P pump running
d differential met (not in case above)
P Panel temp met
T solar threshold met
M solar minimum met

using upper/lower case for all but the first character.

Building that sort of string seems a lot more involved than the 0/1 example above.

The first 2 digits 01010111 indicate the position of a motorised ball valve,
so a single digit could replace them but need to observe "00" as it would indicate the ball valve has not completed it's travel to the final position. Solar, Heat pump or Unknown.

Thanks

Phil

(Rambled a bit there).Edited by Phil23 2017-01-24
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 04:29pm 23 Jan 2017
Copy link to clipboard 
Print this post

Something like
  Quote   IF SolarVolts>=SolarMin THEN f6$="M" ELSE f6$ = "M"
IF SolarVolts>=SolarThres THEN f5$="T" ELSE f5$ = "T"
IF TmpPan-TmpCur>=TmpDifPan THEN f4$="D" ELSE f4$ = "D"
IF TmpOut-TmpInp>=TmpDif THEN f3$="M" ELSE f3$ = "M"
IF PumpStat="Running" THEN f2$="P" ELSE f2$ = "P"
IF PumpRunTime>600 THEN f1$="P" ELSE f1$ = "P"
SELECT CASE Valve1Pos
CASE "Solar Mode"
f0$ =
"S"
CASE "Heat Pump Mode"
f0$ =
"H"
CASE ELSE
f0$ =
"U"
END SELECT
StatFlags$ = f0$+f1$+f2$+f3$+f4$+f5$+f6$



In reality, you should be able to set the individual flag characters elsewhere in the code at the same time you set the "Heat Pump Mode" message etc.
I like having uppercase for ON and lower case for off rather than different characters for the state. Doesn't work for three states but all the others are doable.
I would also prefer to come up with characters that are not repeated between items such as 'P' in you example

You could use and array but I find typing f2$ easier than f$(2)

Jim
VK7JH
MMedit   MMBasic Help
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 10:30pm 23 Jan 2017
Copy link to clipboard 
Print this post

in this case (no pun intended), it would be really handy to access individual characters in a string as if it were an array of bytes. for example, if there was a string called A$ containing the text "ABCDEF", then the following syntax would work:

print A$[3] 'prints out the letter C
A$[5] = "5"
print A$ ' prints out the string "ABCD5F"

thinking more about it, this can currently be accomplished using PEEK and POKE...

A$="ABCDEF"
Print Chr$(Peek(var A$, 3))
Poke var A$, 5, Asc("5")
Print A$
End

> run
C
ABCD5F
>

although if it were supported i would prefer the [] notation, as it make for better code readable.


cheers,
rob :-)Edited by robert.rozee 2017-01-25
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 11:27pm 23 Jan 2017
Copy link to clipboard 
Print this post

  robert.rozee said   in this case (no pun intended), it would be really handy to access individual characters in a string as if it were an array of bytes. for example, if there was a string called A$ containing the text "ABCDEF", then the following syntax would work:

print A$[3] 'prints out the letter C
A$[5] = "5"
print A$ ' prints out the string "ABCD5F"



Really good concept, all ears here now.

So this is the case? You can return the entire array's content?

Print A$ prints the entire content of the array. All elements concatenated?

Or is that a hypothetical situation?

Even so, if Print A$ didn't return the entire content, a function to concatenate all elements would be simple.

I need to use more arrays in my code, but even after 40+ years, I'm still stuck getting past the 3rd dimension....

Phil

PS. Haven't used Peek & Poke since the TRS-80 days.....
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 12:09am 24 Jan 2017
Copy link to clipboard 
Print this post

it is a hypothetical. at the moment you need to use:
Poke var A$, m, Asc("5")
to alter the character at location m in A$

and to extract the character at location m, there is peek, or you could use:
Print Mid$(A$, m, 1)


cheers,
rob :-)
 
Print this page


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

© JAQ Software 2024