comparison Discovery/Src/tInfoLog.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children cc8e24374b83
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file Discovery/Src/tInfoLog.c
5 /// \brief Main Template file for Menu Page Deco
6 /// \author heinrichs weikamp gmbh
7 /// \date 31-July-2014
8 ///
9 /// \details
10 ///
11 /// $Id$
12 ///////////////////////////////////////////////////////////////////////////////
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
14 ///
15 /// This program is free software: you can redistribute it and/or modify
16 /// it under the terms of the GNU General Public License as published by
17 /// the Free Software Foundation, either version 3 of the License, or
18 /// (at your option) any later version.
19 ///
20 /// This program is distributed in the hope that it will be useful,
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 /// GNU General Public License for more details.
24 ///
25 /// You should have received a copy of the GNU General Public License
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 //////////////////////////////////////////////////////////////////////////////
28
29 /* Includes ------------------------------------------------------------------*/
30 #include "tInfoLog.h"
31
32 #include "gfx_fonts.h"
33 #include "logbook.h"
34 #include "show_logbook.h"
35 #include "tHome.h"
36 #include "tInfo.h"
37 #include "tMenu.h"
38 #include "unit.h"
39
40 /* Exported variables --------------------------------------------------------*/
41
42 /* Private types -------------------------------------------------------------*/
43 typedef struct
44 {
45 uint8_t page;
46 uint8_t line;
47 uint8_t linesAvailableForPage;
48 uint8_t modeFlipPages;
49 uint8_t maxpages;
50 } SInfoLogMemory;
51
52 /* Private variables ---------------------------------------------------------*/
53 GFX_DrawCfgScreen INFOLOGscreen;
54 GFX_DrawCfgScreen *pMenuCursor, *pMenuCursorDesignSolo;
55 GFX_DrawCfgWindow INFOLOGwindow;
56
57 SInfoLogMemory infolog;
58
59 /* Private function prototypes -----------------------------------------------*/
60 void nextLineInfoLog(void);
61 void tInfoLog_BuildAndShowNextPage(void);
62 void tInfoLog_nextLine(void);
63 void showLog(void);
64 void showNextLogPage(void);
65 void stepBackInfo(void);
66 void stepForwardInfo(void);
67 void showLogExit(void);
68
69 /* Exported functions --------------------------------------------------------*/
70 void tInfoLog_init(void)
71 {
72 INFOLOGscreen.FBStartAdress = 0;
73 INFOLOGscreen.ImageHeight = 480;
74 INFOLOGscreen.ImageWidth = 800;
75 INFOLOGscreen.LayerIndex = 1;
76
77 INFOLOGwindow.Image = &INFOLOGscreen;
78 INFOLOGwindow.WindowNumberOfTextLines = 6;
79 INFOLOGwindow.WindowLineSpacing = 65;
80 INFOLOGwindow.WindowTab = 400;
81 INFOLOGwindow.WindowX0 = 20;
82 INFOLOGwindow.WindowX1 = 779;
83 INFOLOGwindow.WindowY0 = 4 + 25;
84 INFOLOGwindow.WindowY1 = 390 + 25;
85 }
86
87
88 void openInfoLogLastDive(void)
89 {
90 infolog.page = 0;
91 SLogbookHeader logbookHeader;
92 if(logbook_getHeader(0,&logbookHeader))
93 {
94 set_globalState(StILOGSHOW); // all the rest with zeros
95 infolog.page = 1;
96 infolog.line = 1;
97 show_logbook_test(1, 0);
98 }
99 else
100 openLog(0);
101 }
102
103
104 void openLog(_Bool recallKeepPage)
105 {
106 if(recallKeepPage && infolog.page)
107 infolog.page--;
108 else
109 infolog.page = 0;
110
111 infolog.modeFlipPages = 1;
112 set_globalState_Log_Page(infolog.page);
113 infolog.maxpages = (logbook_getNumberOfHeaders() + 5) / 6;
114 tInfoLog_BuildAndShowNextPage();
115
116 pMenuCursor = get_PointerMenuCursorScreen();
117 pMenuCursorDesignSolo = get_PointerMenuCursorDesignSoloScreen();
118
119 change_CLUT_entry(CLUT_MenuLineSelectedSides, CLUT_InfoPageLogbook);
120 change_CLUT_entry(CLUT_MenuLineSelectedSeperator, CLUT_InfoPageLogbook);
121
122 //GFX_ResetLayer(TOP_LAYER);
123 //GFX_ResetLayer(BACKGRD_LAYER);
124
125 if(infolog.page == 255)
126 GFX_SetFrameBottom((INFOLOGscreen.FBStartAdress), 0, 0, 800, 480);
127 else
128 {
129 // very old: GFX_SetFrameBottom((pMenuCursor->FBStartAdress), 0, 0, 800, 390);
130 // no, set cursor to firt line instead with tInfoLog_nextLine() GFX_SetFrameBottom((pMenuCursorDesignSolo->FBStartAdress), 0, 25, 800, 390);
131 tInfoLog_nextLine();
132 }
133 }
134
135
136 void sendActionToInfoLogList(uint8_t sendAction)
137 {
138 switch(sendAction)
139 {
140 case ACTION_BUTTON_ENTER:
141 stepForwardInfo();
142 break;
143 case ACTION_BUTTON_NEXT:
144
145 if(infolog.modeFlipPages)
146 {
147 tInfoLog_BuildAndShowNextPage();
148 // GFX_SetFrameBottom((pMenuCursor->FBStartAdress), 0, 25, 800, 390);
149 }
150 else
151 tInfoLog_nextLine();
152 break;
153 case ACTION_TIMEOUT:
154 case ACTION_MODE_CHANGE:
155 case ACTION_BUTTON_BACK:
156 stepBackInfo();
157 default:
158 break;
159 case ACTION_IDLE_TICK:
160 case ACTION_IDLE_SECOND:
161 break;
162 }
163 }
164
165
166 void sendActionToInfoLogShow(uint8_t sendAction)
167 {
168 switch(sendAction)
169 {
170 case ACTION_BUTTON_ENTER:
171 break;
172 case ACTION_BUTTON_NEXT:
173 showNextLogPage();
174 break;
175 case ACTION_TIMEOUT:
176 case ACTION_MODE_CHANGE:
177 case ACTION_BUTTON_BACK:
178 if(get_globalState() == StILOGSHOW) // no page nor line
179 {
180 openLog(1);
181 }
182 else
183 {
184 showLogExit();
185 }
186 show_logbook_exit();
187 default:
188 break;
189 case ACTION_IDLE_TICK:
190 case ACTION_IDLE_SECOND:
191 break;
192 }
193 }
194
195
196 /* Private functions ---------------------------------------------------------*/
197
198 void exitLog(void)
199 {
200 //set_globalState_tHome();
201 exitInfo();
202 releaseFrame(15,INFOLOGscreen.FBStartAdress);
203 }
204
205
206 void stepBackInfo(void)
207 {
208 if(infolog.modeFlipPages == 0)
209 {
210 infolog.line = 0;
211 infolog.modeFlipPages = 1;
212 GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 25, 800, 390);
213 }
214 else
215 exitLog();
216 }
217
218
219 void stepForwardInfo(void)
220 {
221 if(infolog.modeFlipPages == 1)
222 {
223 tInfoLog_nextLine();
224 }
225 else
226 showLog();
227 }
228
229
230 void tInfoLog_BuildAndShowNextPage(void)
231 {
232 char text[MAX_PAGE_TEXTSIZE];
233 uint16_t textPointer = 0;
234 SLogbookHeader logbookHeader;
235 // uint16_t divetime = logbookHeader.diveTimeMinutes;
236 // uint16_t maxDepth = logbookHeader.maxDepth/100;
237 int i = 0;
238 uint8_t date[2], month,day;
239
240 if(INFOLOGscreen.FBStartAdress)
241 releaseFrame(15,INFOLOGscreen.FBStartAdress);
242 INFOLOGscreen.FBStartAdress = getFrame(15);
243
244 infolog.page += 1;
245 infolog.linesAvailableForPage = 0;
246
247 if((infolog.page < 1) || (infolog.page > 43)) /* max with 256 entries */
248 infolog.page = 1;
249
250
251 text[0] = '\001';
252 text[1] = TXT_Logbook;
253 text[2] = 0;
254 gfx_write_topline_simple(&INFOLOGscreen, text, CLUT_InfoPageLogbook);
255
256 *text = 0;
257 if(!logbook_getHeader((infolog.page - 1) * 6,&logbookHeader))
258 {
259 infolog.page = 1;
260 if(!logbook_getHeader((infolog.page - 1) * 6,&logbookHeader))
261 {
262 infolog.page = 255;
263 infolog.linesAvailableForPage = 0;
264 text[0] = TXT_LogbookEmpty;
265 text[1] = 0;
266 }
267 }
268
269 if((*text == 0) && (infolog.maxpages > 1))
270 {
271 snprintf(text,8, "\002" "%u/%u", infolog.page, infolog.maxpages);
272 gfx_write_topline_simple(&INFOLOGscreen, text, CLUT_InfoPageLogbook);
273 *text = 0;
274 }
275
276 if(*text == 0)
277 {
278 infolog.line = 0;
279 textPointer = 0;
280 if(settingsGetPointer()->date_format == DDMMYY)
281 {
282 day = 0;
283 month = 1;
284 }
285 else
286 {
287 day = 1;
288 month = 0;
289 }
290 for(i = 0; i < 6; i++)
291 {
292 if(i)
293 {
294 if(!logbook_getHeader(((infolog.page - 1) * 6) + i, &logbookHeader))
295 break;
296 }
297 infolog.linesAvailableForPage += 1;
298 uint16_t divetime = logbookHeader.diveTimeMinutes;
299 uint16_t maxDepthMeter = logbookHeader.maxDepth/100;
300 uint16_t maxDepthSubmeter = (logbookHeader.maxDepth - maxDepthMeter * 100)/10;
301 uint16_t number = ((infolog.page - 1) * 6) + i + 1;
302 if(settingsGetPointer()->logbookOffset)
303 {
304 if(number <= settingsGetPointer()->logbookOffset)
305 number = settingsGetPointer()->logbookOffset + 1 - number;
306 }
307 date[day] = logbookHeader.dateDay;
308 date[month] = logbookHeader.dateMonth;
309
310 text[textPointer++] = '\034';// monospaced space large size mode
311 textPointer += snprintf(&text[textPointer], 20,"\021%04u \020", number);
312 /* if(number < 1000)
313 textPointer += snprintf(&text[textPointer], 20,"\021%2u \020", number);
314 else
315 textPointer += snprintf(&text[textPointer], 20,"\021\016\016%3u \017\020", number);
316 */
317 textPointer += snprintf(&text[textPointer], 20,"%02d.%02d ",date[0],date[1]);
318 textPointer += snprintf(&text[textPointer], 20,"%02d:%02d ",logbookHeader.timeHour,logbookHeader.timeMinute);
319 switch(logbookHeader.decoModel)
320 {
321 case 1:
322 textPointer += snprintf(&text[textPointer],20,"\016\016 GF \017");
323 break;
324 case 2:
325 textPointer += snprintf(&text[textPointer],20,"\016\016 VPM \017");
326 break;
327 default:
328 textPointer += snprintf(&text[textPointer],20,"\016\016 * \017");
329 break;
330 }
331
332 if(settingsGetPointer()->nonMetricalSystem)
333 {
334 float maxDepthFeet = 0;
335 maxDepthFeet = unit_depth_float(((float)logbookHeader.maxDepth)/100);
336 textPointer += snprintf(&text[textPointer], 20,"%3.0f\016\016ft\017 ", maxDepthFeet);
337 }
338 else
339 {
340 textPointer += snprintf(&text[textPointer], 20,"%3d.%d\016\016m\017 ", maxDepthMeter,maxDepthSubmeter);
341 }
342 textPointer += snprintf(&text[textPointer], 20,"%3d'\n\r", divetime);
343 }
344 }
345 GFX_write_string(&FontT48, &INFOLOGwindow, text,1);
346
347 if(infolog.linesAvailableForPage > 1)
348 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
349 else if(infolog.page == 255)
350 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,0,0);
351 else
352 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,0);
353
354 GFX_SetFrameTop(INFOLOGscreen.FBStartAdress);
355 set_globalState_Log_Page(infolog.page);
356 }
357
358
359 void tInfoLog_nextLine(void)
360 {
361 if(infolog.linesAvailableForPage == 0)
362 return;
363
364 infolog.line += 1;
365 if(infolog.line > infolog.linesAvailableForPage)
366 infolog.line = 1;
367
368 infolog.modeFlipPages = 0;
369
370 GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
371 }
372
373
374 void showLogExit(void)
375 {
376 GFX_SetFrameTop(INFOLOGscreen.FBStartAdress);
377 GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
378 set_globalState_Log_Page(infolog.page);
379 }
380
381
382 void showLog(void)
383 {
384 uint8_t stepBack;
385
386 if(infolog.page == 255)
387 return;
388
389 stepBack = (6 * (infolog.page - 1)) + infolog.line - 1;
390 //build_logbook_test();
391 show_logbook_test(1, stepBack);
392 }
393
394
395 void showNextLogPage(void)
396 {
397 uint8_t stepBack;
398
399 if(infolog.page == 255)
400 return;
401
402 stepBack = (6 * (infolog.page - 1)) + infolog.line - 1;
403 //build_logbook_test();
404 show_logbook_test(0, stepBack);
405 }
406
407