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