PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

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 Dec 25 23:59:52 2019 +0000
Revision:
71:531419862202
Parent:
68:61a4ccb0a4b6
Changed Mode2 C++ refresh code (graphical errors)

Who changed what in which revision?

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