Last active
January 5, 2021 11:13
-
-
Save caelor/a0cc4dbf0270b1a5db3195203a2722ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set comment "Read source data. pi=power in, po=power out, pn=power net" | |
sensor pi_raw node1 @powerNetIn | |
sensor po_raw node1 @powerNetOut | |
op sub pn_raw pi_raw po_raw | |
set comment "Read min/max from memory cell. 0=pi_max, 1=po_max, 2=pn_max, 3=pn_min" | |
read pi_max cell1 1 | |
read po_max cell1 2 | |
read pn_max cell1 3 | |
read pn_min cell1 4 | |
set comment "update pi_max if needed" | |
jump 13 lessThanEq pi_raw pi_max | |
set pi_max pi_raw | |
write pi_max cell1 1 | |
set comment "update po_max if needed" | |
jump 17 lessThanEq po_raw po_max | |
set po_max po_raw | |
write po_max cell1 2 | |
set comment "update pi_max if needed" | |
jump 21 lessThanEq pn_raw pn_max | |
set pn_max pn_raw | |
write pn_max cell1 3 | |
set comment "update pi_max if needed" | |
jump 25 greaterThanEq pn_raw pn_min | |
set pn_min pn_raw | |
write pn_min cell1 4 | |
set comment "calculate scale for display 1 (in+out). Zero always at y=40" | |
op max d1_max_d pi_max po_max | |
op div d1_scale 39 d1_max_d | |
set comment "calculate scale for display 2. Zero y varies" | |
op sub pn_delta pn_max pn_min | |
op div d2_scale 77 pn_delta | |
op mul d2_zero_y pn_min d2_scale | |
op abs d2_zero_y d2_zero_y 0 | |
op add d2_zero_y d2_zero_y 1 | |
set comment "calculate the y values for each display" | |
op mul pi_defl d1_scale pi_raw | |
op mul po_defl d1_scale po_raw | |
op add pi_y 40 pi_defl | |
op sub po_y 40 po_defl | |
op mul pn_defl d2_scale pn_raw | |
op add pn_y d2_zero_y pn_defl | |
set comment "draw data onto displays" | |
read x cell1 0 | |
set comment "display 1, fill" | |
draw color 40 80 255 80 0 0 | |
draw lineRect x 40 1 pi_defl 0 0 | |
draw color 255 80 40 80 0 0 | |
draw lineRect x po_y 1 po_defl 0 0 | |
set comment "display 1, data point" | |
draw color 120 200 255 255 0 0 | |
draw lineRect x pi_y 1 1 0 0 | |
draw color 255 200 120 0 0 | |
draw lineRect x po_y 1 1 0 0 | |
set comment "display 1, zero line" | |
draw color 0 255 0 80 0 0 | |
draw lineRect x 40 1 1 0 0 | |
drawflush display1 | |
set comment "display 2, fill" | |
draw color 0 255 80 80 0 0 | |
jump 61 greaterThan pn_raw 0 | |
draw color 255 0 80 80 0 0 | |
draw line x pn_y x d2_zero_y 0 0 | |
set comment "display 2, data point" | |
draw color 128 200 255 255 0 0 | |
jump 66 greaterThan pn_raw 0 | |
draw color 255 200 128 255 0 0 | |
draw lineRect x pn_y 1 1 0 0 | |
set comment "display 2, zero line" | |
draw color 255 255 255 255 0 0 | |
draw lineRect x d2_zero_y 1 1 0 0 | |
drawflush display2 | |
set comment "increment x, save value to memory cell" | |
op add x x 1 | |
jump 75 lessThan x 80 | |
set x 0 | |
write x cell1 0 | |
set comment "blank leading x bar on both displays" | |
draw color 0 0 0 255 0 0 | |
draw lineRect x 0 2 80 0 0 | |
drawflush display1 | |
draw color 0 0 0 255 0 0 | |
draw lineRect x 0 2 80 0 0 | |
drawflush display2 | |
set comment "update message blocks with range info" | |
print "Power In: " | |
print pi_raw | |
print "/" | |
print pi_max | |
print ", Power Out: " | |
print po_raw | |
print "/" | |
print po_max | |
printflush message3 | |
print "Net Power: " | |
print pn_raw | |
print " (range=" | |
print pn_min | |
print " to " | |
print pn_max | |
print ")" | |
printflush message4 | |
set comment "reset to default values if switch is set" | |
sensor reset_sw switch1 @enabled | |
jump 114 equal reset_sw false | |
write 0 cell1 0 | |
write 50 cell1 1 | |
write 50 cell1 2 | |
write 10 cell1 3 | |
write -10 cell1 4 | |
draw clear 0 0 0 0 0 0 | |
drawflush display1 | |
draw clear 0 0 0 0 0 0 | |
drawflush display2 | |
control enabled switch1 0 0 0 0 | |
set comment "end" |
Sign up for free
to join this conversation on GitHub.
Already have an account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