1212import sys
1313import board
1414import nonblocking_serialinput as nb_serialin
15+ import digitalio
1516
1617##########################################
1718# globals
18- my_input = nb_serialin .NonBlockingSerialInput ()
19+ led = digitalio .DigitalInOut (board .LED )
20+ led .direction = digitalio .Direction .OUTPUT
1921
22+ running = True
2023
21- class MyProjectMainClass (object ):
22- """This is just the Container Class for my Project."""
23-
24- def __init__ (self , arg ):
25- super (MyProjectMainClass , self ).__init__ ()
26- self .arg = arg
27-
24+ runtime_print = True
25+ runtime_print_next = time .monotonic ()
26+ runtime_print_intervall = 1.0
2827
2928##########################################
3029# menu
3130
3231
33- def print_help ( self ):
32+ def userinput_print_help ( ):
3433 """Print Help."""
35- profile_list = ""
36- # for name, profile in self.profiles.items():
37- # profile_list += " {}\n".format(profile.title)
38- # ^--> random order..
39- for name in self .profiles_names :
40- current = ""
41- if self .profiles [name ] is self .profile_selected :
42- current = "*"
43- profile_list += " {: 1}{}\n " .format (current , self .profiles [name ].title_short )
34+ global runtime_print
35+ global runtime_print_intervall
4436 print (
45- "you do some things:\n "
46- "- 't': toggle print runtime ({print_runtime})\n "
47- "- 's': set print runtime intervall ({intervall: > 7.2f})\n "
48- "- 'pn' select next profil\n "
49- "{profile_list}"
50- "- 'calibrate'\n "
51- "- 'start' reflow cycle\n "
52- "- 'stop' reflow cycle\n "
37+ "you can change some things:\n "
38+ "- 'tr': toggle print runtime ({runtime_print})\n "
39+ "- 'time set:???': set print runtime intervall ({runtime_print_intervall: > 7.2f}s)\n "
40+ "- 'exit' stop program\n "
5341 "" .format (
54- profile_list = profile_list ,
55- heater_target = self . reflowcontroller . heater_target ,
42+ runtime_print = runtime_print ,
43+ runtime_print_intervall = runtime_print_intervall ,
5644 ),
5745 end = "" ,
5846 )
59- self .print_temperature ()
6047
6148
62- def check_input ( self ):
49+ def userinput_handling ( input_string ):
6350 """Check Input."""
64- input_string = input ()
65- # sys.stdin.read(1)
66- if "pn" in input_string :
67- self .reflowcontroller .profile_select_next ()
68- if "pid p" in input_string :
69- value = nb_serialin .parse_value (input_string , "pid p" )
70- if value :
71- self .reflowcontroller .pid .P_gain = value
72- if "h" in input_string :
73- value = nb_serialin .parse_value (input_string , "h" )
51+ global running
52+ global runtime_print
53+ global runtime_print_intervall
54+
55+ if "tr" in input_string :
56+ runtime_print = not runtime_print
57+ if "time set" in input_string :
58+ print ("time set:" )
59+ value = nb_serialin .parse_value (input_string , "time set" )
7460 if nb_serialin .is_number (value ):
75- self .reflowcontroller .heater_target = value
76- # prepare new input
77- self .print_help ()
78- print (">> " , end = "" )
79-
80-
81- @staticmethod
82- def input_parse_pixel_set (input_string ):
83- """parse pixel_set."""
84- # row = 0
85- # col = 0
86- # value = 0
87- # sep_pos = input_string.find(",")
88- # sep_value = input_string.find(":")
89- # try:
90- # col = int(input_string[1:sep_pos])
91- # except ValueError as e:
92- # print("Exception parsing 'col': ", e)
93- # try:
94- # row = int(input_string[sep_pos + 1 : sep_value])
95- # except ValueError as e:
96- # print("Exception parsing 'row': ", e)
97- # try:
98- # value = int(input_string[sep_value + 1 :])
99- # except ValueError as e:
100- # print("Exception parsing 'value': ", e)
101- # pixel_index = 0
102- pass
61+ runtime_print_intervall = value
62+ if "exit" in input_string :
63+ print ("Stop Program running." )
64+ running = False
10365
10466
67+ my_input = nb_serialin .NonBlockingSerialInput (
68+ parse_input_fn = userinput_handling ,
69+ print_help_fn = userinput_print_help ,
70+ )
71+
10572##########################################
10673# functions
10774
10875
109- def main_update (self ):
76+ def main_update ():
11077 """Do all the things your main code want's to do...."""
111- pass
78+ global runtime_print
79+ global runtime_print_next
80+ global runtime_print_intervall
81+
82+ if runtime_print :
83+ if runtime_print_next < time .monotonic ():
84+ runtime_print_next = time .monotonic () + runtime_print_intervall
85+ print ("{: > 7.2f}s" .format (time .monotonic ()))
86+ led .value = not led .value
11287
11388
11489##########################################
@@ -128,6 +103,7 @@ def main():
128103 print (42 * "*" )
129104 print ("run" )
130105
106+ global running
131107 running = True
132108 while running :
133109 try :
0 commit comments