@@ -33,7 +33,7 @@ def get_pressure_data():
33
33
return_data += "Pressure:\t 9.00E2\n "
34
34
return return_data
35
35
36
- def loop ():
36
+ def loop (data_window , data_text_window , data_logging_window , stdscr ):
37
37
38
38
continuing = 1
39
39
@@ -71,111 +71,83 @@ def loop():
71
71
return continuing
72
72
73
73
74
+ def main (stdscr ):
75
+ curses .curs_set (0 )
74
76
75
77
76
- send = ""
77
- out = ""
78
-
79
-
80
- preamble = "@253" #attention + default address, needed even with RS232
81
- command = ""
82
- terminator = ";FF"
83
-
84
-
85
- #Serial port communication
86
- # port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3.0)
87
- # assemble = preamble + command + terminator
88
- # port.write(assemble)
89
- # time.sleep(1)
90
- # while port.inWaiting() > 0:
91
- # out += port.read(1)
92
- # port.close()
93
-
94
-
95
- stdscr = curses .initscr ()
96
-
97
- #initialize screen
98
- curses .noecho ()
99
- curses .cbreak ()
100
- curses .curs_set (0 )
101
-
102
- if curses .has_colors ():
103
- curses .start_color ()
104
-
105
- #some color choices
106
- curses .init_pair (1 , curses .COLOR_RED , curses .COLOR_BLACK )
107
- curses .init_pair (2 , curses .COLOR_GREEN , curses .COLOR_BLACK )
108
- curses .init_pair (3 , curses .COLOR_BLUE , curses .COLOR_BLACK )
109
-
110
-
111
- #header
112
- stdscr .addstr ("MKS INTERFACE" , curses .A_REVERSE )
113
- stdscr .chgat (- 1 , curses .A_REVERSE )
78
+ #some color choices
79
+ curses .init_pair (1 , curses .COLOR_RED , curses .COLOR_BLACK )
80
+ curses .init_pair (2 , curses .COLOR_GREEN , curses .COLOR_BLACK )
81
+ curses .init_pair (3 , curses .COLOR_BLUE , curses .COLOR_BLACK )
114
82
83
+ #header
84
+ stdscr .addstr ("MKS INTERFACE" , curses .A_REVERSE )
85
+ stdscr .chgat (- 1 , curses .A_REVERSE )
115
86
116
- stdscr .addstr (curses .LINES - 1 , 0 , "'r' to refresh, 'p' to poll, 'q' to quit" )
87
+ stdscr .addstr (curses .LINES - 1 , 0 , "'r' to refresh, 'p' to poll, 'q' to quit" )
117
88
118
89
119
- # green r, blue p, red q
120
- stdscr .chgat (curses .LINES - 1 , 1 , 1 , curses .A_BOLD | curses .color_pair (2 ))
121
- stdscr .chgat (curses .LINES - 1 , 17 , 1 , curses .A_BOLD | curses .color_pair (3 ))
122
- stdscr .chgat (curses .LINES - 1 , 30 , 1 , curses .A_BOLD | curses .color_pair (1 ))
123
-
124
- #window to display gauge setup
125
- data_window = curses .newwin (curses .LINES - 2 , curses .COLS , 1 , 0 )
126
-
127
- #border windows
128
- data_text_border_window = data_window .subwin (curses .LINES - 6 , (curses .COLS - 4 )/ 2 , 3 , 2 )
129
- data_logging_border_window = data_window .subwin (curses .LINES - 6 , (curses .COLS - 4 )/ 2 , 3 , (curses .COLS - 4 )/ 2 + 2 )
130
-
131
-
132
-
133
- #creating subwindow to cleanly display text without touching window's borders
134
- data_text_window = data_text_border_window .subwin (curses .LINES - 8 , (curses .COLS - 6 )/ 2 - 1 , 4 , 3 )
135
-
90
+ # green r, blue p, red q
91
+ stdscr .chgat (curses .LINES - 1 , 1 , 1 , curses .A_BOLD | curses .color_pair (2 ))
92
+ stdscr .chgat (curses .LINES - 1 , 17 , 1 , curses .A_BOLD | curses .color_pair (3 ))
93
+ stdscr .chgat (curses .LINES - 1 , 30 , 1 , curses .A_BOLD | curses .color_pair (1 ))
94
+
136
95
137
- #subwindow for showing pressure log
138
- data_logging_window = data_logging_border_window . subwin (curses .LINES - 8 , ( curses .COLS - 6 ) / 2 - 1 , 4 , ( curses . COLS - 4 ) / 2 + 3 )
96
+ #window to display gauge setup
97
+ data_window = curses . newwin (curses .LINES - 2 , curses .COLS , 1 , 0 )
139
98
99
+ #border windows
100
+ data_text_border_window = data_window .subwin (curses .LINES - 6 , (curses .COLS - 4 )/ 2 , 3 , 2 )
101
+ data_logging_border_window = data_window .subwin (curses .LINES - 6 , (curses .COLS - 4 )/ 2 , 3 , (curses .COLS - 4 )/ 2 + 2 )
140
102
103
+
104
+ #creating subwindow to cleanly display text without touching window's borders
105
+ data_text_window = data_text_border_window .subwin (curses .LINES - 8 , (curses .COLS - 6 )/ 2 - 1 , 4 , 3 )
141
106
142
107
143
- #data_text_window.addstr("Press 'R' to load data")
144
- # data_logging_window.addstr("Press 'P' to log here" )
108
+ #subwindow for showing pressure log
109
+ data_logging_window = data_logging_border_window . subwin ( curses . LINES - 8 , ( curses . COLS - 6 ) / 2 - 1 , 4 , ( curses . COLS - 4 ) / 2 + 3 )
145
110
111
+ #draw a box around main window
112
+ data_window .box ()
146
113
147
- #draw a box around main window
148
- data_window .box ()
114
+ data_text_border_window . box ()
115
+ data_logging_border_window .box ()
149
116
150
- data_text_border_window . box ( )
151
- data_logging_border_window . box ( )
117
+ data_text_window . addstr ( "Press 'r' to load data" )
118
+ data_logging_window . addstr ( "Press 'p' to log pressure data here" )
152
119
153
- #data_logging_window.box()
154
- #data_text_window.box()
120
+ #update internal curses structures
121
+ stdscr .noutrefresh ()
122
+ data_window .noutrefresh ()
155
123
124
+ #redraw screen
125
+ curses .doupdate ()
156
126
157
- data_text_window .addstr ("Press 'r' to load data" )
158
- data_logging_window .addstr ("Press 'p' to log pressure data here" )
127
+ while True :
128
+ if not loop (data_window , data_text_window , data_logging_window , stdscr ):
129
+ break
159
130
160
131
161
- #update internal curses structures
162
- stdscr .noutrefresh ()
163
- data_window .noutrefresh ()
164
132
165
- #redraw screen
166
- curses . doupdate ()
133
+ send = ""
134
+ out = ""
167
135
168
- while True :
169
- if not loop ():
170
- break
171
136
137
+ preamble = "@253" #attention + default address, needed even with RS232
138
+ command = ""
139
+ terminator = ";FF"
172
140
141
+ curses .wrapper (main )
173
142
174
143
144
+ #Serial port communication
145
+ # port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3.0)
146
+ # assemble = preamble + command + terminator
147
+ # port.write(assemble)
148
+ # time.sleep(1)
149
+ # while port.inWaiting() > 0:
150
+ # out += port.read(1)
151
+ # port.close()
175
152
176
- #restore terminal settings
177
- curses .nocbreak ()
178
- curses .echo ()
179
- curses .curs_set (1 )
180
153
181
- curses .endwin ()
0 commit comments