Jonne Valola / PokittoLib Featured

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Wed Jun 27 13:14:54 2018 +0000
Revision:
50:ca94812a17b6
Parent:
49:74201663ba8b
Lockup at startup due to missing EEPROM values fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 46:e7e438368e16 1 /**************************************************************************/
Pokitto 46:e7e438368e16 2 /*!
Pokitto 46:e7e438368e16 3 @file PokittoCore.cpp
Pokitto 46:e7e438368e16 4 @author Jonne Valola
Pokitto 46:e7e438368e16 5
Pokitto 46:e7e438368e16 6 @section LICENSE
Pokitto 46:e7e438368e16 7
Pokitto 46:e7e438368e16 8 Software License Agreement (BSD License)
Pokitto 46:e7e438368e16 9
Pokitto 46:e7e438368e16 10 Copyright (c) 2016, Jonne Valola
Pokitto 46:e7e438368e16 11 All rights reserved.
Pokitto 46:e7e438368e16 12
Pokitto 46:e7e438368e16 13 Redistribution and use in source and binary forms, with or without
Pokitto 46:e7e438368e16 14 modification, are permitted provided that the following conditions are met:
Pokitto 46:e7e438368e16 15 1. Redistributions of source code must retain the above copyright
Pokitto 46:e7e438368e16 16 notice, this list of conditions and the following disclaimer.
Pokitto 46:e7e438368e16 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 46:e7e438368e16 18 notice, this list of conditions and the following disclaimer in the
Pokitto 46:e7e438368e16 19 documentation and/or other materials provided with the distribution.
Pokitto 46:e7e438368e16 20 3. Neither the name of the copyright holders nor the
Pokitto 46:e7e438368e16 21 names of its contributors may be used to endorse or promote products
Pokitto 46:e7e438368e16 22 derived from this software without specific prior written permission.
Pokitto 46:e7e438368e16 23
Pokitto 46:e7e438368e16 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 46:e7e438368e16 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 46:e7e438368e16 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 46:e7e438368e16 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 46:e7e438368e16 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 46:e7e438368e16 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 46:e7e438368e16 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 46:e7e438368e16 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 46:e7e438368e16 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 46:e7e438368e16 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 46:e7e438368e16 34 */
Pokitto 46:e7e438368e16 35 /**************************************************************************/
Pokitto 46:e7e438368e16 36
Pokitto 46:e7e438368e16 37 #include "Pokitto_settings.h"
Pokitto 46:e7e438368e16 38 #include "PokittoCore.h"
Pokitto 46:e7e438368e16 39 #include "PokittoConsole.h"
Pokitto 46:e7e438368e16 40 #include "PokittoFonts.h"
Pokitto 46:e7e438368e16 41 #include "PokittoTimer.h"
Pokitto 46:e7e438368e16 42 #include "PokittoLogos.h"
Pokitto 46:e7e438368e16 43 #include <stdlib.h>
Pokitto 46:e7e438368e16 44
Pokitto 46:e7e438368e16 45 #ifndef DISABLEAVRMIN
Pokitto 46:e7e438368e16 46 #define max(a,b) ((a)>(b)?(a):(b))
Pokitto 46:e7e438368e16 47 #endif // DISABLEAVRMIN
Pokitto 46:e7e438368e16 48
Pokitto 46:e7e438368e16 49 char selectedfile[25];
Pokitto 46:e7e438368e16 50
Pokitto 46:e7e438368e16 51 //#define F
Pokitto 46:e7e438368e16 52 #ifdef __ARMCC_VERSION
Pokitto 46:e7e438368e16 53 typedef void (*func_t)(void);
Pokitto 46:e7e438368e16 54 #endif
Pokitto 46:e7e438368e16 55
Pokitto 46:e7e438368e16 56 #ifndef POK_SIM
Pokitto 46:e7e438368e16 57 #include "iap.h"
Pokitto 46:e7e438368e16 58 /** start the user application
Pokitto 46:e7e438368e16 59 * https://community.nxp.com/thread/417695
Pokitto 46:e7e438368e16 60 *
Pokitto 46:e7e438368e16 61 */
Pokitto 46:e7e438368e16 62 void start_application(unsigned long app_link_location){
Pokitto 46:e7e438368e16 63 //asm(" ldr sp, [r0,#0]");
Pokitto 46:e7e438368e16 64 //asm(" ldr pc, [r0,#4]");
Pokitto 46:e7e438368e16 65 //This code is not valid for the Cortex-m0+ instruction set.
Pokitto 46:e7e438368e16 66 // The equivalent for this (as used by the KL26) is
Pokitto 46:e7e438368e16 67 __disable_irq();// Start by disabling interrupts, before changing interrupt vectors
Pokitto 46:e7e438368e16 68
Pokitto 46:e7e438368e16 69 // delete buttons
Pokitto 46:e7e438368e16 70 //pokDeleteButtons();
Pokitto 46:e7e438368e16 71
Pokitto 46:e7e438368e16 72 // completely kill button interrupts in preparation for reset
Pokitto 46:e7e438368e16 73 LPC_PINT->IENR = 0;
Pokitto 46:e7e438368e16 74 LPC_PINT->IENF = 0;
Pokitto 46:e7e438368e16 75
Pokitto 46:e7e438368e16 76 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk & ~(SysTick_CTRL_ENABLE_Msk); //disable systick
Pokitto 46:e7e438368e16 77 LPC_SYSCON->PDRUNCFG |= (1 << 10); /* Power-down USB PHY */
Pokitto 46:e7e438368e16 78 LPC_SYSCON->PDRUNCFG |= (1 << 8); /* Power-down USB PLL */
Pokitto 46:e7e438368e16 79
Pokitto 46:e7e438368e16 80 // reset clock source to IRC
Pokitto 46:e7e438368e16 81 LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */
Pokitto 46:e7e438368e16 82 LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */
Pokitto 46:e7e438368e16 83 while (LPC_SYSCON->MAINCLKUEN & 0x01); /* Wait Until Updated */
Pokitto 46:e7e438368e16 84 // switch clock selection to IRC
Pokitto 46:e7e438368e16 85 LPC_SYSCON->MAINCLKSEL = 0; /* Select Clock Source */
Pokitto 46:e7e438368e16 86 LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */
Pokitto 46:e7e438368e16 87 LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */
Pokitto 46:e7e438368e16 88 while (LPC_SYSCON->MAINCLKUEN & 0x01); /* Wait Until Updated */
Pokitto 46:e7e438368e16 89 //disable PLL clock output
Pokitto 46:e7e438368e16 90 LPC_SYSCON->SYSPLLCLKUEN = 0;
Pokitto 46:e7e438368e16 91 while (LPC_SYSCON->SYSPLLCLKUEN & 0x00);
Pokitto 46:e7e438368e16 92 LPC_SYSCON->SYSPLLCTRL = 0;
Pokitto 46:e7e438368e16 93
Pokitto 46:e7e438368e16 94 //kill peripherals
Pokitto 46:e7e438368e16 95 LPC_SYSCON->MAINCLKSEL = 0;
Pokitto 46:e7e438368e16 96 LPC_SYSCON->PRESETCTRL = 0; //disable all peripherals
Pokitto 46:e7e438368e16 97
Pokitto 46:e7e438368e16 98 //power down PLL
Pokitto 46:e7e438368e16 99 volatile uint32_t tmp;
Pokitto 46:e7e438368e16 100 tmp = (LPC_SYSCON->PDRUNCFG & 0x000025FFL);
Pokitto 46:e7e438368e16 101 tmp |= ((1<<7) & 0x000025FFL);
Pokitto 46:e7e438368e16 102 LPC_SYSCON->PDRUNCFG = (tmp | 0x0000C800L); /* Power-down SYSPLL */
Pokitto 46:e7e438368e16 103
Pokitto 46:e7e438368e16 104 //Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC); //switch to IRC
Pokitto 46:e7e438368e16 105
Pokitto 46:e7e438368e16 106 // clear all gpio states
Pokitto 46:e7e438368e16 107 LPC_GPIO_PORT->PIN[0] = 0;
Pokitto 46:e7e438368e16 108 LPC_GPIO_PORT->PIN[1] = 0;
Pokitto 46:e7e438368e16 109 LPC_GPIO_PORT->PIN[2] = 0;
Pokitto 46:e7e438368e16 110
Pokitto 46:e7e438368e16 111 SCB->VTOR = app_link_location;//APPL_ADDRESS; /* Change vector table address */
Pokitto 46:e7e438368e16 112 #ifndef __ARMCC_VERSION
Pokitto 46:e7e438368e16 113 asm(" mov r0, %[address]"::[address] "r" (app_link_location));
Pokitto 46:e7e438368e16 114 asm(" ldr r1, [r0,#0]"); // get the stack pointer value from the program's reset vector
Pokitto 46:e7e438368e16 115 asm(" mov sp, r1"); // copy the value to the stack pointer
Pokitto 46:e7e438368e16 116 asm(" ldr r0, [r0,#4]"); // get the program counter value from the program's reset vector
Pokitto 46:e7e438368e16 117 asm(" blx r0"); // jump to the' start address
Pokitto 46:e7e438368e16 118 #else
Pokitto 46:e7e438368e16 119 uint32_t *app_loc = (uint32_t*)app_link_location;
Pokitto 46:e7e438368e16 120 __set_MSP (app_loc[0]);
Pokitto 46:e7e438368e16 121 ((func_t)(app_loc[1]))();
Pokitto 46:e7e438368e16 122 #endif
Pokitto 46:e7e438368e16 123 }
Pokitto 46:e7e438368e16 124 #endif
Pokitto 46:e7e438368e16 125
Pokitto 46:e7e438368e16 126 // returns a random integar between 0 and maxVal
Pokitto 46:e7e438368e16 127 int random(int maxVal)
Pokitto 46:e7e438368e16 128 {
Pokitto 46:e7e438368e16 129 return random( 0, maxVal);
Pokitto 46:e7e438368e16 130 }
Pokitto 46:e7e438368e16 131
Pokitto 46:e7e438368e16 132 // returns a random integar between minVal and maxVal
Pokitto 46:e7e438368e16 133 int random(int minVal, int maxVal)
Pokitto 46:e7e438368e16 134 {
Pokitto 46:e7e438368e16 135 // int rand(void); included by default from newlib
Pokitto 46:e7e438368e16 136 return rand() % (maxVal-minVal+1) + minVal;
Pokitto 46:e7e438368e16 137 }
Pokitto 46:e7e438368e16 138
Pokitto 46:e7e438368e16 139 using namespace Pokitto;
Pokitto 46:e7e438368e16 140
Pokitto 46:e7e438368e16 141 bool Core::run_state; // this definition needed
Pokitto 46:e7e438368e16 142
Pokitto 46:e7e438368e16 143 /** Components */
Pokitto 46:e7e438368e16 144 Backlight Core::backlight;
Pokitto 46:e7e438368e16 145 Buttons Core::buttons;
Pokitto 46:e7e438368e16 146 Battery Core::battery;
Pokitto 46:e7e438368e16 147 #if POK_ENABLE_SOUND > 0
Pokitto 46:e7e438368e16 148 Sound Core::sound;
Pokitto 46:e7e438368e16 149 #endif
Pokitto 46:e7e438368e16 150 Display Core::display;
Pokitto 46:e7e438368e16 151
Pokitto 46:e7e438368e16 152 //GB Related
Pokitto 46:e7e438368e16 153 uint8_t Core::startMenuTimer;
Pokitto 46:e7e438368e16 154 uint8_t Core::timePerFrame;
Pokitto 46:e7e438368e16 155 uint32_t Core::nextFrameMillis;
Pokitto 46:e7e438368e16 156 uint32_t Core::frameCount;
Pokitto 46:e7e438368e16 157 const char* Core::popupText;
Pokitto 46:e7e438368e16 158 uint8_t Core::popupTimeLeft;
Pokitto 46:e7e438368e16 159 uint16_t Core::frameDurationMicros;
Pokitto 46:e7e438368e16 160 uint32_t Core::frameStartMicros, Core::frameEndMicros;
Pokitto 46:e7e438368e16 161 uint8_t Core::volbar_visible=0;
Pokitto 46:e7e438368e16 162
Pokitto 46:e7e438368e16 163 uint32_t Core::fps_counter;
Pokitto 46:e7e438368e16 164 bool Core::fps_counter_updated;
Pokitto 46:e7e438368e16 165 uint32_t Core::fps_refreshtime;
Pokitto 46:e7e438368e16 166 uint32_t Core::fps_frameCount;
Pokitto 46:e7e438368e16 167
Pokitto 46:e7e438368e16 168 Core::Core() {
Pokitto 46:e7e438368e16 169
Pokitto 46:e7e438368e16 170 }
Pokitto 46:e7e438368e16 171
Pokitto 46:e7e438368e16 172
Pokitto 46:e7e438368e16 173 int Core::updateLoader (uint32_t version, uint32_t jumpaddress) {
Pokitto 46:e7e438368e16 174 #ifndef POK_SIM
Pokitto 46:e7e438368e16 175 uint32_t counter=0;
Pokitto 46:e7e438368e16 176 uint8_t data[256];
Pokitto 46:e7e438368e16 177 /** prepare the flash writing **/
Pokitto 46:e7e438368e16 178 float progress=0;
Pokitto 46:e7e438368e16 179 int opg=-1;
Pokitto 46:e7e438368e16 180 uint32_t fsize=0;
Pokitto 46:e7e438368e16 181 fileEnd(); //
Pokitto 46:e7e438368e16 182 fsize = fileGetPosition();
Pokitto 46:e7e438368e16 183 if (fsize>0x40000-jumpaddress) fsize = 0x40000-jumpaddress; // shouldn't happen!!
Pokitto 46:e7e438368e16 184 fileRewind();
Pokitto 46:e7e438368e16 185 display.println("PLEASE WAIT");
Pokitto 46:e7e438368e16 186 while (1) {
Pokitto 46:e7e438368e16 187 //if (counter >= fsize-0x200) {
Pokitto 46:e7e438368e16 188 // display.println("gotcha");
Pokitto 46:e7e438368e16 189 //}
Pokitto 46:e7e438368e16 190 if (counter >= fsize) {
Pokitto 46:e7e438368e16 191 break;
Pokitto 46:e7e438368e16 192 }
Pokitto 46:e7e438368e16 193 opg=progress;
Pokitto 46:e7e438368e16 194 if (fileReadBytes(&data[0],0x100)<0x100) {
Pokitto 46:e7e438368e16 195 if (fsize-counter>0x100) {
Pokitto 46:e7e438368e16 196 display.println("ERROR READING LOA.DER FILE");
Pokitto 46:e7e438368e16 197 return 1; // 1 means error
Pokitto 46:e7e438368e16 198 }
Pokitto 46:e7e438368e16 199 }
Pokitto 46:e7e438368e16 200 if (CopyPageToFlash(jumpaddress+counter,data)) {
Pokitto 46:e7e438368e16 201 display.println("FLASH WRITE ERROR");
Pokitto 46:e7e438368e16 202 return 1;
Pokitto 46:e7e438368e16 203 } else {
Pokitto 46:e7e438368e16 204 counter += 0x100;
Pokitto 46:e7e438368e16 205 display.print(".");
Pokitto 46:e7e438368e16 206 }
Pokitto 46:e7e438368e16 207 }
Pokitto 46:e7e438368e16 208 #endif // POK_SIM
Pokitto 46:e7e438368e16 209 return 0; //success
Pokitto 46:e7e438368e16 210 }
Pokitto 46:e7e438368e16 211
Pokitto 46:e7e438368e16 212 void Core::showWarning() {
Pokitto 46:e7e438368e16 213 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 214 display.directbgcolor = COLOR_BLACK;
Pokitto 46:e7e438368e16 215 display.clearLCD();
Pokitto 46:e7e438368e16 216 display.directcolor = COLOR_RED;
Pokitto 46:e7e438368e16 217 display.setFont(fntC64UIGfx);
Pokitto 46:e7e438368e16 218 display.adjustCharStep = 0;
Pokitto 46:e7e438368e16 219 display.adjustLineStep = 0;
Pokitto 46:e7e438368e16 220 display.setCursor(10*8,9);
Pokitto 46:e7e438368e16 221 display.print("WARNING!");
Pokitto 46:e7e438368e16 222 display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 223 display.setCursor(5*8,4*9);
Pokitto 46:e7e438368e16 224 display.print("LOUD SOUND THROUGH");
Pokitto 46:e7e438368e16 225 display.setCursor(2*8,5*9);
Pokitto 46:e7e438368e16 226 display.print("HEADPHONES COULD DAMAGE");
Pokitto 46:e7e438368e16 227 display.setCursor(7*8,6*9);
Pokitto 46:e7e438368e16 228 display.print("YOUR HEARING.");
Pokitto 46:e7e438368e16 229 display.setCursor(5*8,8*9);
Pokitto 46:e7e438368e16 230 display.print("USE "); display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 231 display.print("0-100% VOLUME");
Pokitto 46:e7e438368e16 232 display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 233 display.setCursor(5*8,9*9);
Pokitto 46:e7e438368e16 234 display.print("FOR LISTENING WITH");
Pokitto 46:e7e438368e16 235 display.setCursor(8*8,10*9);
Pokitto 46:e7e438368e16 236 display.print("HEADPHONES");
Pokitto 46:e7e438368e16 237 display.setCursor(5*8,12*9);
Pokitto 46:e7e438368e16 238 display.print("USE "); display.directcolor = COLOR_RED;
Pokitto 46:e7e438368e16 239 display.print("> 100% VOLUME"); display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 240 display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 241 display.setCursor(1*8,13*9);
Pokitto 46:e7e438368e16 242 display.print("ONLY FOR LISTENING VIA THE");
Pokitto 46:e7e438368e16 243 display.setCursor(5*8,14*9);
Pokitto 46:e7e438368e16 244 display.print("BUILT-IN SPEAKER");
Pokitto 46:e7e438368e16 245 display.setCursor(5*8,17*9);
Pokitto 46:e7e438368e16 246 display.print("PRESS ");display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 247 display.print("C ");display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 248 display.print("TO ACCEPT");
Pokitto 46:e7e438368e16 249 while (!buttons.cBtn()) {
Pokitto 46:e7e438368e16 250 wait(100);
Pokitto 46:e7e438368e16 251 }
Pokitto 46:e7e438368e16 252 display.clearLCD();
Pokitto 46:e7e438368e16 253 display.enableDirectPrinting(false);
Pokitto 46:e7e438368e16 254 }
Pokitto 46:e7e438368e16 255
Pokitto 46:e7e438368e16 256 void Core::jumpToLoader() {
Pokitto 46:e7e438368e16 257 //display.setFont(font5x7);
Pokitto 46:e7e438368e16 258 //display.adjustCharStep=1;
Pokitto 46:e7e438368e16 259 //display.adjustLineStep=2;
Pokitto 46:e7e438368e16 260 display.fontSize=1;
Pokitto 46:e7e438368e16 261 display.directbgcolor=COLOR_BLACK;
Pokitto 46:e7e438368e16 262 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 263 display.clearLCD();
Pokitto 46:e7e438368e16 264 display.setCursor(0,0);
Pokitto 46:e7e438368e16 265 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 266 #ifdef POK_SIM
Pokitto 46:e7e438368e16 267 display.println("LOADER IS NOT AVAILABLE ON THE SIMULATOR. PRESS A TO RETURN.");
Pokitto 46:e7e438368e16 268 #else
Pokitto 46:e7e438368e16 269 uint32_t* bootinfo;
Pokitto 46:e7e438368e16 270 uint32_t bootversion=0, sdversion=0, sdjump=0;
Pokitto 46:e7e438368e16 271 bool flashloader=false, checkforboot=true;
Pokitto 46:e7e438368e16 272 //check for loa.der on SD card
Pokitto 46:e7e438368e16 273 #if POK_ENABLE_LOADER_UPDATES > 0
Pokitto 46:e7e438368e16 274 pokInitSD();
Pokitto 46:e7e438368e16 275 if (fileOpen("LOA.DER", FILE_MODE_BINARY)==0) {
Pokitto 46:e7e438368e16 276 //LOA.DER found on SD
Pokitto 46:e7e438368e16 277 fileEnd(); // go to end
Pokitto 46:e7e438368e16 278 fileSeekRelative(-8); //rewind 8 bytes
Pokitto 46:e7e438368e16 279 uint32_t* tptr = &sdversion;
Pokitto 46:e7e438368e16 280 fileReadBytes((uint8_t*)tptr,4); //read version number of loader on SD card
Pokitto 46:e7e438368e16 281 tptr = &sdjump;
Pokitto 46:e7e438368e16 282 fileReadBytes((uint8_t*)tptr,4); //read jump address of loader on sd card
Pokitto 46:e7e438368e16 283 fileRewind();
Pokitto 46:e7e438368e16 284 }
Pokitto 46:e7e438368e16 285 #endif
Pokitto 46:e7e438368e16 286 //now start searching for bootkey
Pokitto 46:e7e438368e16 287 while (checkforboot)
Pokitto 46:e7e438368e16 288 {
Pokitto 46:e7e438368e16 289 checkforboot=false; flashloader=false;
Pokitto 46:e7e438368e16 290 bootinfo = (uint32_t*)0x3FFF4;
Pokitto 46:e7e438368e16 291 if (*bootinfo != 0xB007AB1E) bootinfo = (uint32_t*)0x3FF04; //allow couple of alternative locations
Pokitto 46:e7e438368e16 292 if (*bootinfo != 0xB007AB1E) bootinfo = (uint32_t*)0x3FE04; //allow couple of alternative locations
Pokitto 46:e7e438368e16 293 if (*bootinfo != 0xB007AB1E) bootinfo = (uint32_t*)0x3F004; //for futureproofing
Pokitto 46:e7e438368e16 294 if (*bootinfo != 0xB007AB1E) {
Pokitto 46:e7e438368e16 295 // no bootkey found at all
Pokitto 46:e7e438368e16 296 display.directcolor=COLOR_YELLOW;
Pokitto 46:e7e438368e16 297 display.println("NO LOADER INSTALLED");
Pokitto 46:e7e438368e16 298 if (sdversion==0 || sdjump < 0x38000) {
Pokitto 46:e7e438368e16 299 //file open of loader failed
Pokitto 46:e7e438368e16 300 display.println("NO VALID LOA.DER ON SD");
Pokitto 46:e7e438368e16 301 display.println("");
Pokitto 46:e7e438368e16 302 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 303 display.println("PUT LOA.DER ON SD & REBOOT");
Pokitto 46:e7e438368e16 304 } else flashloader=true;
Pokitto 46:e7e438368e16 305 } else {
Pokitto 46:e7e438368e16 306 //loader was found
Pokitto 46:e7e438368e16 307 //check if we should update the loader
Pokitto 46:e7e438368e16 308 display.directcolor=COLOR_CYAN;
Pokitto 46:e7e438368e16 309 display.print("LOADER V.");
Pokitto 46:e7e438368e16 310 display.directcolor=COLOR_WHITE;
Pokitto 46:e7e438368e16 311 display.println(*(bootinfo+1));
Pokitto 46:e7e438368e16 312 #if POK_ENABLE_LOADER_UPDATES
Pokitto 46:e7e438368e16 313 if (sdversion>(*(bootinfo+1))) flashloader=true;
Pokitto 46:e7e438368e16 314 else start_application(*(bootinfo+2)); //never returns
Pokitto 46:e7e438368e16 315 #else
Pokitto 46:e7e438368e16 316 start_application(*(bootinfo+2)); //never returns
Pokitto 46:e7e438368e16 317 #endif
Pokitto 46:e7e438368e16 318 }
Pokitto 46:e7e438368e16 319 // update loader if it was requested
Pokitto 46:e7e438368e16 320 if(flashloader) {
Pokitto 46:e7e438368e16 321 display.directcolor=COLOR_MAGENTA;
Pokitto 46:e7e438368e16 322 display.print("NEW LOADER ON SD V.");
Pokitto 46:e7e438368e16 323 display.directcolor=COLOR_WHITE;
Pokitto 46:e7e438368e16 324 display.println(sdversion);
Pokitto 46:e7e438368e16 325 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 326 display.println("UPDATE LOADER?\n(UP=YES, DOWN=CANCEL)");
Pokitto 46:e7e438368e16 327 while(1) {
Pokitto 46:e7e438368e16 328 if (buttons.upBtn()) {
Pokitto 46:e7e438368e16 329 if (updateLoader(sdversion,sdjump)) {
Pokitto 46:e7e438368e16 330 display.println("PUT LOA.DER ON SD AND RETRY");
Pokitto 46:e7e438368e16 331 } else {
Pokitto 46:e7e438368e16 332 display.println("SUCCESS!!");
Pokitto 46:e7e438368e16 333 checkforboot=true; //recheck
Pokitto 46:e7e438368e16 334 }
Pokitto 46:e7e438368e16 335 break;
Pokitto 46:e7e438368e16 336 }
Pokitto 46:e7e438368e16 337 if (buttons.downBtn()) return;
Pokitto 46:e7e438368e16 338 }
Pokitto 46:e7e438368e16 339 } // if flashloader
Pokitto 46:e7e438368e16 340 } // while checkforboot
Pokitto 46:e7e438368e16 341 #endif // POK_SIM
Pokitto 46:e7e438368e16 342 while (!buttons.aBtn()) {
Pokitto 46:e7e438368e16 343 buttons.pollButtons();
Pokitto 46:e7e438368e16 344 if (buttons.aBtn()) {
Pokitto 46:e7e438368e16 345 while (buttons.aBtn()) {
Pokitto 46:e7e438368e16 346 buttons.pollButtons();
Pokitto 46:e7e438368e16 347 }
Pokitto 46:e7e438368e16 348 return;
Pokitto 46:e7e438368e16 349 }
Pokitto 46:e7e438368e16 350 }
Pokitto 46:e7e438368e16 351 }
Pokitto 46:e7e438368e16 352
Pokitto 46:e7e438368e16 353 void Core::askLoader() {
Pokitto 46:e7e438368e16 354 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 355 display.directbgcolor = COLOR_BLACK;
Pokitto 46:e7e438368e16 356 display.clearLCD();
Pokitto 46:e7e438368e16 357 display.directcolor = COLOR_RED;
Pokitto 46:e7e438368e16 358 display.setFont(fntC64UIGfx);
Pokitto 46:e7e438368e16 359 display.fontSize=1;
Pokitto 46:e7e438368e16 360 display.adjustCharStep = 0;
Pokitto 46:e7e438368e16 361 display.adjustLineStep = 0;
Pokitto 46:e7e438368e16 362 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 363 display.set_cursor(12*8,6*8);
Pokitto 46:e7e438368e16 364 display.print("ijkl");
Pokitto 46:e7e438368e16 365 display.set_cursor(12*8,7*8);
Pokitto 46:e7e438368e16 366 display.print("mnop");
Pokitto 46:e7e438368e16 367 display.set_cursor(12*8,8*8);
Pokitto 46:e7e438368e16 368 display.print("qrst");
Pokitto 46:e7e438368e16 369 display.set_cursor(12*8,9*8);
Pokitto 46:e7e438368e16 370 display.print("uvwx");
Pokitto 46:e7e438368e16 371 display.set_cursor(5*8,12*8);
Pokitto 46:e7e438368e16 372 display.print("PRESS");
Pokitto 46:e7e438368e16 373 display.directcolor=COLOR_WHITE;
Pokitto 46:e7e438368e16 374 display.print(" C ");
Pokitto 46:e7e438368e16 375 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 376 display.print("FOR LOADER");
Pokitto 46:e7e438368e16 377 display.directcolor=COLOR_WHITE;
Pokitto 46:e7e438368e16 378 display.fontSize=2;
Pokitto 46:e7e438368e16 379 int countd = 0;
Pokitto 46:e7e438368e16 380 #ifndef POK_SIM
Pokitto 46:e7e438368e16 381 //read countdown time from settings
Pokitto 46:e7e438368e16 382 countd = eeprom_read_byte((uint16_t*)EESETTINGS_LOADERWAIT);
Pokitto 46:e7e438368e16 383 #endif
Pokitto 50:ca94812a17b6 384 if (countd<=0 || countd > 5) countd=3;
Pokitto 46:e7e438368e16 385 uint16_t c2 = getTime();
Pokitto 46:e7e438368e16 386 while (countd) {
Pokitto 46:e7e438368e16 387 buttons.pollButtons();
Pokitto 46:e7e438368e16 388 display.set_cursor(13*8,15*8);
Pokitto 46:e7e438368e16 389 display.print(countd);
Pokitto 46:e7e438368e16 390 if (getTime()>c2+1000) {
Pokitto 46:e7e438368e16 391 c2=getTime();
Pokitto 46:e7e438368e16 392 countd--;
Pokitto 46:e7e438368e16 393 }
Pokitto 46:e7e438368e16 394 if (cBtn()) {while (cBtn()) buttons.pollButtons();jumpToLoader();countd=0;}
Pokitto 46:e7e438368e16 395 if (aBtn()) {while (aBtn()) buttons.pollButtons();countd=0;}
Pokitto 46:e7e438368e16 396 if (bBtn()) {while (bBtn()) buttons.pollButtons();countd=0;}
Pokitto 46:e7e438368e16 397 }
Pokitto 46:e7e438368e16 398 display.fontSize=1;
Pokitto 46:e7e438368e16 399 display.clearLCD();
Pokitto 46:e7e438368e16 400 display.enableDirectPrinting(false);
Pokitto 46:e7e438368e16 401 }
Pokitto 46:e7e438368e16 402
Pokitto 46:e7e438368e16 403
Pokitto 46:e7e438368e16 404 void Core::drawvolbar(int x, int y, int level, bool text) {
Pokitto 46:e7e438368e16 405 uint16_t oldcol = display.directcolor;
Pokitto 46:e7e438368e16 406 level = level >> 5;
Pokitto 46:e7e438368e16 407 if (text) display.directRectangle(0,0,50,50,COLOR_BLACK);
Pokitto 46:e7e438368e16 408 if (level<4) display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 409 if (level==4) display.directcolor = COLOR_YELLOW;
Pokitto 46:e7e438368e16 410 if (level>4) display.directcolor = COLOR_RED;
Pokitto 46:e7e438368e16 411
Pokitto 46:e7e438368e16 412 if (text) {
Pokitto 46:e7e438368e16 413 bool temp = display.isDirectPrintingEnabled();
Pokitto 46:e7e438368e16 414 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 415 display.print(x-1,y-20,(int)sound.getVolume());
Pokitto 46:e7e438368e16 416 display.print(" ");
Pokitto 46:e7e438368e16 417 display.enableDirectPrinting(temp);
Pokitto 46:e7e438368e16 418 }
Pokitto 46:e7e438368e16 419 if (level<1) display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 420 display.directBitmap(x,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 421 if (level<2) display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 422 display.directBitmap(x+8,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 423 display.directBitmap(x+8,y-4,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 424 if (level<3) display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 425 display.directBitmap(x+16,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 426 display.directBitmap(x+16,y-4,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 427 display.directBitmap(x+16,y-8,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 428 if (level<4) {
Pokitto 46:e7e438368e16 429 display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 430 }
Pokitto 46:e7e438368e16 431 display.directBitmap(x+24,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 432 display.directBitmap(x+24,y-4,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 433 display.directBitmap(x+24,y-8,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 434 display.directBitmap(x+24,y-12,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 435
Pokitto 46:e7e438368e16 436 if (level<5) {
Pokitto 46:e7e438368e16 437 display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 438 }
Pokitto 46:e7e438368e16 439 display.directBitmap(x+32,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 440 display.directBitmap(x+32,y-4,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 441 display.directBitmap(x+32,y-8,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 442 display.directBitmap(x+32,y-12,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 443 display.directBitmap(x+32,y-16,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 444
Pokitto 46:e7e438368e16 445 if (level<6) {
Pokitto 46:e7e438368e16 446 display.directcolor = COLOR_GRAY_80;
Pokitto 46:e7e438368e16 447 }
Pokitto 46:e7e438368e16 448 display.directBitmap(x+40,y,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 449 display.directBitmap(x+40,y-4,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 450 display.directBitmap(x+40,y-8,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 451 display.directBitmap(x+40,y-12,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 452 display.directBitmap(x+40,y-16,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 453 display.directBitmap(x+40,y-20,Pokitto_volumebar,1,1);
Pokitto 46:e7e438368e16 454 display.directcolor = oldcol;
Pokitto 46:e7e438368e16 455 }
Pokitto 46:e7e438368e16 456
Pokitto 46:e7e438368e16 457
Pokitto 46:e7e438368e16 458 #ifdef POK_SIM
Pokitto 46:e7e438368e16 459 #define VINCMULT 0.9f
Pokitto 46:e7e438368e16 460 #else
Pokitto 46:e7e438368e16 461 #define VINCMULT 50
Pokitto 46:e7e438368e16 462 #endif //POK_SIM
Pokitto 46:e7e438368e16 463 void Core::setVolLimit() {
Pokitto 46:e7e438368e16 464 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 465 display.adjustCharStep = 0;
Pokitto 46:e7e438368e16 466 //sound.setMaxVol(VOLUME_HEADPHONE_MAX);
Pokitto 46:e7e438368e16 467 int dstate=1;
Pokitto 46:e7e438368e16 468 bool wipe = true;
Pokitto 46:e7e438368e16 469 float vol = sound.getVolume(); float tvol;
Pokitto 46:e7e438368e16 470 #ifndef POK_SIM
Pokitto 46:e7e438368e16 471 vol=eeprom_read_byte((uint16_t*)EESETTINGS_VOL);
Pokitto 46:e7e438368e16 472 Pokitto::Sound::globalVolume=vol;
Pokitto 46:e7e438368e16 473 #endif
Pokitto 46:e7e438368e16 474 if (vol>VOLUME_HEADPHONE_MAX) sound.setMaxVol(VOLUME_SPEAKER_MAX);
Pokitto 46:e7e438368e16 475 else sound.setMaxVol(VOLUME_HEADPHONE_MAX);
Pokitto 46:e7e438368e16 476 #ifdef PRODUCTIONTESTING
Pokitto 46:e7e438368e16 477 vol=170;
Pokitto 46:e7e438368e16 478 sound.setMaxVol(VOLUME_SPEAKER_MAX);
Pokitto 46:e7e438368e16 479 #endif
Pokitto 46:e7e438368e16 480 for (uint8_t t=0;t<=vol;t++) {
Pokitto 46:e7e438368e16 481 sound.setVolume(t);
Pokitto 46:e7e438368e16 482 }
Pokitto 46:e7e438368e16 483 volbar_visible=0;
Pokitto 46:e7e438368e16 484 int countd=0;
Pokitto 46:e7e438368e16 485 #ifndef POK_SIM
Pokitto 46:e7e438368e16 486 //read countdown time from settings
Pokitto 46:e7e438368e16 487 countd = eeprom_read_byte((uint16_t*)EESETTINGS_VOLWAIT);
Pokitto 46:e7e438368e16 488 #endif
Pokitto 46:e7e438368e16 489 if (countd==0 || countd > 10) countd=0xFFFF;
Pokitto 46:e7e438368e16 490 #ifdef PRODUCTIONTESTING
Pokitto 46:e7e438368e16 491 countd=2;
Pokitto 46:e7e438368e16 492 #endif
Pokitto 46:e7e438368e16 493 uint16_t c2 = getTime();
Pokitto 46:e7e438368e16 494 while (core.isRunning() && dstate && countd){
Pokitto 46:e7e438368e16 495 if (getTime()>c2+1000) {
Pokitto 46:e7e438368e16 496 c2=getTime();
Pokitto 46:e7e438368e16 497 if (countd<0xFFFF) countd--;
Pokitto 46:e7e438368e16 498 }
Pokitto 46:e7e438368e16 499 switch (dstate) {
Pokitto 46:e7e438368e16 500 case 1:
Pokitto 46:e7e438368e16 501 //redraw
Pokitto 46:e7e438368e16 502 if (wipe) {
Pokitto 46:e7e438368e16 503 display.clearLCD();
Pokitto 46:e7e438368e16 504 display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 505 display.setCursor(4*8,2*8);
Pokitto 46:e7e438368e16 506 display.print("SELECT VOLUME LIMIT");
Pokitto 46:e7e438368e16 507 display.setCursor(5*8,17*9);
Pokitto 46:e7e438368e16 508 display.print("PRESS ");
Pokitto 46:e7e438368e16 509 display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 510 display.print("A");
Pokitto 46:e7e438368e16 511 display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 512 display.print(" TO ACCEPT");
Pokitto 46:e7e438368e16 513 display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 514 // draw frame below first
Pokitto 46:e7e438368e16 515 display.setCursor(0,11*8);
Pokitto 46:e7e438368e16 516 display.println(" abbbbbbbbbbbbbbbbbbbbbbbc");
Pokitto 46:e7e438368e16 517 display.println(" | |");
Pokitto 46:e7e438368e16 518 display.println(" | |");
Pokitto 46:e7e438368e16 519 display.println(" | |");
Pokitto 46:e7e438368e16 520 display.println(" | |");
Pokitto 46:e7e438368e16 521 display.println(" dbbbbbbbbbbbbbbbbbbbbbbbe");
Pokitto 46:e7e438368e16 522 } // wipe = true
Pokitto 46:e7e438368e16 523 display.setCursor(6*8,17*9);
Pokitto 46:e7e438368e16 524 if (discrete_vol<4) display.directcolor = COLOR_WHITE;
Pokitto 46:e7e438368e16 525 else display.directcolor = COLOR_RED;
Pokitto 46:e7e438368e16 526 display.directBitmap(21*8-4,6*8,Pokitto_headphones,1,2);
Pokitto 46:e7e438368e16 527 display.setCursor(3*8,6*8+6);
Pokitto 46:e7e438368e16 528 display.print("HEADPHONES");
Pokitto 46:e7e438368e16 529 display.setCursor(3*8,8*8+2);
Pokitto 46:e7e438368e16 530 if (discrete_vol>3) display.print("TOO LOUD!");
Pokitto 46:e7e438368e16 531 else display.print("OK ");
Pokitto 46:e7e438368e16 532 display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 533 display.directBitmap(21*8-4,12*8,Pokitto_speaker,1,2);
Pokitto 46:e7e438368e16 534 display.setCursor(3*8,12*8+6);
Pokitto 46:e7e438368e16 535 display.print("VOLUME MAX");
Pokitto 46:e7e438368e16 536 display.setCursor(3*8,14*8+2);
Pokitto 46:e7e438368e16 537 //tvol = (vol/float(VOLUME_HEADPHONE_MAX))*100;
Pokitto 46:e7e438368e16 538 //if (tvol > 100 && tvol < 120) tvol=100;
Pokitto 46:e7e438368e16 539 //if (sound.getVolume()-5>VOLUME_HEADPHONE_MAX) { display.directcolor=COLOR_RED;}
Pokitto 46:e7e438368e16 540 if ((sound.getVolume()>>5)>3) { display.directcolor=COLOR_RED;}
Pokitto 46:e7e438368e16 541 else display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 542 if (discrete_vol==4) display.directcolor=COLOR_YELLOW;
Pokitto 46:e7e438368e16 543 if (discrete_vol==7) discrete_vol=6;
Pokitto 46:e7e438368e16 544 display.print((int)discrete_vol);
Pokitto 46:e7e438368e16 545 //display.print(int(tvol));
Pokitto 46:e7e438368e16 546 display.print(" ");
Pokitto 46:e7e438368e16 547 display.directcolor=COLOR_GREEN;
Pokitto 46:e7e438368e16 548 drawvolbar(14*8,14*8+4+3,sound.getVolume(),false);
Pokitto 46:e7e438368e16 549 //display.setCursor(1,10);
Pokitto 46:e7e438368e16 550 //display.print(vol);
Pokitto 46:e7e438368e16 551 dstate=2; break;
Pokitto 46:e7e438368e16 552 case 2:
Pokitto 46:e7e438368e16 553 #ifndef POK_SIM
Pokitto 46:e7e438368e16 554 buttons.pollButtons();
Pokitto 46:e7e438368e16 555 #endif // POK_SIM
Pokitto 46:e7e438368e16 556 buttons.update();
Pokitto 46:e7e438368e16 557 if (aBtn()) {dstate=0;break;}
Pokitto 46:e7e438368e16 558 if (buttons.pressed(BTN_RIGHT)) {
Pokitto 46:e7e438368e16 559 countd=0xFFFF; //disable countdown
Pokitto 46:e7e438368e16 560 /*if (vol >= VOLUME_HEADPHONE_MAX && vol < VOLUME_HEADPHONE_MAX+1 ) vol += 0.00025f*VINCMULT;
Pokitto 46:e7e438368e16 561 else if (vol >= VOLUME_HEADPHONE_MAX) vol += 0.25f*VINCMULT;
Pokitto 46:e7e438368e16 562 else vol += 0.05f*VINCMULT;
Pokitto 46:e7e438368e16 563 if (vol > VOLUME_HEADPHONE_MAX + 20) {
Pokitto 46:e7e438368e16 564 sound.setMaxVol(VOLUME_SPEAKER_MAX);
Pokitto 46:e7e438368e16 565 }
Pokitto 46:e7e438368e16 566 if (vol > VOLUME_SPEAKER_MAX) vol=VOLUME_SPEAKER_MAX;
Pokitto 46:e7e438368e16 567 sound.setVolume(vol);*/
Pokitto 46:e7e438368e16 568 sound.volumeUp();
Pokitto 46:e7e438368e16 569 dstate=1; wipe=false;
Pokitto 46:e7e438368e16 570 break;
Pokitto 46:e7e438368e16 571 }
Pokitto 46:e7e438368e16 572 if (buttons.pressed(BTN_LEFT)) {
Pokitto 46:e7e438368e16 573 countd=0xFFFF; //disable countdown
Pokitto 46:e7e438368e16 574 /*if (vol >= VOLUME_HEADPHONE_MAX) vol -= 0.25f*VINCMULT;
Pokitto 46:e7e438368e16 575 else vol -= 0.05f*VINCMULT;
Pokitto 46:e7e438368e16 576 if (vol <= VOLUME_HEADPHONE_MAX) sound.setMaxVol(VOLUME_HEADPHONE_MAX);
Pokitto 46:e7e438368e16 577 if (vol < 0) vol=0;
Pokitto 46:e7e438368e16 578 sound.setVolume(vol);*/
Pokitto 46:e7e438368e16 579 sound.volumeDown();
Pokitto 46:e7e438368e16 580 dstate=1; wipe=false;
Pokitto 46:e7e438368e16 581 break;
Pokitto 46:e7e438368e16 582 }
Pokitto 46:e7e438368e16 583 break;
Pokitto 46:e7e438368e16 584 }
Pokitto 46:e7e438368e16 585 }
Pokitto 46:e7e438368e16 586 vol = sound.getVolume();
Pokitto 46:e7e438368e16 587 #ifndef POK_SIM
Pokitto 46:e7e438368e16 588 if (vol != eeprom_read_byte((uint16_t*)EESETTINGS_VOL)) eeprom_write_byte((uint16_t*)EESETTINGS_VOL,(uint8_t)vol);
Pokitto 46:e7e438368e16 589 #endif
Pokitto 46:e7e438368e16 590 sound.setVolume(vol);
Pokitto 46:e7e438368e16 591 //sound.volumeUp();
Pokitto 46:e7e438368e16 592 display.setCursor(0,0);
Pokitto 46:e7e438368e16 593 }
Pokitto 46:e7e438368e16 594
Pokitto 46:e7e438368e16 595 void Core::begin() {
Pokitto 46:e7e438368e16 596
Pokitto 46:e7e438368e16 597 init(); // original functions
Pokitto 46:e7e438368e16 598 timePerFrame = POK_FRAMEDURATION;
Pokitto 46:e7e438368e16 599 //nextFrameMillis = 0;
Pokitto 46:e7e438368e16 600 //frameCount = 0;
Pokitto 46:e7e438368e16 601 frameEndMicros = 1;
Pokitto 46:e7e438368e16 602 startMenuTimer = 255;
Pokitto 46:e7e438368e16 603 //read default settings from flash memory (set using settings.hex)
Pokitto 46:e7e438368e16 604 readSettings();
Pokitto 46:e7e438368e16 605 //init everything
Pokitto 46:e7e438368e16 606 backlight.begin();
Pokitto 46:e7e438368e16 607 backlight.set(BACKLIGHT_MAX);
Pokitto 46:e7e438368e16 608 buttons.begin();
Pokitto 46:e7e438368e16 609 buttons.update();
Pokitto 46:e7e438368e16 610 battery.begin();
Pokitto 46:e7e438368e16 611 display.begin();
Pokitto 46:e7e438368e16 612 #if POK_DISPLAYLOGO
Pokitto 46:e7e438368e16 613 #if PROJ_DEVELOPER_MODE != 1
Pokitto 46:e7e438368e16 614 showLogo();
Pokitto 46:e7e438368e16 615 #endif // PROJ_DEVELOPER_MODE
Pokitto 46:e7e438368e16 616 #endif // POK_DISPLAYLOGO
Pokitto 46:e7e438368e16 617
Pokitto 46:e7e438368e16 618 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 619 display.directbgcolor = COLOR_BLACK;
Pokitto 46:e7e438368e16 620 display.clearLCD();
Pokitto 46:e7e438368e16 621 display.setFont(fntC64UIGfx);
Pokitto 46:e7e438368e16 622
Pokitto 46:e7e438368e16 623 display.enableDirectPrinting(true);
Pokitto 46:e7e438368e16 624 display.directbgcolor = COLOR_BLACK;
Pokitto 46:e7e438368e16 625 display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 626 display.clearLCD();
Pokitto 46:e7e438368e16 627 display.setFont(fntC64UIGfx);
Pokitto 46:e7e438368e16 628 display.adjustCharStep=0;
Pokitto 46:e7e438368e16 629 display.adjustLineStep=1;
Pokitto 46:e7e438368e16 630 #ifdef JUSTLOAD
Pokitto 46:e7e438368e16 631 jumpToLoader();
Pokitto 46:e7e438368e16 632 #endif
Pokitto 46:e7e438368e16 633
Pokitto 46:e7e438368e16 634 #ifndef DISABLE_LOADER
Pokitto 46:e7e438368e16 635 #if PROJ_DEVELOPER_MODE != 1
Pokitto 46:e7e438368e16 636 askLoader();
Pokitto 46:e7e438368e16 637 #endif // PROJ_DEVELOPER_MODE
Pokitto 46:e7e438368e16 638 #endif
Pokitto 46:e7e438368e16 639
Pokitto 46:e7e438368e16 640 #if PROJ_DEVELOPER_MODE==1
Pokitto 46:e7e438368e16 641 sound.setMaxVol(VOLUME_SPEAKER_MAX);
Pokitto 46:e7e438368e16 642 sound.setVolume(VOLUME_SPEAKER_MAX);
Pokitto 46:e7e438368e16 643 #else
Pokitto 46:e7e438368e16 644 //showWarning();
Pokitto 46:e7e438368e16 645 setVolLimit();
Pokitto 46:e7e438368e16 646 display.clear();
Pokitto 46:e7e438368e16 647 display.update();
Pokitto 46:e7e438368e16 648
Pokitto 46:e7e438368e16 649 while(buttons.states[BTN_A])
Pokitto 46:e7e438368e16 650 {
Pokitto 46:e7e438368e16 651 buttons.update();
Pokitto 46:e7e438368e16 652 }
Pokitto 46:e7e438368e16 653
Pokitto 46:e7e438368e16 654 //sound.setVolume(sound.getVolume());//make sure we're at set volume before continue
Pokitto 46:e7e438368e16 655 #endif
Pokitto 46:e7e438368e16 656 display.enableDirectPrinting(false);
Pokitto 46:e7e438368e16 657 display.adjustCharStep=1;
Pokitto 46:e7e438368e16 658 display.adjustLineStep=1;
Pokitto 46:e7e438368e16 659 display.fontSize=1;
Pokitto 46:e7e438368e16 660 display.textWrap=true;
Pokitto 46:e7e438368e16 661 #if POK_GAMEBUINO_SUPPORT > 0
Pokitto 46:e7e438368e16 662 display.setFont(font5x7);
Pokitto 46:e7e438368e16 663 #else
Pokitto 46:e7e438368e16 664 display.setFont(fontC64);
Pokitto 46:e7e438368e16 665 #endif
Pokitto 46:e7e438368e16 666 #if POK_ENABLE_SOUND > 0
Pokitto 46:e7e438368e16 667 sound.begin();
Pokitto 46:e7e438368e16 668
Pokitto 46:e7e438368e16 669 //mute when B is held during start up or if battery is low
Pokitto 46:e7e438368e16 670 battery.update();
Pokitto 46:e7e438368e16 671 if(buttons.pressed(BTN_B)){
Pokitto 46:e7e438368e16 672 sound.setVolume(0);
Pokitto 46:e7e438368e16 673 }
Pokitto 46:e7e438368e16 674 else{ //play the startup sound on each channel for it to be louder
Pokitto 46:e7e438368e16 675 #if POK_GBSOUND > 0
Pokitto 46:e7e438368e16 676 #if(NUM_CHANNELS > 0)
Pokitto 46:e7e438368e16 677 sound.playPattern(startupSound, 0);
Pokitto 46:e7e438368e16 678 #endif
Pokitto 46:e7e438368e16 679 #if(NUM_CHANNELS > 1)
Pokitto 46:e7e438368e16 680 sound.playPattern(startupSound, 1);
Pokitto 46:e7e438368e16 681 #endif
Pokitto 46:e7e438368e16 682 #if(NUM_CHANNELS > 2)
Pokitto 46:e7e438368e16 683 sound.playPattern(startupSound, 2);
Pokitto 46:e7e438368e16 684 #endif
Pokitto 46:e7e438368e16 685 #if(NUM_CHANNELS > 3)
Pokitto 46:e7e438368e16 686 sound.playPattern(startupSound, 3);
Pokitto 46:e7e438368e16 687 #endif
Pokitto 46:e7e438368e16 688 #endif // POK_GBSOUND
Pokitto 46:e7e438368e16 689 }
Pokitto 46:e7e438368e16 690 #endif // POK ENABLE_SOUND
Pokitto 46:e7e438368e16 691 }
Pokitto 46:e7e438368e16 692
Pokitto 46:e7e438368e16 693 void Core::init() {
Pokitto 46:e7e438368e16 694 run_state = true;
Pokitto 46:e7e438368e16 695 display.enableDirectPrinting(false);
Pokitto 46:e7e438368e16 696 display.setFont(DEFAULT_FONT);
Pokitto 46:e7e438368e16 697 initClock();
Pokitto 46:e7e438368e16 698 initGPIO();
Pokitto 46:e7e438368e16 699 initButtons();
Pokitto 46:e7e438368e16 700 initRandom();
Pokitto 46:e7e438368e16 701 //initAudio();
Pokitto 46:e7e438368e16 702 //initDisplay();
Pokitto 46:e7e438368e16 703 }
Pokitto 46:e7e438368e16 704
Pokitto 46:e7e438368e16 705 void Core::init(uint8_t switches) {
Pokitto 46:e7e438368e16 706 run_state = true;
Pokitto 46:e7e438368e16 707 display.enableDirectPrinting(false);
Pokitto 46:e7e438368e16 708 display.setFont(DEFAULT_FONT);
Pokitto 46:e7e438368e16 709 initClock();
Pokitto 46:e7e438368e16 710 initGPIO();
Pokitto 46:e7e438368e16 711 initButtons();
Pokitto 46:e7e438368e16 712 initRandom();
Pokitto 46:e7e438368e16 713 //initAudio();
Pokitto 46:e7e438368e16 714 //initDisplay();
Pokitto 46:e7e438368e16 715 }
Pokitto 46:e7e438368e16 716
Pokitto 46:e7e438368e16 717 void Core::initButtons() {
Pokitto 46:e7e438368e16 718 #ifndef POK_SIM
Pokitto 46:e7e438368e16 719 Pokitto::initButtons();
Pokitto 46:e7e438368e16 720 #endif
Pokitto 46:e7e438368e16 721 }
Pokitto 46:e7e438368e16 722
Pokitto 46:e7e438368e16 723 bool Core::isRunning() {
Pokitto 46:e7e438368e16 724 #ifdef POK_SIM
Pokitto 46:e7e438368e16 725 run_state = simulator.isRunning();
Pokitto 46:e7e438368e16 726 #endif // POK_SIM
Pokitto 46:e7e438368e16 727 return run_state;
Pokitto 46:e7e438368e16 728 }
Pokitto 46:e7e438368e16 729
Pokitto 46:e7e438368e16 730 void Core::initDisplay() {
Pokitto 46:e7e438368e16 731 #if POK_DISPLAYLOGO > 0
Pokitto 46:e7e438368e16 732 showLogo();
Pokitto 46:e7e438368e16 733 #endif
Pokitto 46:e7e438368e16 734 #if POK_USE_CONSOLE > 0
Pokitto 46:e7e438368e16 735 console.AddMessage(MSOURCE_LCD,MSG_INIT_OK);
Pokitto 46:e7e438368e16 736 #endif
Pokitto 46:e7e438368e16 737 }
Pokitto 46:e7e438368e16 738
Pokitto 46:e7e438368e16 739 void Core::showLogo() {
Pokitto 46:e7e438368e16 740 uint32_t now;
Pokitto 46:e7e438368e16 741 uint8_t state=0; //jump directly to logo, bypass teeth
Pokitto 46:e7e438368e16 742 uint16_t counter=0, i=0;
Pokitto 46:e7e438368e16 743 uint16_t sc;
Pokitto 46:e7e438368e16 744 while (state < 255/6) {
Pokitto 46:e7e438368e16 745 now=getTime();
Pokitto 46:e7e438368e16 746 if (now>refreshtime) {
Pokitto 46:e7e438368e16 747 refreshtime=now+30;
Pokitto 46:e7e438368e16 748 switch (state) {
Pokitto 46:e7e438368e16 749 case 0:
Pokitto 46:e7e438368e16 750 /** POKITTO CLEAN **/
Pokitto 46:e7e438368e16 751 display.directbgcolor = COLOR_BLACK;
Pokitto 46:e7e438368e16 752 display.fillLCD(display.directbgcolor);
Pokitto 46:e7e438368e16 753 sc = COLOR_BLACK;
Pokitto 46:e7e438368e16 754 state++;
Pokitto 46:e7e438368e16 755 break;
Pokitto 46:e7e438368e16 756 case 1:
Pokitto 46:e7e438368e16 757 /** POKITTO FADE IN **/
Pokitto 46:e7e438368e16 758 display.directcolor = display.interpolateColor(sc, COLOR_GREEN, i);
Pokitto 46:e7e438368e16 759 display.directBitmap(POK_LCD_W/2 - (*Pokitto_logo/2),POK_LCD_H/2-(*(Pokitto_logo+1)/2),Pokitto_logo,1,1);
Pokitto 46:e7e438368e16 760 i += 28;
Pokitto 46:e7e438368e16 761 if (i>=0xFF) { state++; i=0;}
Pokitto 46:e7e438368e16 762 break;
Pokitto 46:e7e438368e16 763 case 2:
Pokitto 46:e7e438368e16 764 /** POKITTO WAIT **/
Pokitto 46:e7e438368e16 765 display.directcolor = COLOR_GREEN;
Pokitto 46:e7e438368e16 766 display.directBitmap(POK_LCD_W/2 - (*Pokitto_logo/2),POK_LCD_H/2-(*(Pokitto_logo+1)/2),Pokitto_logo,1,1);
Pokitto 46:e7e438368e16 767 i+= 0x3F;
Pokitto 46:e7e438368e16 768 if (i>0x3FF) state = 255;
Pokitto 46:e7e438368e16 769 break;
Pokitto 46:e7e438368e16 770 }
Pokitto 46:e7e438368e16 771 if(buttons.aBtn()) state=255;
Pokitto 46:e7e438368e16 772 }
Pokitto 46:e7e438368e16 773 }
Pokitto 46:e7e438368e16 774 }
Pokitto 46:e7e438368e16 775
Pokitto 46:e7e438368e16 776 void Core::readSettings() {
Pokitto 46:e7e438368e16 777 // ToDo
Pokitto 46:e7e438368e16 778 /*display.contrast = SCR_CONTRAST;
Pokitto 46:e7e438368e16 779 backlight.backlightMin = BACKLIGHT_MIN;
Pokitto 46:e7e438368e16 780 backlight.backlightMax = BACKLIGHT_MAX;
Pokitto 46:e7e438368e16 781 backlight.ambientLightMin = AMBIENTLIGHT_MIN;
Pokitto 46:e7e438368e16 782 backlight.ambientLightMax = AMBIENTLIGHT_MAX;
Pokitto 46:e7e438368e16 783 */
Pokitto 46:e7e438368e16 784 sound.setMaxVol(VOLUME_HEADPHONE_MAX);
Pokitto 46:e7e438368e16 785 sound.globalVolume = VOLUME_STARTUP;
Pokitto 46:e7e438368e16 786
Pokitto 46:e7e438368e16 787 startMenuTimer = START_MENU_TIMER;
Pokitto 46:e7e438368e16 788 /*
Pokitto 46:e7e438368e16 789 battery.thresolds[0] = BAT_LVL_CRITIC;
Pokitto 46:e7e438368e16 790 battery.thresolds[1] = BAT_LVL_LOW;
Pokitto 46:e7e438368e16 791 battery.thresolds[2] = BAT_LVL_MED;
Pokitto 46:e7e438368e16 792 battery.thresolds[3] = BAT_LVL_FULL;*/
Pokitto 46:e7e438368e16 793 }
Pokitto 46:e7e438368e16 794
Pokitto 46:e7e438368e16 795 void Core::titleScreen(const char* name){
Pokitto 46:e7e438368e16 796 titleScreen(name, 0);
Pokitto 46:e7e438368e16 797 }
Pokitto 46:e7e438368e16 798
Pokitto 46:e7e438368e16 799 void Core::titleScreen(const uint8_t* logo){
Pokitto 46:e7e438368e16 800 titleScreen((""), logo);
Pokitto 46:e7e438368e16 801 }
Pokitto 46:e7e438368e16 802
Pokitto 46:e7e438368e16 803 void Core::titleScreen(){
Pokitto 46:e7e438368e16 804 titleScreen((""));
Pokitto 46:e7e438368e16 805 }
Pokitto 46:e7e438368e16 806
Pokitto 46:e7e438368e16 807 void Core::titleScreen(const char* name, const uint8_t *logo){
Pokitto 46:e7e438368e16 808 display.setFont(font5x7);
Pokitto 46:e7e438368e16 809 if(startMenuTimer){
Pokitto 46:e7e438368e16 810 display.fontSize = 1;
Pokitto 46:e7e438368e16 811 display.textWrap = false;
Pokitto 46:e7e438368e16 812 display.persistence = false;
Pokitto 46:e7e438368e16 813 battery.show = false;
Pokitto 46:e7e438368e16 814 display.setColor(BLACK);
Pokitto 46:e7e438368e16 815 while(isRunning()){
Pokitto 46:e7e438368e16 816 if(update()){
Pokitto 46:e7e438368e16 817 uint8_t logoOffset = name[0]?display.fontHeight:0; //add an offset the logo when there is a name to display
Pokitto 46:e7e438368e16 818 //draw graphics
Pokitto 46:e7e438368e16 819 display.setColorDepth(1);
Pokitto 46:e7e438368e16 820 display.setColor(3);
Pokitto 46:e7e438368e16 821 //display.drawBitmap(0,0, gamebuinoLogo);
Pokitto 46:e7e438368e16 822 display.setColor(1);
Pokitto 46:e7e438368e16 823 if(logo){
Pokitto 46:e7e438368e16 824 display.drawBitmap(0, 12+logoOffset, logo);
Pokitto 46:e7e438368e16 825 }
Pokitto 46:e7e438368e16 826 display.cursorX = 0;
Pokitto 46:e7e438368e16 827 display.cursorY = 12;
Pokitto 46:e7e438368e16 828 display.print(name);
Pokitto 46:e7e438368e16 829
Pokitto 46:e7e438368e16 830 //A button
Pokitto 46:e7e438368e16 831 display.cursorX = LCDWIDTH - display.fontWidth*3 -1;
Pokitto 46:e7e438368e16 832 display.cursorY = LCDHEIGHT - display.fontHeight*3 - 3;
Pokitto 46:e7e438368e16 833 if((frameCount/16)%2)
Pokitto 46:e7e438368e16 834 display.println(("\25 \20"));
Pokitto 46:e7e438368e16 835 else
Pokitto 46:e7e438368e16 836 display.println(("\25\20 "));
Pokitto 46:e7e438368e16 837 //B button
Pokitto 46:e7e438368e16 838 display.cursorX = LCDWIDTH - display.fontWidth*3 - 1;
Pokitto 46:e7e438368e16 839 display.cursorY++;
Pokitto 46:e7e438368e16 840 if(sound.globalVolume)
Pokitto 46:e7e438368e16 841 display.println(("\26\23\24"));
Pokitto 46:e7e438368e16 842 else
Pokitto 46:e7e438368e16 843 display.println(("\26\23x"));
Pokitto 46:e7e438368e16 844 //C button
Pokitto 46:e7e438368e16 845 display.cursorX = LCDWIDTH - display.fontWidth*3 - 1;
Pokitto 46:e7e438368e16 846 display.cursorY++;
Pokitto 46:e7e438368e16 847 //display.println(F("\27SD"));
Pokitto 46:e7e438368e16 848
Pokitto 46:e7e438368e16 849 //toggle volume when B is pressed
Pokitto 46:e7e438368e16 850 if(buttons.pressed(BTN_B)){
Pokitto 46:e7e438368e16 851 sound.setVolume(sound.getVolume() + 1);
Pokitto 46:e7e438368e16 852 sound.playTick();
Pokitto 46:e7e438368e16 853 }
Pokitto 46:e7e438368e16 854 //leave the menu
Pokitto 46:e7e438368e16 855 if(buttons.pressed(BTN_A) || ((frameCount>=startMenuTimer)&&(startMenuTimer != 255))){
Pokitto 46:e7e438368e16 856 startMenuTimer = 255; //don't automatically skip the title screen next time it's displayed
Pokitto 46:e7e438368e16 857 sound.stopPattern(0);
Pokitto 46:e7e438368e16 858 sound.playOK();
Pokitto 46:e7e438368e16 859 break;
Pokitto 46:e7e438368e16 860 }
Pokitto 46:e7e438368e16 861 //flash the loader
Pokitto 46:e7e438368e16 862 //if(buttons.pressed(BTN_C))
Pokitto 46:e7e438368e16 863 // ToDo changeGame();
Pokitto 46:e7e438368e16 864 }
Pokitto 46:e7e438368e16 865 }
Pokitto 46:e7e438368e16 866 battery.show = true;
Pokitto 46:e7e438368e16 867 }
Pokitto 46:e7e438368e16 868 }
Pokitto 46:e7e438368e16 869
Pokitto 46:e7e438368e16 870 /**
Pokitto 46:e7e438368e16 871 * Update all the subsystems, like graphics, audio, events, etc.
Pokitto 46:e7e438368e16 872 * Note: the update rect is used for drawing only part of the screen buffer to LCD. Because of speed optimizations,
Pokitto 46:e7e438368e16 873 * the x, y, and width of the update rect must be dividable by 4 pixels, and the height must be dividable by 8 pixels.
Pokitto 46:e7e438368e16 874 * The update rect is currently used for 220x176, 4 colors, screen mode only.
Pokitto 46:e7e438368e16 875 * @param useDirectMode True, if only direct screen drawing is used. False, if the screen buffer is drawn. Note: If sprites are enabled, they are drawn in both modes.
Pokitto 46:e7e438368e16 876 * @param updRectX The update rect.
Pokitto 46:e7e438368e16 877 * @param updRectY The update rect.
Pokitto 46:e7e438368e16 878 * @param updRectW The update rect.
Pokitto 46:e7e438368e16 879 * @param updRectH The update rect.
Pokitto 46:e7e438368e16 880 */
Pokitto 46:e7e438368e16 881 bool Core::update(bool useDirectMode, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH) {
Pokitto 46:e7e438368e16 882
Pokitto 46:e7e438368e16 883 #if POK_STREAMING_MUSIC
Pokitto 46:e7e438368e16 884 sound.updateStream();
Pokitto 46:e7e438368e16 885 #endif
Pokitto 46:e7e438368e16 886
Pokitto 46:e7e438368e16 887 uint32_t now = getTime();
Pokitto 46:e7e438368e16 888 if ((((nextFrameMillis - now)) > timePerFrame) && frameEndMicros) { //if time to render a new frame is reached and the frame end has ran once
Pokitto 46:e7e438368e16 889 nextFrameMillis = now + timePerFrame;
Pokitto 46:e7e438368e16 890 frameCount++;
Pokitto 46:e7e438368e16 891
Pokitto 46:e7e438368e16 892 frameEndMicros = 0;
Pokitto 46:e7e438368e16 893 backlight.update();
Pokitto 46:e7e438368e16 894 buttons.update();
Pokitto 46:e7e438368e16 895 battery.update();
Pokitto 46:e7e438368e16 896
Pokitto 46:e7e438368e16 897 // FPS counter
Pokitto 46:e7e438368e16 898 #if defined(PROJ_USE_FPS_COUNTER) || defined(PROJ_SHOW_FPS_COUNTER)
Pokitto 46:e7e438368e16 899 const uint32_t fpsInterval_ms = 1000*3;
Pokitto 46:e7e438368e16 900
Pokitto 46:e7e438368e16 901 fps_frameCount++;
Pokitto 46:e7e438368e16 902 if (now > fps_refreshtime) {
Pokitto 46:e7e438368e16 903 fps_counter = (1000*fps_frameCount) / (now - fps_refreshtime + fpsInterval_ms);
Pokitto 46:e7e438368e16 904 fps_refreshtime = now + fpsInterval_ms;
Pokitto 46:e7e438368e16 905 fps_frameCount = 0;
Pokitto 46:e7e438368e16 906 fps_counter_updated = true;
Pokitto 46:e7e438368e16 907 }
Pokitto 46:e7e438368e16 908 #endif
Pokitto 46:e7e438368e16 909
Pokitto 46:e7e438368e16 910 return true;
Pokitto 46:e7e438368e16 911
Pokitto 46:e7e438368e16 912 } else {
Pokitto 46:e7e438368e16 913 if (!frameEndMicros) { //runs once at the end of the frame
Pokitto 46:e7e438368e16 914 #if POK_ENABLE_SOUND > 0
Pokitto 46:e7e438368e16 915 sound.updateTrack();
Pokitto 46:e7e438368e16 916 sound.updatePattern();
Pokitto 46:e7e438368e16 917 sound.updateNote();
Pokitto 46:e7e438368e16 918 #endif
Pokitto 46:e7e438368e16 919 updatePopup();
Pokitto 46:e7e438368e16 920 displayBattery();
Pokitto 46:e7e438368e16 921
Pokitto 46:e7e438368e16 922 display.update(useDirectMode, updRectX, updRectY, updRectW, updRectH); //send the buffer to the screen
Pokitto 46:e7e438368e16 923
Pokitto 46:e7e438368e16 924 frameEndMicros = 1; //jonne
Pokitto 46:e7e438368e16 925
Pokitto 46:e7e438368e16 926 }
Pokitto 46:e7e438368e16 927 return false;
Pokitto 46:e7e438368e16 928 }
Pokitto 46:e7e438368e16 929 }
Pokitto 46:e7e438368e16 930
Pokitto 46:e7e438368e16 931 void Core::displayBattery(){
Pokitto 46:e7e438368e16 932 #if (ENABLE_BATTERY > 0)
Pokitto 46:e7e438368e16 933 //display.setColor(BLACK, WHITE);
Pokitto 46:e7e438368e16 934 uint8_t ox,oy;
Pokitto 46:e7e438368e16 935 ox=display.cursorX;
Pokitto 46:e7e438368e16 936 oy=display.cursorY;
Pokitto 46:e7e438368e16 937 display.cursorX = LCDWIDTH-display.fontWidth+1;
Pokitto 46:e7e438368e16 938 display.cursorY = 0;
Pokitto 46:e7e438368e16 939 switch(battery.level){
Pokitto 46:e7e438368e16 940 case 0://battery critic, power down
Pokitto 46:e7e438368e16 941 sound.stopPattern();
Pokitto 46:e7e438368e16 942 backlight.set(0);
Pokitto 46:e7e438368e16 943 display.clear();
Pokitto 46:e7e438368e16 944 display.fontSize = 1;
Pokitto 46:e7e438368e16 945 display.print(("LOW BATTERY\n"));
Pokitto 46:e7e438368e16 946 display.print(battery.voltage);
Pokitto 46:e7e438368e16 947 display.print(("mV\n\nPLEASE\nTURN OFF"));
Pokitto 46:e7e438368e16 948 display.update();
Pokitto 46:e7e438368e16 949 break;
Pokitto 46:e7e438368e16 950 case 1: //empty battery
Pokitto 46:e7e438368e16 951 if((frameCount % 16) < 8) display.print('\7'); //blinking battery
Pokitto 46:e7e438368e16 952 else display.print('x');
Pokitto 46:e7e438368e16 953 break;
Pokitto 46:e7e438368e16 954 case 2://low battery
Pokitto 46:e7e438368e16 955 case 3://full battery
Pokitto 46:e7e438368e16 956 case 4://full battery
Pokitto 46:e7e438368e16 957 if(battery.show){
Pokitto 46:e7e438368e16 958 display.print(char(5+battery.level));
Pokitto 46:e7e438368e16 959 }
Pokitto 46:e7e438368e16 960 break;
Pokitto 46:e7e438368e16 961 default:
Pokitto 46:e7e438368e16 962 if(battery.show){
Pokitto 46:e7e438368e16 963 display.print('/');
Pokitto 46:e7e438368e16 964 }
Pokitto 46:e7e438368e16 965 break;
Pokitto 46:e7e438368e16 966 }
Pokitto 46:e7e438368e16 967 display.cursorX = ox;
Pokitto 46:e7e438368e16 968 display.cursorY = oy;
Pokitto 46:e7e438368e16 969 #endif
Pokitto 46:e7e438368e16 970 }
Pokitto 46:e7e438368e16 971
Pokitto 46:e7e438368e16 972 char* Core::filemenu(char *ext) {
Pokitto 46:e7e438368e16 973 uint8_t oldPersistence = display.persistence;
Pokitto 46:e7e438368e16 974 display.persistence = false;
Pokitto 46:e7e438368e16 975 uint16_t oldpal0=display.palette[0];
Pokitto 46:e7e438368e16 976 uint16_t oldpal1=display.palette[1];
Pokitto 46:e7e438368e16 977 uint16_t oldpal2=display.palette[2];
Pokitto 46:e7e438368e16 978 display.palette[2]=COLOR_GREEN;
Pokitto 46:e7e438368e16 979 display.palette[1]=COLOR_WHITE;
Pokitto 46:e7e438368e16 980 display.palette[0]=COLOR_BLACK;
Pokitto 46:e7e438368e16 981 uint8_t oldbg=display.bgcolor;
Pokitto 46:e7e438368e16 982 uint8_t oldfg=display.color;
Pokitto 46:e7e438368e16 983 display.color=1;
Pokitto 46:e7e438368e16 984 display.bgcolor=0;
Pokitto 46:e7e438368e16 985
Pokitto 46:e7e438368e16 986 int16_t rowh = display.fontHeight + 2;
Pokitto 46:e7e438368e16 987 int8_t activeItem = 0;
Pokitto 46:e7e438368e16 988 int16_t currentTopItem = 0;
Pokitto 46:e7e438368e16 989 int16_t itemsPerScreen = (display.height+1) / rowh;
Pokitto 46:e7e438368e16 990 int16_t numOfItemsFound = 0;
Pokitto 46:e7e438368e16 991 boolean exit = false;
Pokitto 46:e7e438368e16 992
Pokitto 46:e7e438368e16 993 char* txt;
Pokitto 46:e7e438368e16 994
Pokitto 46:e7e438368e16 995 pokInitSD();
Pokitto 46:e7e438368e16 996
Pokitto 46:e7e438368e16 997 bool updated = true;
Pokitto 46:e7e438368e16 998 while (isRunning()) {
Pokitto 46:e7e438368e16 999 if (update(true)) {
Pokitto 46:e7e438368e16 1000 if (buttons.pressed(BTN_A) || buttons.pressed(BTN_B) || buttons.pressed(BTN_C)) {
Pokitto 46:e7e438368e16 1001 exit = true; //time to exit menu !
Pokitto 46:e7e438368e16 1002 if (buttons.pressed(BTN_A)) {
Pokitto 46:e7e438368e16 1003 sound.playOK();
Pokitto 46:e7e438368e16 1004 } else {
Pokitto 46:e7e438368e16 1005 *selectedfile = 0;
Pokitto 46:e7e438368e16 1006 sound.playCancel();
Pokitto 46:e7e438368e16 1007 }
Pokitto 46:e7e438368e16 1008 updated = true; // update screen
Pokitto 46:e7e438368e16 1009 }
Pokitto 46:e7e438368e16 1010 if (exit == false) {
Pokitto 46:e7e438368e16 1011 if (buttons.repeat(BTN_DOWN,4)) {
Pokitto 46:e7e438368e16 1012 if( ++activeItem >= numOfItemsFound ) activeItem = numOfItemsFound - 1;
Pokitto 46:e7e438368e16 1013 if( activeItem >= currentTopItem + itemsPerScreen) currentTopItem += itemsPerScreen; // next page
Pokitto 46:e7e438368e16 1014 sound.playTick();
Pokitto 46:e7e438368e16 1015 updated = true; // update screen
Pokitto 46:e7e438368e16 1016 }
Pokitto 46:e7e438368e16 1017 if (buttons.repeat(BTN_UP,4)) {
Pokitto 46:e7e438368e16 1018 if( --activeItem < 0 ) activeItem = 0;
Pokitto 46:e7e438368e16 1019 if( activeItem < currentTopItem) currentTopItem -= itemsPerScreen; // previous page
Pokitto 46:e7e438368e16 1020 sound.playTick();
Pokitto 46:e7e438368e16 1021 updated = true; // update screen
Pokitto 46:e7e438368e16 1022 }
Pokitto 46:e7e438368e16 1023
Pokitto 46:e7e438368e16 1024 } else { //exit :
Pokitto 46:e7e438368e16 1025 display.bgcolor=oldbg;
Pokitto 46:e7e438368e16 1026 display.color=oldfg;
Pokitto 46:e7e438368e16 1027 display.palette[0] = oldpal0;
Pokitto 46:e7e438368e16 1028 display.palette[1] = oldpal1;
Pokitto 46:e7e438368e16 1029 display.palette[2] = oldpal2;
Pokitto 46:e7e438368e16 1030 display.persistence = oldPersistence;
Pokitto 46:e7e438368e16 1031 return selectedfile;
Pokitto 46:e7e438368e16 1032 }
Pokitto 46:e7e438368e16 1033
Pokitto 46:e7e438368e16 1034 //draw a fancy menu
Pokitto 46:e7e438368e16 1035 display.textWrap = false;
Pokitto 46:e7e438368e16 1036 uint16_t fc,bc;
Pokitto 46:e7e438368e16 1037 fc = display.color;
Pokitto 46:e7e438368e16 1038 bc = display.bgcolor;
Pokitto 46:e7e438368e16 1039 if( updated ) { // update screen?
Pokitto 46:e7e438368e16 1040 #if POK_SIM
Pokitto 46:e7e438368e16 1041 getFirstFile(ext);
Pokitto 46:e7e438368e16 1042 #else
Pokitto 46:e7e438368e16 1043 bool isFirstFile = true;
Pokitto 46:e7e438368e16 1044 #endif
Pokitto 46:e7e438368e16 1045 for (int i = 0; ; i++) {
Pokitto 46:e7e438368e16 1046 display.cursorX = 0;
Pokitto 46:e7e438368e16 1047 display.invisiblecolor=255;
Pokitto 46:e7e438368e16 1048 display.cursorY = (i - currentTopItem ) * rowh;
Pokitto 46:e7e438368e16 1049
Pokitto 46:e7e438368e16 1050 // read the file name from SD
Pokitto 46:e7e438368e16 1051 #ifndef POK_SIM
Pokitto 46:e7e438368e16 1052 if(isFirstFile) {
Pokitto 46:e7e438368e16 1053 txt = getFirstFile(ext);
Pokitto 46:e7e438368e16 1054 isFirstFile = false;
Pokitto 46:e7e438368e16 1055 }
Pokitto 46:e7e438368e16 1056 else
Pokitto 46:e7e438368e16 1057 #endif
Pokitto 46:e7e438368e16 1058
Pokitto 46:e7e438368e16 1059 txt = getNextFile(ext);
Pokitto 46:e7e438368e16 1060
Pokitto 46:e7e438368e16 1061 if (txt) {
Pokitto 46:e7e438368e16 1062
Pokitto 46:e7e438368e16 1063 numOfItemsFound = i+1;
Pokitto 46:e7e438368e16 1064
Pokitto 46:e7e438368e16 1065 // Draw active line with diffrent backgtound and char color
Pokitto 46:e7e438368e16 1066 if (i == activeItem){
Pokitto 46:e7e438368e16 1067 display.cursorX = 3;
Pokitto 46:e7e438368e16 1068 display.color=2;
Pokitto 46:e7e438368e16 1069 display.fillRect(0, display.cursorY - 2, LCDWIDTH, rowh);
Pokitto 46:e7e438368e16 1070 display.setColor(0,2);
Pokitto 46:e7e438368e16 1071 } else display.setColor(1,0);
Pokitto 46:e7e438368e16 1072
Pokitto 46:e7e438368e16 1073 // break loop if going out of screen
Pokitto 46:e7e438368e16 1074 if(i >= currentTopItem + itemsPerScreen ) {
Pokitto 46:e7e438368e16 1075 break;
Pokitto 46:e7e438368e16 1076 }
Pokitto 46:e7e438368e16 1077
Pokitto 46:e7e438368e16 1078 // Display only if the file is on the current page
Pokitto 46:e7e438368e16 1079 if( i >= currentTopItem) {
Pokitto 46:e7e438368e16 1080 display.print(display.cursorX, display.cursorY, txt);
Pokitto 46:e7e438368e16 1081 if (i == activeItem)
Pokitto 46:e7e438368e16 1082 strcpy(selectedfile,txt);
Pokitto 46:e7e438368e16 1083 }
Pokitto 46:e7e438368e16 1084 } else
Pokitto 46:e7e438368e16 1085 break; // break loop as no more files found
Pokitto 46:e7e438368e16 1086
Pokitto 46:e7e438368e16 1087 display.setColor(1,0);
Pokitto 46:e7e438368e16 1088 } // end for
Pokitto 46:e7e438368e16 1089
Pokitto 46:e7e438368e16 1090 display.update();
Pokitto 46:e7e438368e16 1091 }
Pokitto 46:e7e438368e16 1092 updated = false;
Pokitto 46:e7e438368e16 1093 } // update
Pokitto 46:e7e438368e16 1094
Pokitto 46:e7e438368e16 1095 display.setColor(1,0);
Pokitto 46:e7e438368e16 1096 }
Pokitto 46:e7e438368e16 1097 return 0;
Pokitto 46:e7e438368e16 1098 }
Pokitto 46:e7e438368e16 1099
Pokitto 46:e7e438368e16 1100 char* Core::filemenu() {
Pokitto 46:e7e438368e16 1101 return filemenu("");
Pokitto 46:e7e438368e16 1102 }
Pokitto 46:e7e438368e16 1103
Pokitto 46:e7e438368e16 1104 int8_t Core::menu(const char* const* items, uint8_t length) {
Pokitto 49:74201663ba8b 1105 if (display.color>4) display.color=1;
Pokitto 46:e7e438368e16 1106 #if (ENABLE_GUI > 0)
Pokitto 46:e7e438368e16 1107 display.persistence = false;
Pokitto 46:e7e438368e16 1108 int8_t activeItem = 0;
Pokitto 46:e7e438368e16 1109 int16_t currentY = display.height;
Pokitto 46:e7e438368e16 1110 int16_t targetY = 0, rowh = display.fontHeight + 2;
Pokitto 46:e7e438368e16 1111 boolean exit = false;
Pokitto 46:e7e438368e16 1112 int8_t answer = -1;
Pokitto 46:e7e438368e16 1113 while (isRunning()) {
Pokitto 46:e7e438368e16 1114 if (update()) {
Pokitto 46:e7e438368e16 1115 if (buttons.pressed(BTN_A) || buttons.pressed(BTN_B) || buttons.pressed(BTN_C)) {
Pokitto 46:e7e438368e16 1116 exit = true; //time to exit menu !
Pokitto 46:e7e438368e16 1117 targetY = - display.fontHeight * length - 2; //send the menu out of the screen
Pokitto 46:e7e438368e16 1118 if (buttons.pressed(BTN_A)) {
Pokitto 46:e7e438368e16 1119 answer = activeItem;
Pokitto 46:e7e438368e16 1120 sound.playOK();
Pokitto 46:e7e438368e16 1121 } else {
Pokitto 46:e7e438368e16 1122 sound.playCancel();
Pokitto 46:e7e438368e16 1123 }
Pokitto 46:e7e438368e16 1124 }
Pokitto 46:e7e438368e16 1125 if (exit == false) {
Pokitto 46:e7e438368e16 1126 if (buttons.repeat(BTN_DOWN,4)) {
Pokitto 46:e7e438368e16 1127 activeItem++;
Pokitto 46:e7e438368e16 1128 sound.playTick();
Pokitto 46:e7e438368e16 1129 }
Pokitto 46:e7e438368e16 1130 if (buttons.repeat(BTN_UP,4)) {
Pokitto 46:e7e438368e16 1131 activeItem--;
Pokitto 46:e7e438368e16 1132 sound.playTick();
Pokitto 46:e7e438368e16 1133 }
Pokitto 46:e7e438368e16 1134 //don't go out of the menu
Pokitto 46:e7e438368e16 1135 if (activeItem == length) activeItem = 0;
Pokitto 46:e7e438368e16 1136 if (activeItem < 0) activeItem = length - 1;
Pokitto 46:e7e438368e16 1137
Pokitto 46:e7e438368e16 1138 targetY = -rowh * activeItem + (rowh+4); //center the menu on the active item
Pokitto 46:e7e438368e16 1139 } else { //exit :
Pokitto 46:e7e438368e16 1140 if ((currentY - targetY) <= 1)
Pokitto 46:e7e438368e16 1141 return (answer);
Pokitto 46:e7e438368e16 1142 }
Pokitto 46:e7e438368e16 1143 //draw a fancy menu
Pokitto 46:e7e438368e16 1144 currentY = (currentY + targetY) / 2;
Pokitto 46:e7e438368e16 1145 display.cursorX = 0;
Pokitto 46:e7e438368e16 1146 display.cursorY = currentY;
Pokitto 46:e7e438368e16 1147 display.textWrap = false;
Pokitto 46:e7e438368e16 1148 uint16_t fc,bc;
Pokitto 46:e7e438368e16 1149 fc = display.color;
Pokitto 46:e7e438368e16 1150 bc = display.bgcolor;
Pokitto 46:e7e438368e16 1151 for (byte i = 0; i < length; i++) {
Pokitto 46:e7e438368e16 1152 display.cursorY = currentY + rowh * i;
Pokitto 46:e7e438368e16 1153 if (i == activeItem){
Pokitto 46:e7e438368e16 1154 display.cursorX = 3;
Pokitto 46:e7e438368e16 1155
Pokitto 46:e7e438368e16 1156 //display.fillRoundRect(0, currentY + display.fontHeight * activeItem - 2, LCDWIDTH, (display.fontHeight+3), 3);
Pokitto 46:e7e438368e16 1157 display.fillRect(0, currentY + rowh * activeItem - 2, LCDWIDTH, (rowh));
Pokitto 46:e7e438368e16 1158 display.setColor(bc,fc);
Pokitto 46:e7e438368e16 1159 } else display.setColor(fc,bc);
Pokitto 46:e7e438368e16 1160
Pokitto 46:e7e438368e16 1161 display.println((char*)*(const unsigned int*)(items+i));
Pokitto 46:e7e438368e16 1162 display.setColor(fc,bc);
Pokitto 46:e7e438368e16 1163 }
Pokitto 46:e7e438368e16 1164
Pokitto 46:e7e438368e16 1165 }
Pokitto 46:e7e438368e16 1166 }
Pokitto 46:e7e438368e16 1167 #else
Pokitto 46:e7e438368e16 1168 return 0;
Pokitto 46:e7e438368e16 1169 #endif
Pokitto 46:e7e438368e16 1170 return 0;
Pokitto 46:e7e438368e16 1171 }
Pokitto 46:e7e438368e16 1172
Pokitto 46:e7e438368e16 1173 void Core::keyboard(char* text, uint8_t length) {
Pokitto 46:e7e438368e16 1174 #if (ENABLE_GUI > 0)
Pokitto 46:e7e438368e16 1175 display.persistence = false;
Pokitto 46:e7e438368e16 1176 //memset(text, 0, length); //clear the text
Pokitto 46:e7e438368e16 1177 text[length-1] = '\0';
Pokitto 46:e7e438368e16 1178 //active character in the typing area
Pokitto 46:e7e438368e16 1179 int8_t activeChar = 0;
Pokitto 46:e7e438368e16 1180 //selected char on the keyboard
Pokitto 46:e7e438368e16 1181 int8_t activeX = 0;
Pokitto 46:e7e438368e16 1182 int8_t activeY = 2;
Pokitto 46:e7e438368e16 1183 //position of the keyboard on the screen
Pokitto 46:e7e438368e16 1184 int8_t currentX = LCDWIDTH;
Pokitto 46:e7e438368e16 1185 int8_t currentY = LCDHEIGHT;
Pokitto 46:e7e438368e16 1186 int8_t targetX = 0;
Pokitto 46:e7e438368e16 1187 int8_t targetY = 0;
Pokitto 46:e7e438368e16 1188
Pokitto 46:e7e438368e16 1189 while (1) {
Pokitto 46:e7e438368e16 1190 if (update()) {
Pokitto 46:e7e438368e16 1191 //move the character selector
Pokitto 46:e7e438368e16 1192 if (buttons.repeat(BTN_DOWN, 4)) {
Pokitto 46:e7e438368e16 1193 activeY++;
Pokitto 46:e7e438368e16 1194 sound.playTick();
Pokitto 46:e7e438368e16 1195 }
Pokitto 46:e7e438368e16 1196 if (buttons.repeat(BTN_UP, 4)) {
Pokitto 46:e7e438368e16 1197 activeY--;
Pokitto 46:e7e438368e16 1198 sound.playTick();
Pokitto 46:e7e438368e16 1199 }
Pokitto 46:e7e438368e16 1200 if (buttons.repeat(BTN_RIGHT, 4)) {
Pokitto 46:e7e438368e16 1201 activeX++;
Pokitto 46:e7e438368e16 1202 sound.playTick();
Pokitto 46:e7e438368e16 1203 }
Pokitto 46:e7e438368e16 1204 if (buttons.repeat(BTN_LEFT, 4)) {
Pokitto 46:e7e438368e16 1205 activeX--;
Pokitto 46:e7e438368e16 1206 sound.playTick();
Pokitto 46:e7e438368e16 1207 }
Pokitto 46:e7e438368e16 1208 //don't go out of the keyboard
Pokitto 46:e7e438368e16 1209 if (activeX == KEYBOARD_W) activeX = 0;
Pokitto 46:e7e438368e16 1210 if (activeX < 0) activeX = KEYBOARD_W - 1;
Pokitto 46:e7e438368e16 1211 if (activeY == KEYBOARD_H) activeY = 0;
Pokitto 46:e7e438368e16 1212 if (activeY < 0) activeY = KEYBOARD_H - 1;
Pokitto 46:e7e438368e16 1213 //set the keyboard position on screen
Pokitto 46:e7e438368e16 1214 targetX = -(display.fontWidth+1) * activeX + LCDWIDTH / 2 - 3;
Pokitto 46:e7e438368e16 1215 targetY = -(display.fontHeight+1) * activeY + LCDHEIGHT / 2 - 4 - display.fontHeight;
Pokitto 46:e7e438368e16 1216 //smooth the keyboard displacement
Pokitto 46:e7e438368e16 1217 currentX = (targetX + currentX) / 2;
Pokitto 46:e7e438368e16 1218 currentY = (targetY + currentY) / 2;
Pokitto 46:e7e438368e16 1219 //type character
Pokitto 46:e7e438368e16 1220 if (buttons.pressed(BTN_A)) {
Pokitto 46:e7e438368e16 1221 if (activeChar < (length-1)) {
Pokitto 46:e7e438368e16 1222 byte thisChar = activeX + KEYBOARD_W * activeY;
Pokitto 46:e7e438368e16 1223 if((thisChar == 0)||(thisChar == 10)||(thisChar == 13)) //avoid line feed and carriage return
Pokitto 46:e7e438368e16 1224 continue;
Pokitto 46:e7e438368e16 1225 text[activeChar] = thisChar;
Pokitto 46:e7e438368e16 1226 text[activeChar+1] = '\0';
Pokitto 46:e7e438368e16 1227 }
Pokitto 46:e7e438368e16 1228 activeChar++;
Pokitto 46:e7e438368e16 1229 sound.playOK();
Pokitto 46:e7e438368e16 1230 if (activeChar > length)
Pokitto 46:e7e438368e16 1231 activeChar = length;
Pokitto 46:e7e438368e16 1232 }
Pokitto 46:e7e438368e16 1233 //erase character
Pokitto 46:e7e438368e16 1234 if (buttons.pressed(BTN_B)) {
Pokitto 46:e7e438368e16 1235 activeChar--;
Pokitto 46:e7e438368e16 1236 sound.playCancel();
Pokitto 46:e7e438368e16 1237 if (activeChar >= 0)
Pokitto 46:e7e438368e16 1238 text[activeChar] = 0;
Pokitto 46:e7e438368e16 1239 else
Pokitto 46:e7e438368e16 1240 activeChar = 0;
Pokitto 46:e7e438368e16 1241 }
Pokitto 46:e7e438368e16 1242 //leave menu
Pokitto 46:e7e438368e16 1243 if (buttons.pressed(BTN_C)) {
Pokitto 46:e7e438368e16 1244 sound.playOK();
Pokitto 46:e7e438368e16 1245 while (1) {
Pokitto 46:e7e438368e16 1246 if (update()) {
Pokitto 46:e7e438368e16 1247 //display.setCursor(0,0);
Pokitto 46:e7e438368e16 1248 display.println(("You entered\n"));
Pokitto 46:e7e438368e16 1249 display.print(text);
Pokitto 46:e7e438368e16 1250 display.println(("\n\n\n\x15:okay \x16:edit"));
Pokitto 46:e7e438368e16 1251 if(buttons.pressed(BTN_A)){
Pokitto 46:e7e438368e16 1252 sound.playOK();
Pokitto 46:e7e438368e16 1253 return;
Pokitto 46:e7e438368e16 1254 }
Pokitto 46:e7e438368e16 1255 if(buttons.pressed(BTN_B)){
Pokitto 46:e7e438368e16 1256 sound.playCancel();
Pokitto 46:e7e438368e16 1257 break;
Pokitto 46:e7e438368e16 1258 }
Pokitto 46:e7e438368e16 1259 }
Pokitto 46:e7e438368e16 1260 }
Pokitto 46:e7e438368e16 1261 }
Pokitto 46:e7e438368e16 1262 //draw the keyboard
Pokitto 46:e7e438368e16 1263 for (int8_t y = 0; y < KEYBOARD_H; y++) {
Pokitto 46:e7e438368e16 1264 for (int8_t x = 0; x < KEYBOARD_W; x++) {
Pokitto 46:e7e438368e16 1265 display.drawChar(currentX + x * (display.fontWidth+1), currentY + y * (display.fontHeight+1), x + y * KEYBOARD_W, 1);
Pokitto 46:e7e438368e16 1266 }
Pokitto 46:e7e438368e16 1267 }
Pokitto 46:e7e438368e16 1268 //draw instruction
Pokitto 46:e7e438368e16 1269 display.cursorX = currentX-display.fontWidth*6-2;
Pokitto 46:e7e438368e16 1270 display.cursorY = currentY+1*(display.fontHeight+1);
Pokitto 46:e7e438368e16 1271 display.print(("\25type"));
Pokitto 46:e7e438368e16 1272
Pokitto 46:e7e438368e16 1273 display.cursorX = currentX-display.fontWidth*6-2;
Pokitto 46:e7e438368e16 1274 display.cursorY = currentY+2*(display.fontHeight+1);
Pokitto 46:e7e438368e16 1275 display.print(("\26back"));
Pokitto 46:e7e438368e16 1276
Pokitto 46:e7e438368e16 1277 display.cursorX = currentX-display.fontWidth*6-2;
Pokitto 46:e7e438368e16 1278 display.cursorY = currentY+3*(display.fontHeight+1);
Pokitto 46:e7e438368e16 1279 display.print(("\27save"));
Pokitto 46:e7e438368e16 1280
Pokitto 46:e7e438368e16 1281 //erase some pixels around the selected character
Pokitto 46:e7e438368e16 1282 display.setColor(WHITE);
Pokitto 46:e7e438368e16 1283 display.drawFastHLine(currentX + activeX * (display.fontWidth+1) - 1, currentY + activeY * (display.fontHeight+1) - 2, 7);
Pokitto 46:e7e438368e16 1284 //draw the selection rectangle
Pokitto 46:e7e438368e16 1285 display.setColor(BLACK);
Pokitto 46:e7e438368e16 1286 display.drawRoundRect(currentX + activeX * (display.fontWidth+1) - 2, currentY + activeY * (display.fontHeight+1) - 3, (display.fontWidth+2)+(display.fontWidth-1)%2, (display.fontHeight+5), 3);
Pokitto 46:e7e438368e16 1287 //draw keyboard outline
Pokitto 46:e7e438368e16 1288 //display.drawRoundRect(currentX - 6, currentY - 6, KEYBOARD_W * (display.fontWidth+1) + 12, KEYBOARD_H * (display.fontHeight+1) + 12, 8, BLACK);
Pokitto 46:e7e438368e16 1289 //text field
Pokitto 46:e7e438368e16 1290 display.drawFastHLine(0, LCDHEIGHT-display.fontHeight-2, LCDWIDTH);
Pokitto 46:e7e438368e16 1291 display.setColor(WHITE);
Pokitto 46:e7e438368e16 1292 display.fillRect(0, LCDHEIGHT-display.fontHeight-1, LCDWIDTH, display.fontHeight+1);
Pokitto 46:e7e438368e16 1293 //typed text
Pokitto 46:e7e438368e16 1294 display.cursorX = 0;
Pokitto 46:e7e438368e16 1295 display.cursorY = LCDHEIGHT-display.fontHeight;
Pokitto 46:e7e438368e16 1296 display.setColor(BLACK);
Pokitto 46:e7e438368e16 1297 display.print(text);
Pokitto 46:e7e438368e16 1298 //blinking cursor
Pokitto 46:e7e438368e16 1299 if (((frameCount % 8) < 4) && (activeChar < (length-1)))
Pokitto 46:e7e438368e16 1300 display.drawChar(display.fontWidth * activeChar, LCDHEIGHT-display.fontHeight, '_',1);
Pokitto 46:e7e438368e16 1301 }
Pokitto 46:e7e438368e16 1302 }
Pokitto 46:e7e438368e16 1303 #endif
Pokitto 46:e7e438368e16 1304 }
Pokitto 46:e7e438368e16 1305
Pokitto 46:e7e438368e16 1306 void Core::popup(const char* text, uint8_t duration){
Pokitto 46:e7e438368e16 1307 #if (ENABLE_GUI > 0)
Pokitto 46:e7e438368e16 1308 popupText = text;
Pokitto 46:e7e438368e16 1309 popupTimeLeft = duration+12;
Pokitto 46:e7e438368e16 1310 #endif
Pokitto 46:e7e438368e16 1311 }
Pokitto 46:e7e438368e16 1312
Pokitto 46:e7e438368e16 1313 void Core::updatePopup(){
Pokitto 46:e7e438368e16 1314 #if (ENABLE_GUI > 0)
Pokitto 46:e7e438368e16 1315 if (popupTimeLeft){
Pokitto 46:e7e438368e16 1316 uint8_t yOffset = 0;
Pokitto 46:e7e438368e16 1317 if(popupTimeLeft<12){
Pokitto 46:e7e438368e16 1318 yOffset = 12-popupTimeLeft;
Pokitto 46:e7e438368e16 1319 }
Pokitto 46:e7e438368e16 1320 display.fontSize = 1;
Pokitto 46:e7e438368e16 1321 display.setColor(WHITE);
Pokitto 46:e7e438368e16 1322 display.fillRoundRect(0,LCDHEIGHT-display.fontHeight+yOffset-3,84,display.fontHeight+3,3);
Pokitto 46:e7e438368e16 1323 display.setColor(BLACK);
Pokitto 46:e7e438368e16 1324 display.drawRoundRect(0,LCDHEIGHT-display.fontHeight+yOffset-3,84,display.fontHeight+3,3);
Pokitto 46:e7e438368e16 1325 display.cursorX = 4;
Pokitto 46:e7e438368e16 1326 display.cursorY = LCDHEIGHT-display.fontHeight+yOffset-1;
Pokitto 46:e7e438368e16 1327 display.print(popupText);
Pokitto 46:e7e438368e16 1328 popupTimeLeft--;
Pokitto 46:e7e438368e16 1329 }
Pokitto 46:e7e438368e16 1330 #endif
Pokitto 46:e7e438368e16 1331 }
Pokitto 46:e7e438368e16 1332
Pokitto 46:e7e438368e16 1333 void Core::setFrameRate(uint8_t fps) {
Pokitto 46:e7e438368e16 1334 timePerFrame = 1000 / fps;
Pokitto 46:e7e438368e16 1335 sound.prescaler = fps / 20;
Pokitto 46:e7e438368e16 1336 sound.prescaler = __avrmax(1, sound.prescaler);
Pokitto 46:e7e438368e16 1337 }
Pokitto 46:e7e438368e16 1338
Pokitto 46:e7e438368e16 1339 void Core::pickRandomSeed(){
Pokitto 46:e7e438368e16 1340 initRandom();
Pokitto 46:e7e438368e16 1341 }
Pokitto 46:e7e438368e16 1342
Pokitto 46:e7e438368e16 1343 bool Core::collidePointRect(int16_t x1, int16_t y1 ,int16_t x2 ,int16_t y2, int16_t w, int16_t h){
Pokitto 46:e7e438368e16 1344 if((x1>=x2)&&(x1<x2+w))
Pokitto 46:e7e438368e16 1345 if((y1>=y2)&&(y1<y2+h))
Pokitto 46:e7e438368e16 1346 return true;
Pokitto 46:e7e438368e16 1347 return false;
Pokitto 46:e7e438368e16 1348 }
Pokitto 46:e7e438368e16 1349
Pokitto 46:e7e438368e16 1350 bool Core::collideRectRect(int16_t x1, int16_t y1, int16_t w1, int16_t h1 ,int16_t x2 ,int16_t y2, int16_t w2, int16_t h2){
Pokitto 46:e7e438368e16 1351 return !( x2 >= x1+w1 ||
Pokitto 46:e7e438368e16 1352 x2+w2 <= x1 ||
Pokitto 46:e7e438368e16 1353 y2 >= y1+h1 ||
Pokitto 46:e7e438368e16 1354 y2+h2 <= y1 );
Pokitto 46:e7e438368e16 1355 }
Pokitto 46:e7e438368e16 1356
Pokitto 46:e7e438368e16 1357 bool Core::collideBitmapBitmap(int16_t x1, int16_t y1, const uint8_t* b1, int16_t x2, int16_t y2, const uint8_t* b2){
Pokitto 46:e7e438368e16 1358 int16_t w1 = pgm_read_byte(b1);
Pokitto 46:e7e438368e16 1359 int16_t h1 = pgm_read_byte(b1 + 1);
Pokitto 46:e7e438368e16 1360 int16_t w2 = pgm_read_byte(b2);
Pokitto 46:e7e438368e16 1361 int16_t h2 = pgm_read_byte(b2 + 1);
Pokitto 46:e7e438368e16 1362
Pokitto 46:e7e438368e16 1363 if(collideRectRect(x1, y1, w1, h1, x2, y2, w2, h2) == false){
Pokitto 46:e7e438368e16 1364 return false;
Pokitto 46:e7e438368e16 1365 }
Pokitto 46:e7e438368e16 1366
Pokitto 46:e7e438368e16 1367 int16_t xmin = (x1>=x2)? 0 : x2-x1;
Pokitto 46:e7e438368e16 1368 int16_t ymin = (y1>=y2)? 0 : y2-y1;
Pokitto 46:e7e438368e16 1369 int16_t xmax = (x1+w1>=x2+w2)? x2+w2-x1 : w1;
Pokitto 46:e7e438368e16 1370 int16_t ymax = (y1+h1>=y2+h2)? y2+h2-y1 : h1;
Pokitto 46:e7e438368e16 1371 for(uint8_t y = ymin; y < ymax; y++){
Pokitto 46:e7e438368e16 1372 for(uint8_t x = xmin; x < xmax; x++){
Pokitto 46:e7e438368e16 1373 if(display.getBitmapPixel(b1, x, y) && display.getBitmapPixel(b2, x1+x-x2, y1+y-y2)){
Pokitto 46:e7e438368e16 1374 return true;
Pokitto 46:e7e438368e16 1375 }
Pokitto 46:e7e438368e16 1376 }
Pokitto 46:e7e438368e16 1377 }
Pokitto 46:e7e438368e16 1378 return false;
Pokitto 46:e7e438368e16 1379 }
Pokitto 46:e7e438368e16 1380
Pokitto 46:e7e438368e16 1381
Pokitto 46:e7e438368e16 1382 //** EOF **//
Pokitto 46:e7e438368e16 1383
Pokitto 46:e7e438368e16 1384
Pokitto 46:e7e438368e16 1385
Pokitto 46:e7e438368e16 1386
Pokitto 46:e7e438368e16 1387
Pokitto 46:e7e438368e16 1388
Pokitto 46:e7e438368e16 1389
Pokitto 46:e7e438368e16 1390
Pokitto 46:e7e438368e16 1391