38
+ − 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"
452
+ − 39 #include "externLogbookFlash.h"
+ − 40 #include "configuration.h"
594
+ − 41 #include "logbook_miniLive.h"
38
+ − 42
+ − 43 /* Exported variables --------------------------------------------------------*/
+ − 44
+ − 45 /* Private types -------------------------------------------------------------*/
+ − 46 typedef struct
+ − 47 {
+ − 48 uint8_t page;
+ − 49 uint8_t line;
+ − 50 uint8_t linesAvailableForPage;
+ − 51 uint8_t modeFlipPages;
+ − 52 uint8_t maxpages;
+ − 53 } SInfoLogMemory;
+ − 54
+ − 55 /* Private variables ---------------------------------------------------------*/
+ − 56 GFX_DrawCfgScreen INFOLOGscreen;
+ − 57 GFX_DrawCfgScreen *pMenuCursor, *pMenuCursorDesignSolo;
+ − 58 GFX_DrawCfgWindow INFOLOGwindow;
+ − 59
+ − 60 SInfoLogMemory infolog;
+ − 61
+ − 62 /* Private function prototypes -----------------------------------------------*/
+ − 63 void tInfoLog_BuildAndShowNextPage(void);
+ − 64 void tInfoLog_nextLine(void);
+ − 65 void showLog(void);
+ − 66 void showNextLogPage(void);
+ − 67 void stepBackInfo(void);
+ − 68 void stepForwardInfo(void);
+ − 69 void showLogExit(void);
+ − 70
+ − 71 /* Exported functions --------------------------------------------------------*/
+ − 72 void tInfoLog_init(void)
+ − 73 {
+ − 74 INFOLOGscreen.FBStartAdress = 0;
+ − 75 INFOLOGscreen.ImageHeight = 480;
+ − 76 INFOLOGscreen.ImageWidth = 800;
+ − 77 INFOLOGscreen.LayerIndex = 1;
+ − 78
+ − 79 INFOLOGwindow.Image = &INFOLOGscreen;
+ − 80 INFOLOGwindow.WindowNumberOfTextLines = 6;
+ − 81 INFOLOGwindow.WindowLineSpacing = 65;
+ − 82 INFOLOGwindow.WindowTab = 400;
+ − 83 INFOLOGwindow.WindowX0 = 20;
+ − 84 INFOLOGwindow.WindowX1 = 779;
110
+ − 85 if(!settingsGetPointer()->FlipDisplay)
+ − 86 {
+ − 87 INFOLOGwindow.WindowY0 = 4 + 25;
+ − 88 INFOLOGwindow.WindowY1 = 390 + 25;
+ − 89 }
+ − 90 else
+ − 91 {
+ − 92 INFOLOGwindow.WindowY0 = 479 - 390;
+ − 93 INFOLOGwindow.WindowY1 = 479 - 25;
+ − 94 }
38
+ − 95 }
+ − 96
+ − 97
+ − 98 void openInfoLogLastDive(void)
+ − 99 {
+ − 100 infolog.page = 0;
+ − 101 SLogbookHeader logbookHeader;
+ − 102 if(logbook_getHeader(0,&logbookHeader))
+ − 103 {
+ − 104 set_globalState(StILOGSHOW); // all the rest with zeros
+ − 105 infolog.page = 1;
+ − 106 infolog.line = 1;
+ − 107 show_logbook_test(1, 0);
+ − 108 }
+ − 109 else
+ − 110 openLog(0);
+ − 111 }
+ − 112
+ − 113
+ − 114 void openLog(_Bool recallKeepPage)
+ − 115 {
+ − 116 if(recallKeepPage && infolog.page)
+ − 117 infolog.page--;
+ − 118 else
+ − 119 infolog.page = 0;
+ − 120
+ − 121 infolog.modeFlipPages = 1;
+ − 122 set_globalState_Log_Page(infolog.page);
+ − 123 infolog.maxpages = (logbook_getNumberOfHeaders() + 5) / 6;
+ − 124 tInfoLog_BuildAndShowNextPage();
+ − 125
+ − 126 pMenuCursor = get_PointerMenuCursorScreen();
+ − 127 pMenuCursorDesignSolo = get_PointerMenuCursorDesignSoloScreen();
+ − 128
+ − 129 change_CLUT_entry(CLUT_MenuLineSelectedSides, CLUT_InfoPageLogbook);
+ − 130 change_CLUT_entry(CLUT_MenuLineSelectedSeperator, CLUT_InfoPageLogbook);
+ − 131
+ − 132 //GFX_ResetLayer(TOP_LAYER);
+ − 133 //GFX_ResetLayer(BACKGRD_LAYER);
+ − 134
+ − 135 if(infolog.page == 255)
+ − 136 GFX_SetFrameBottom((INFOLOGscreen.FBStartAdress), 0, 0, 800, 480);
+ − 137 else
+ − 138 {
+ − 139 // very old: GFX_SetFrameBottom((pMenuCursor->FBStartAdress), 0, 0, 800, 390);
+ − 140 // no, set cursor to firt line instead with tInfoLog_nextLine() GFX_SetFrameBottom((pMenuCursorDesignSolo->FBStartAdress), 0, 25, 800, 390);
+ − 141 tInfoLog_nextLine();
+ − 142 }
+ − 143 }
+ − 144
+ − 145
+ − 146 void sendActionToInfoLogList(uint8_t sendAction)
+ − 147 {
+ − 148 switch(sendAction)
+ − 149 {
+ − 150 case ACTION_BUTTON_ENTER:
+ − 151 stepForwardInfo();
+ − 152 break;
+ − 153 case ACTION_BUTTON_NEXT:
+ − 154
+ − 155 if(infolog.modeFlipPages)
+ − 156 {
+ − 157 tInfoLog_BuildAndShowNextPage();
+ − 158 // GFX_SetFrameBottom((pMenuCursor->FBStartAdress), 0, 25, 800, 390);
+ − 159 }
+ − 160 else
+ − 161 tInfoLog_nextLine();
+ − 162 break;
+ − 163 case ACTION_TIMEOUT:
+ − 164 case ACTION_MODE_CHANGE:
+ − 165 case ACTION_BUTTON_BACK:
+ − 166 stepBackInfo();
186
+ − 167 break;
38
+ − 168 default:
+ − 169 break;
+ − 170 case ACTION_IDLE_TICK:
+ − 171 case ACTION_IDLE_SECOND:
+ − 172 break;
+ − 173 }
+ − 174 }
+ − 175
+ − 176
+ − 177 void sendActionToInfoLogShow(uint8_t sendAction)
+ − 178 {
594
+ − 179 #ifdef ENABLE_T3_PROFILE_VIEW
+ − 180 uint8_t stepBack;
+ − 181 #endif
38
+ − 182 switch(sendAction)
+ − 183 {
+ − 184 case ACTION_BUTTON_ENTER:
594
+ − 185 #ifdef ENABLE_T3_PROFILE_VIEW
+ − 186 if(getActiveLogPage() == 1)
+ − 187 {
+ − 188 stepBack = (6 * (infolog.page - 1)) + infolog.line - 1;
+ − 189 prepareReplayLog(stepBack);
+ − 190 updateReplayIncdicator(&INFOLOGscreen);
+ − 191 }
+ − 192 #endif
38
+ − 193 break;
+ − 194 case ACTION_BUTTON_NEXT:
+ − 195 showNextLogPage();
+ − 196 break;
+ − 197 case ACTION_TIMEOUT:
+ − 198 case ACTION_MODE_CHANGE:
+ − 199 case ACTION_BUTTON_BACK:
+ − 200 if(get_globalState() == StILOGSHOW) // no page nor line
+ − 201 {
+ − 202 openLog(1);
+ − 203 }
+ − 204 else
+ − 205 {
+ − 206 showLogExit();
+ − 207 }
+ − 208 show_logbook_exit();
186
+ − 209 break;
38
+ − 210 default:
+ − 211 break;
+ − 212 case ACTION_IDLE_TICK:
+ − 213 case ACTION_IDLE_SECOND:
+ − 214 break;
+ − 215 }
+ − 216 }
+ − 217
+ − 218
+ − 219 /* Private functions ---------------------------------------------------------*/
+ − 220
+ − 221 void exitLog(void)
+ − 222 {
+ − 223 //set_globalState_tHome();
+ − 224 exitInfo();
+ − 225 releaseFrame(15,INFOLOGscreen.FBStartAdress);
+ − 226 }
+ − 227
+ − 228
+ − 229 void stepBackInfo(void)
+ − 230 {
+ − 231 if(infolog.modeFlipPages == 0)
+ − 232 {
+ − 233 infolog.line = 0;
+ − 234 infolog.modeFlipPages = 1;
110
+ − 235
865
+ − 236 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
+ − 237
110
+ − 238 if(!settingsGetPointer()->FlipDisplay)
+ − 239 {
+ − 240 GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 25, 800, 390);
+ − 241 }
+ − 242 else
+ − 243 {
+ − 244 GFX_SetFrameBottom(pMenuCursorDesignSolo->FBStartAdress, 0, 65, 800, 390);
+ − 245 }
+ − 246
38
+ − 247 }
+ − 248 else
+ − 249 exitLog();
+ − 250 }
+ − 251
+ − 252
+ − 253 void stepForwardInfo(void)
+ − 254 {
+ − 255 if(infolog.modeFlipPages == 1)
+ − 256 {
+ − 257 tInfoLog_nextLine();
+ − 258 }
+ − 259 else
+ − 260 showLog();
+ − 261 }
+ − 262
+ − 263
+ − 264 void tInfoLog_BuildAndShowNextPage(void)
+ − 265 {
+ − 266 char text[MAX_PAGE_TEXTSIZE];
+ − 267 uint16_t textPointer = 0;
+ − 268 SLogbookHeader logbookHeader;
+ − 269 // uint16_t divetime = logbookHeader.diveTimeMinutes;
+ − 270 // uint16_t maxDepth = logbookHeader.maxDepth/100;
+ − 271 int i = 0;
+ − 272 uint8_t date[2], month,day;
567
+ − 273 char timeSuffix;
+ − 274 uint8_t hours;
38
+ − 275
+ − 276 if(INFOLOGscreen.FBStartAdress)
+ − 277 releaseFrame(15,INFOLOGscreen.FBStartAdress);
+ − 278 INFOLOGscreen.FBStartAdress = getFrame(15);
+ − 279
+ − 280 infolog.page += 1;
+ − 281 infolog.linesAvailableForPage = 0;
+ − 282
+ − 283 if((infolog.page < 1) || (infolog.page > 43)) /* max with 256 entries */
+ − 284 infolog.page = 1;
+ − 285
+ − 286
+ − 287 text[0] = '\001';
+ − 288 text[1] = TXT_Logbook;
+ − 289 text[2] = 0;
+ − 290 gfx_write_topline_simple(&INFOLOGscreen, text, CLUT_InfoPageLogbook);
+ − 291
+ − 292 *text = 0;
+ − 293 if(!logbook_getHeader((infolog.page - 1) * 6,&logbookHeader))
+ − 294 {
+ − 295 infolog.page = 1;
+ − 296 if(!logbook_getHeader((infolog.page - 1) * 6,&logbookHeader))
+ − 297 {
+ − 298 infolog.page = 255;
+ − 299 infolog.linesAvailableForPage = 0;
+ − 300 text[0] = TXT_LogbookEmpty;
+ − 301 text[1] = 0;
+ − 302 }
+ − 303 }
+ − 304
+ − 305 if((*text == 0) && (infolog.maxpages > 1))
+ − 306 {
630
+ − 307 snprintf(text,10, "\002" "%u/%u", infolog.page, infolog.maxpages);
38
+ − 308 gfx_write_topline_simple(&INFOLOGscreen, text, CLUT_InfoPageLogbook);
+ − 309 *text = 0;
+ − 310 }
+ − 311
+ − 312 if(*text == 0)
+ − 313 {
+ − 314 infolog.line = 0;
+ − 315 textPointer = 0;
+ − 316 if(settingsGetPointer()->date_format == DDMMYY)
+ − 317 {
+ − 318 day = 0;
+ − 319 month = 1;
+ − 320 }
+ − 321 else
+ − 322 {
+ − 323 day = 1;
+ − 324 month = 0;
+ − 325 }
+ − 326 for(i = 0; i < 6; i++)
+ − 327 {
+ − 328 if(i)
+ − 329 {
+ − 330 if(!logbook_getHeader(((infolog.page - 1) * 6) + i, &logbookHeader))
+ − 331 break;
+ − 332 }
+ − 333 infolog.linesAvailableForPage += 1;
+ − 334 uint16_t divetime = logbookHeader.diveTimeMinutes;
+ − 335 uint16_t maxDepthMeter = logbookHeader.maxDepth/100;
+ − 336 uint16_t maxDepthSubmeter = (logbookHeader.maxDepth - maxDepthMeter * 100)/10;
+ − 337 uint16_t number = ((infolog.page - 1) * 6) + i + 1;
+ − 338 if(settingsGetPointer()->logbookOffset)
+ − 339 {
+ − 340 if(number <= settingsGetPointer()->logbookOffset)
+ − 341 number = settingsGetPointer()->logbookOffset + 1 - number;
+ − 342 }
+ − 343 date[day] = logbookHeader.dateDay;
+ − 344 date[month] = logbookHeader.dateMonth;
+ − 345
+ − 346 text[textPointer++] = '\034';// monospaced space large size mode
525
+ − 347 textPointer += snprintf(&text[textPointer], 20,"\031%04u \020", number);
38
+ − 348 /* if(number < 1000)
525
+ − 349 textPointer += snprintf(&text[textPointer], 20,"\031%2u \020", number);
38
+ − 350 else
525
+ − 351 textPointer += snprintf(&text[textPointer], 20,"\031\016\016%3u \017\020", number);
38
+ − 352 */
+ − 353 textPointer += snprintf(&text[textPointer], 20,"%02d.%02d ",date[0],date[1]);
567
+ − 354
+ − 355 if (settingsGetPointer()->amPMTime)
+ − 356 {
+ − 357 if (logbookHeader.timeHour > 11)
+ − 358 {
+ − 359 timeSuffix = 'P';
+ − 360 }
+ − 361 else
+ − 362 {
+ − 363 timeSuffix = 'A';
+ − 364 }
+ − 365
+ − 366 if (logbookHeader.timeHour % 12 == 0)
+ − 367 {
+ − 368 hours = 12;
+ − 369 }
+ − 370 else
+ − 371 {
+ − 372 hours = (logbookHeader.timeHour % 12);
+ − 373 }
+ − 374
+ − 375 textPointer += snprintf(&text[textPointer], 20,"%02d:%02d\016\016%cM\017", hours,logbookHeader.timeMinute, timeSuffix);
+ − 376 }
+ − 377 else
+ − 378 {
+ − 379 textPointer += snprintf(&text[textPointer], 20,"%02d:%02d ",logbookHeader.timeHour,logbookHeader.timeMinute);
+ − 380 }
+ − 381
38
+ − 382 switch(logbookHeader.decoModel)
+ − 383 {
+ − 384 case 1:
570
+ − 385 if(!settingsGetPointer()->nonMetricalSystem) /* safe space to avoid cursor overlap */
+ − 386 {
+ − 387 if(settingsGetPointer()->amPMTime)
+ − 388 {
+ − 389 textPointer += snprintf(&text[textPointer],20,"\016\016 GF \017");
+ − 390 }
+ − 391 else
+ − 392 {
+ − 393 textPointer += snprintf(&text[textPointer],20,"\016\016GF \017");
+ − 394 }
+ − 395 }
+ − 396 else
+ − 397 {
+ − 398 textPointer += snprintf(&text[textPointer],20,"\016\016 GF \017");
+ − 399 }
38
+ − 400 break;
+ − 401 case 2:
590
+ − 402 textPointer += snprintf(&text[textPointer],20,"\016\016VPM\017");
38
+ − 403 break;
+ − 404 default:
+ − 405 textPointer += snprintf(&text[textPointer],20,"\016\016 * \017");
+ − 406 break;
+ − 407 }
+ − 408
+ − 409 if(settingsGetPointer()->nonMetricalSystem)
+ − 410 {
+ − 411 float maxDepthFeet = 0;
+ − 412 maxDepthFeet = unit_depth_float(((float)logbookHeader.maxDepth)/100);
+ − 413 textPointer += snprintf(&text[textPointer], 20,"%3.0f\016\016ft\017 ", maxDepthFeet);
+ − 414 }
+ − 415 else
+ − 416 {
570
+ − 417 textPointer += snprintf(&text[textPointer], 20,"%3d.%d\016\016m \017", maxDepthMeter,maxDepthSubmeter);
38
+ − 418 }
567
+ − 419 textPointer += snprintf(&text[textPointer], 20,"%3d\016\016min\017\n\r", divetime);
+ − 420
38
+ − 421 }
+ − 422 }
+ − 423 GFX_write_string(&FontT48, &INFOLOGwindow, text,1);
+ − 424
865
+ − 425 if(infolog.page == 255) {
+ − 426 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,0,0);
+ − 427 } else {
38
+ − 428 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
865
+ − 429 }
38
+ − 430
+ − 431 GFX_SetFrameTop(INFOLOGscreen.FBStartAdress);
+ − 432 set_globalState_Log_Page(infolog.page);
+ − 433 }
+ − 434
+ − 435
+ − 436 void tInfoLog_nextLine(void)
+ − 437 {
+ − 438 if(infolog.linesAvailableForPage == 0)
+ − 439 return;
+ − 440
+ − 441 infolog.line += 1;
+ − 442 if(infolog.line > infolog.linesAvailableForPage)
+ − 443 infolog.line = 1;
+ − 444
+ − 445 infolog.modeFlipPages = 0;
+ − 446
865
+ − 447 if (infolog.linesAvailableForPage > 1) {
+ − 448 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_Page, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonNext);
+ − 449 } else {
+ − 450 tInfo_write_buttonTextline(&INFOLOGscreen, TXT2BYTE_Page, TXT2BYTE_ButtonEnter, 0);
+ − 451 }
+ − 452
110
+ − 453 if(!settingsGetPointer()->FlipDisplay)
+ − 454 {
+ − 455 GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
+ − 456 }
+ − 457 else
+ − 458 {
+ − 459 GFX_SetFrameBottom((pMenuCursor->FBStartAdress)+ (390 - 65 *(infolog.line)) *2, 0, 480-390-25, 800, 390);
+ − 460 }
38
+ − 461 }
+ − 462
+ − 463
+ − 464 void showLogExit(void)
+ − 465 {
+ − 466 GFX_SetFrameTop(INFOLOGscreen.FBStartAdress);
+ − 467 GFX_SetFrameBottom((pMenuCursor->FBStartAdress) + 65*2*(infolog.line - 1), 0, 25, 800, 390);
+ − 468 set_globalState_Log_Page(infolog.page);
+ − 469 }
+ − 470
+ − 471
+ − 472 void showLog(void)
+ − 473 {
+ − 474 uint8_t stepBack;
+ − 475
+ − 476 if(infolog.page == 255)
+ − 477 return;
+ − 478
+ − 479 stepBack = (6 * (infolog.page - 1)) + infolog.line - 1;
+ − 480 //build_logbook_test();
+ − 481 show_logbook_test(1, stepBack);
+ − 482 }
+ − 483
+ − 484
+ − 485 void showNextLogPage(void)
+ − 486 {
+ − 487 uint8_t stepBack;
+ − 488
+ − 489 if(infolog.page == 255)
+ − 490 return;
+ − 491
+ − 492 stepBack = (6 * (infolog.page - 1)) + infolog.line - 1;
+ − 493 //build_logbook_test();
+ − 494 show_logbook_test(0, stepBack);
+ − 495 }
+ − 496