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: AustraliaPosts: 1664 |
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). |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5923 |
Something like 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 ZealandPosts: 2294 |
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 :-) |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
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 ZealandPosts: 2294 |
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 |