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

Committer:
Pokitto
Date:
Tue May 01 18:42:46 2018 +0000
Revision:
42:798b5d67b372
Parent:
36:771321e70814
Child:
44:2b8560b11eab
New volume control;

Who changed what in which revision?

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