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/PokittoConsole.h@28:958b71c4b92a, 2018-01-05 (annotated)
- Committer:
- Pokitto
- Date:
- Fri Jan 05 02:19:51 2018 +0000
- Revision:
- 28:958b71c4b92a
- Parent:
- 0:e8b8f36b4505
Sound level stored in EEPROM, sound output improved
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 PokittoConsole.h |
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 | #ifndef POKITTO_CONSOLE_H |
Pokitto | 0:e8b8f36b4505 | 38 | #define POKITTO_CONSOLE_H |
Pokitto | 0:e8b8f36b4505 | 39 | |
Pokitto | 0:e8b8f36b4505 | 40 | #include "Pokitto_settings.h" |
Pokitto | 0:e8b8f36b4505 | 41 | #include "PokittoButtons.h" |
Pokitto | 0:e8b8f36b4505 | 42 | #include <stdint.h> |
Pokitto | 0:e8b8f36b4505 | 43 | |
Pokitto | 0:e8b8f36b4505 | 44 | struct consmsg { |
Pokitto | 0:e8b8f36b4505 | 45 | uint32_t val; |
Pokitto | 0:e8b8f36b4505 | 46 | uint8_t valtype; |
Pokitto | 0:e8b8f36b4505 | 47 | uint8_t msgsource; |
Pokitto | 0:e8b8f36b4505 | 48 | uint8_t msgtype; |
Pokitto | 0:e8b8f36b4505 | 49 | }; |
Pokitto | 0:e8b8f36b4505 | 50 | |
Pokitto | 0:e8b8f36b4505 | 51 | /** VAL TYPES **/ |
Pokitto | 0:e8b8f36b4505 | 52 | #define V_UINT8 0 |
Pokitto | 0:e8b8f36b4505 | 53 | #define V_INT8 1 |
Pokitto | 0:e8b8f36b4505 | 54 | #define V_UINT16 2 |
Pokitto | 0:e8b8f36b4505 | 55 | #define V_INT16 3 |
Pokitto | 0:e8b8f36b4505 | 56 | #define V_UINT32 4 |
Pokitto | 0:e8b8f36b4505 | 57 | #define V_INT32 5 |
Pokitto | 0:e8b8f36b4505 | 58 | #define V_FLOAT 6 |
Pokitto | 0:e8b8f36b4505 | 59 | #define V_STRING 7 |
Pokitto | 0:e8b8f36b4505 | 60 | #define V_NONE 8 |
Pokitto | 0:e8b8f36b4505 | 61 | |
Pokitto | 0:e8b8f36b4505 | 62 | /** MESSAGE TYPE **/ |
Pokitto | 0:e8b8f36b4505 | 63 | #define MSG_NULL 0 |
Pokitto | 0:e8b8f36b4505 | 64 | #define MSG_OK 1 |
Pokitto | 0:e8b8f36b4505 | 65 | #define MSG_WARNING 2 |
Pokitto | 0:e8b8f36b4505 | 66 | #define MSG_FATAL 255 |
Pokitto | 0:e8b8f36b4505 | 67 | #define MSG_INIT_OK 3 |
Pokitto | 0:e8b8f36b4505 | 68 | #define MSG_INIT_FAIL 4 |
Pokitto | 0:e8b8f36b4505 | 69 | #define MSG_NOT_ENOUGH_MEM 5 |
Pokitto | 0:e8b8f36b4505 | 70 | #define MSG_GFX_MODE_CHANGE 6 |
Pokitto | 0:e8b8f36b4505 | 71 | #define MSG_GFX_MODE_INVALID 7 |
Pokitto | 0:e8b8f36b4505 | 72 | #define MSG_UP 8 |
Pokitto | 0:e8b8f36b4505 | 73 | #define MSG_DOWN 9 |
Pokitto | 0:e8b8f36b4505 | 74 | #define MSG_PRINT 10 |
Pokitto | 0:e8b8f36b4505 | 75 | #define MSG_BREAK 11 |
Pokitto | 0:e8b8f36b4505 | 76 | #define MSG_YESNO 12 |
Pokitto | 0:e8b8f36b4505 | 77 | #define MSG_YES 13 |
Pokitto | 0:e8b8f36b4505 | 78 | #define MSG_NO 14 |
Pokitto | 0:e8b8f36b4505 | 79 | #define MSG_OBJECT 15 |
Pokitto | 0:e8b8f36b4505 | 80 | #define MSG_OBJECT2 16 |
Pokitto | 0:e8b8f36b4505 | 81 | |
Pokitto | 0:e8b8f36b4505 | 82 | /** MESSAGE SOURCE **/ |
Pokitto | 0:e8b8f36b4505 | 83 | #define MSOURCE_NULL 0 |
Pokitto | 0:e8b8f36b4505 | 84 | #define MSOURCE_SD 1 |
Pokitto | 0:e8b8f36b4505 | 85 | #define MSOURCE_LCD 2 |
Pokitto | 0:e8b8f36b4505 | 86 | #define MSOURCE_SOUND 3 |
Pokitto | 0:e8b8f36b4505 | 87 | #define MSOURCE_TIMER 4 |
Pokitto | 0:e8b8f36b4505 | 88 | #define MSOURCE_BTNA 5 |
Pokitto | 0:e8b8f36b4505 | 89 | #define MSOURCE_BTNB 6 |
Pokitto | 0:e8b8f36b4505 | 90 | #define MSOURCE_BTNC 7 |
Pokitto | 0:e8b8f36b4505 | 91 | #define MSOURCE_BTNU 8 |
Pokitto | 0:e8b8f36b4505 | 92 | #define MSOURCE_BTND 9 |
Pokitto | 0:e8b8f36b4505 | 93 | #define MSOURCE_BTNL 10 |
Pokitto | 0:e8b8f36b4505 | 94 | #define MSOURCE_BTNR 11 |
Pokitto | 0:e8b8f36b4505 | 95 | #define MSOURCE_BATT 12 |
Pokitto | 0:e8b8f36b4505 | 96 | #define MSOURCE_APP 13 |
Pokitto | 0:e8b8f36b4505 | 97 | #define MSOURCE_USER 14 |
Pokitto | 0:e8b8f36b4505 | 98 | #define MSOURCE_COLLISION 15 |
Pokitto | 0:e8b8f36b4505 | 99 | |
Pokitto | 0:e8b8f36b4505 | 100 | /** CONSOLE MODES **/ |
Pokitto | 0:e8b8f36b4505 | 101 | #define CONS_OVERLAY 0x1 |
Pokitto | 0:e8b8f36b4505 | 102 | #define CONS_PAUSE 0x2 |
Pokitto | 0:e8b8f36b4505 | 103 | #define CONS_STEP 0x4 |
Pokitto | 0:e8b8f36b4505 | 104 | #define CONS_VISIBLE 0x8 |
Pokitto | 0:e8b8f36b4505 | 105 | |
Pokitto | 0:e8b8f36b4505 | 106 | |
Pokitto | 0:e8b8f36b4505 | 107 | /** CONSOLE DEBOUNCE **/ |
Pokitto | 0:e8b8f36b4505 | 108 | #define CONS_TIMEOUT 20 |
Pokitto | 0:e8b8f36b4505 | 109 | extern uint16_t conscounter; |
Pokitto | 0:e8b8f36b4505 | 110 | |
Pokitto | 0:e8b8f36b4505 | 111 | |
Pokitto | 0:e8b8f36b4505 | 112 | |
Pokitto | 0:e8b8f36b4505 | 113 | namespace Pokitto { |
Pokitto | 0:e8b8f36b4505 | 114 | |
Pokitto | 0:e8b8f36b4505 | 115 | class Display; |
Pokitto | 0:e8b8f36b4505 | 116 | |
Pokitto | 0:e8b8f36b4505 | 117 | class Console { |
Pokitto | 0:e8b8f36b4505 | 118 | public: |
Pokitto | 0:e8b8f36b4505 | 119 | /** Console class constructor */ |
Pokitto | 0:e8b8f36b4505 | 120 | Console(); |
Pokitto | 0:e8b8f36b4505 | 121 | |
Pokitto | 0:e8b8f36b4505 | 122 | static uint8_t mode; |
Pokitto | 0:e8b8f36b4505 | 123 | static uint8_t visible; |
Pokitto | 0:e8b8f36b4505 | 124 | static unsigned char* font; |
Pokitto | 0:e8b8f36b4505 | 125 | static void Toggle(); |
Pokitto | 0:e8b8f36b4505 | 126 | static void AddMessage(uint8_t, uint8_t, uint8_t, uint32_t); |
Pokitto | 0:e8b8f36b4505 | 127 | static void AddMessage(uint8_t, uint8_t); |
Pokitto | 0:e8b8f36b4505 | 128 | static void AddMessage(uint8_t, char*); |
Pokitto | 0:e8b8f36b4505 | 129 | static void AddMessage(uint8_t, uint8_t, uint32_t); |
Pokitto | 0:e8b8f36b4505 | 130 | static void Last(); |
Pokitto | 0:e8b8f36b4505 | 131 | static void First(); |
Pokitto | 0:e8b8f36b4505 | 132 | static void RemoveLast(); |
Pokitto | 0:e8b8f36b4505 | 133 | static void Previous(); |
Pokitto | 0:e8b8f36b4505 | 134 | static void Next(); |
Pokitto | 0:e8b8f36b4505 | 135 | static consmsg GetMessage(); |
Pokitto | 0:e8b8f36b4505 | 136 | static void PrintMessage(); |
Pokitto | 0:e8b8f36b4505 | 137 | static void Purge(); |
Pokitto | 0:e8b8f36b4505 | 138 | static void Draw(); // pokConsole |
Pokitto | 0:e8b8f36b4505 | 139 | |
Pokitto | 0:e8b8f36b4505 | 140 | private: |
Pokitto | 0:e8b8f36b4505 | 141 | /** Message buffer */ |
Pokitto | 0:e8b8f36b4505 | 142 | static consmsg msgbuf[CONSOLEBUFSIZE]; |
Pokitto | 0:e8b8f36b4505 | 143 | static uint8_t conslast; |
Pokitto | 0:e8b8f36b4505 | 144 | static uint8_t consfirst; |
Pokitto | 0:e8b8f36b4505 | 145 | static uint8_t conspointer; |
Pokitto | 0:e8b8f36b4505 | 146 | public: |
Pokitto | 0:e8b8f36b4505 | 147 | static uint16_t conscounter; |
Pokitto | 0:e8b8f36b4505 | 148 | static uint16_t color; |
Pokitto | 0:e8b8f36b4505 | 149 | static Display* _display; |
Pokitto | 0:e8b8f36b4505 | 150 | static Buttons* _buttons; |
Pokitto | 0:e8b8f36b4505 | 151 | }; |
Pokitto | 0:e8b8f36b4505 | 152 | |
Pokitto | 0:e8b8f36b4505 | 153 | |
Pokitto | 0:e8b8f36b4505 | 154 | } // namespace |
Pokitto | 0:e8b8f36b4505 | 155 | |
Pokitto | 0:e8b8f36b4505 | 156 | // this is the console used by the core if POK_USE_CONSOLE is nonzero |
Pokitto | 0:e8b8f36b4505 | 157 | extern Pokitto::Console console; |
Pokitto | 0:e8b8f36b4505 | 158 | |
Pokitto | 0:e8b8f36b4505 | 159 | #endif // POKITTO_CONSOLE_H |
Pokitto | 0:e8b8f36b4505 | 160 |