Finializing tests
[solderbot.git] / src / SBUI / SBUI.cpp
blob0d14c966be29c7873dba73f724bb609f1d3d13c7
1 /*
2 Copyright 2008 Lukas Kropatschek lukas.krop@gmail.com
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "SBUI.h"
20 //#include "StaticStrings.h"
22 #include <LCD.h>
23 #include <IOManager.h>
24 #include <core/defines.h>
25 #include <SolderManager.h>
27 #define clearViewArea() LCD.drawRect(21, 0, 109, 130, FILL, WHITE);
28 #define clearStatusMsgArea() LCD.drawRect(0,0,19,69,FILL,WHITE);
31 SBUI::SBUI()
33 total = 0;
36 void SBUI::update()
38 LCD.putVariable("X:", SolderMgr.curX, 100, 5, RED, WHITE, 30);
39 LCD.putVariable("Y:", SolderMgr.curY, 90, 5, BLUE, WHITE, 30);
42 void SBUI::draw()
44 clearViewArea();
46 drawStatusBar();
49 void SBUI::drawCoordInput()
51 byte xcursor = 0;
52 byte ycursor = 0;
53 byte curField = 0;
54 byte xArray[] = { 0, 0, 0};
55 byte yArray[] = { 0, 0, 0};
56 byte xpos = 2;
57 byte ypos = 2;
59 LCD.putChar('X', 65, 5, RED, WHITE);
60 LCD.putChar('Y', 50, 5, BLUE, WHITE);
62 LCD.drawRect(49, 15, 75, 75, FILL, WHITE);
64 LCD.drawRect(64, 15, 75, 75, 0, RED);
65 LCD.drawRect(49, 15, 60, 75, 0, GREY);
67 while (true)
69 // acquire PS2 keycode
70 byte ps2 = IOMgr.getPS2Keycode();
72 // delete the last character and set cursor position accordingly
74 if (ps2 == KEYCODE_BACKSPACE)
76 if (curField == 0)
78 xArray[xpos] = 0;
80 if (xcursor != 0)
81 xcursor -= 1;
83 if (xpos != 2)
84 xpos++;
86 // clear with an space char
87 LCD.putChar(' ', 65, (16 + (6 * xcursor)), BLACK, WHITE);
90 if (curField == 1)
92 yArray[ypos] = 0;
94 if (ycursor != 0)
95 ycursor -= 1;
97 if (ypos != 2)
98 ypos++;
100 LCD.putChar(' ', 50, (16 + (6 * ycursor)), BLACK, WHITE);
105 if (ps2 == KEYCODE_TAB)
107 //Toogle current coordinate input (x/y)
108 if (curField == 0)
110 curField = 1;
111 LCD.drawRect(64, 15, 75, 75, 0, GREY);
112 LCD.drawRect(49, 15, 60, 75, 0, RED);
115 else
117 curField = 0;
118 LCD.drawRect(64, 15, 75, 75, 0, RED);
119 LCD.drawRect(49, 15, 60, 75, 0, GREY);
123 if (ps2 == KEYCODE_ENTER)
125 byte x, y;
127 switch (xcursor)
130 case 1:
131 x = xArray[2];
132 break;
134 case 2:
135 x = xArray[1] + (xArray[2] * 10);
136 break;
138 case 3:
139 x = xArray[0] + (xArray[1] * 10) + (xArray[2] * 100);
140 break;
142 default:
143 x = 0;
144 break;
147 switch (ycursor)
150 case 1:
151 y = yArray[2];
152 break;
154 case 2:
155 y = yArray[1] + (yArray[2] * 10);
156 break;
158 case 3:
159 y = yArray[0] + (yArray[1] * 10) + (yArray[2] * 10);
160 break;
162 default:
163 y = 0;
164 break;
167 //LCD.putVariable("x:", x, 35, 5, BLACK, WHITE, 30);
168 //LCD.putVariable("y:", y, 25, 5, BLACK, WHITE, 30);
169 SolderMgr.goTo(x, y);
171 // get out of the endless loop
172 break;
175 else
177 if (ps2 != 0 && ps2 != KEYCODE_TAB && ps2 != KEYCODE_BACKSPACE && ps2 != KEYCODE_ENTER)
179 // do work for the x field
180 if (curField == 0)
182 if (xcursor <= 2)
184 // print char on screen
185 LCD.putChar(ps2, 65, (16 + (6 * xcursor)), BLACK, WHITE);
186 // add value to data array
187 xArray[xpos] = ps2 - 48;
188 xcursor++;
190 if (xpos != 0)
191 xpos--;
195 if (curField == 1)
197 if (ycursor <= 2)
199 LCD.putChar(ps2, 50, (16 + (6 * ycursor)), BLACK, WHITE);
200 yArray[ypos] = ps2 - 48;
201 ycursor++;
203 if (ypos != 0)
204 ypos--;
213 void SBUI::drawStatusBar()
215 // draw a line and the current status text
216 LCD.drawLine(20, 0, 20, 130, BLACK);
217 // draw free SRAM
218 LCD.putVariable("SRAM:", availableSRAM(), 5, 70, BLACK, WHITE, 40);
220 // check whicht status message should be displayed
222 /* switch (code)
225 case 0:
226 // clear area
227 clearStatusMsgArea();
228 LCD.putString ( (const char*) getPGMStr (Idle), 5, 5, BLACK, WHITE);
229 lastStatusMsg = 0;
230 break;
232 case 1:
233 // only draw status message if it is not the
234 // same as the currently displayed
236 if (lastStatusMsg != 1)
238 clearStatusMsgArea();
239 LCD.putString ( (const char*) getPGMStr (Solder), 5, 5, BLACK, WHITE);
242 lastStatusMsg = 1;
244 break;
246 case 2:
248 if (lastStatusMsg != 2)
250 clearStatusMsgArea();
251 LCD.putString ( (const char*) getPGMStr (Moving), 5, 5, BLACK, WHITE);
254 lastStatusMsg = 2;
256 break;
258 case 3:
260 if (lastStatusMsg != 3)
262 clearStatusMsgArea();
263 LCD.putString ( (const char*) getPGMStr (Loading), 5, 5, BLACK, WHITE);
266 lastStatusMsg = 3;
268 break;
274 void SBUI::drawShowTrack()
276 // draw coord system
277 clearViewArea();
279 for (byte i = 0; i < 16; i++)
281 LCD.drawLine(35, 25 + (5 * i), 105, 25 + (5 * i), LIGHTGREY);
283 if (i < 14)
284 LCD.drawLine(35 + (5 * i), 25, 35 + (5 * i), 105, LIGHTGREY);
287 // y axis
288 LCD.drawLine(35, 25, 105, 25, BLACK);
290 // x axis
291 LCD.drawLine(35, 25, 35, 105, BLACK);
293 // loop through all points / 2 doing 2 points each time
294 for (byte i = 1; i <= (total / 2); i++)
296 // aquire point data
297 byte x1;
298 byte y1;
299 byte x2;
300 byte y2;
301 x1 = IOMgr.smap[i][1];
302 y1 = IOMgr.smap[i][2];
303 x2 = IOMgr.smap[i+1][1];
304 y2 = IOMgr.smap[i+1][2];
306 //coordinate system finished draw points and lines now
308 // draw a line from point to point
309 LCD.drawLine(35 + y1, 25 + x1, 35 + y2, 25 + x2, LIGHTBLUE);
311 // draw points
312 LCD.drawX(35 + y1, 25 + x1, RED);
313 LCD.drawX(35 + y2, 25 + x2, RED);
316 LCD.putVariable("Points:", total, 22, 5, BLACK, WHITE);
319 void SBUI::drawLoadTrack(byte count, byte coord, byte pos)
321 // if we haven't started to receive
322 if (count == 0)
324 clearViewArea();
325 LCD.putString("Waiting for SMap..", 100, 5, BLACK, WHITE);
328 if (count > 0 && count != 101)
330 // display what we received yet and the percentage
331 LCD.drawRect(100, 5, 110, 100, FILL, WHITE);
332 LCD.putVariable("RX:", count, 100, 5, BLACK, WHITE, 30);
333 LCD.putVariable("/", total, 100, 42, BLACK, WHITE, 30);
334 LCD.putVariable("", ((count * 100) / total), 100, 70, BLACK, WHITE, 3);
335 LCD.putChar('%', 100, 92, BLACK, WHITE);
337 // display x coord
339 if (pos == 1)
341 LCD.putVariable("LP(", coord, 90, 5, BLACK, WHITE, 30);
344 // display y coord
346 if (pos == 2)
348 LCD.putVariable("/", coord, 90, 42, BLACK, WHITE, 30);
349 LCD.putChar(')', 90, 67, BLACK, WHITE);
354 // if we finished receiving the count is set to 101
356 if (count == 101)
358 LCD.putString("Enter -> start", 70, 5, BLACK, WHITE);
359 LCD.putString("V -> show track", 60, 5, BLACK, WHITE);
360 while(true)
362 byte ps2 = IOMgr.getPS2Keycode();
364 if(ps2 == KEYCODE_V)
366 drawShowTrack();
367 break;
369 else if(ps2 == KEYCODE_ENTER)
371 drawSolder();
372 break;
375 //TODO Add info message for start soldering
379 void SBUI::drawSolder()
381 clearViewArea();
382 update();
383 LCD.putString("Space -> Pause", 70, 5, BLACK, WHITE);
385 byte i = 0;
387 while(i <= total)
389 byte ps2 = IOMgr.getPS2Keycode();
391 if(ps2 == KEYCODE_SPACE)
393 while(true)
395 byte pause = IOMgr.getPS2Keycode();
396 if(pause == KEYCODE_SPACE)
397 break;
401 byte x,y;
403 x = IOMgr.smap[i][1];
404 y = IOMgr.smap[i][2];
406 SolderMgr.goTo(x,y);
407 SolderMgr.solder();
409 i++;
415 SBUI sbui = SBUI();