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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Wed Dec 25 23:59:52 2019 +0000
Revision:
71:531419862202
Parent:
31:f4b9b85c7b62
Changed Mode2 C++ refresh code (graphical errors)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 31:f4b9b85c7b62 1 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 2 /*!
Pokitto 31:f4b9b85c7b62 3 @file PokittoConsole.h
Pokitto 31:f4b9b85c7b62 4 @author Jonne Valola
Pokitto 31:f4b9b85c7b62 5
Pokitto 31:f4b9b85c7b62 6 @section LICENSE
Pokitto 31:f4b9b85c7b62 7
Pokitto 31:f4b9b85c7b62 8 Software License Agreement (BSD License)
Pokitto 31:f4b9b85c7b62 9
Pokitto 31:f4b9b85c7b62 10 Copyright (c) 2016, Jonne Valola
Pokitto 31:f4b9b85c7b62 11 All rights reserved.
Pokitto 31:f4b9b85c7b62 12
Pokitto 31:f4b9b85c7b62 13 Redistribution and use in source and binary forms, with or without
Pokitto 31:f4b9b85c7b62 14 modification, are permitted provided that the following conditions are met:
Pokitto 31:f4b9b85c7b62 15 1. Redistributions of source code must retain the above copyright
Pokitto 31:f4b9b85c7b62 16 notice, this list of conditions and the following disclaimer.
Pokitto 31:f4b9b85c7b62 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 31:f4b9b85c7b62 18 notice, this list of conditions and the following disclaimer in the
Pokitto 31:f4b9b85c7b62 19 documentation and/or other materials provided with the distribution.
Pokitto 31:f4b9b85c7b62 20 3. Neither the name of the copyright holders nor the
Pokitto 31:f4b9b85c7b62 21 names of its contributors may be used to endorse or promote products
Pokitto 31:f4b9b85c7b62 22 derived from this software without specific prior written permission.
Pokitto 31:f4b9b85c7b62 23
Pokitto 31:f4b9b85c7b62 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 31:f4b9b85c7b62 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 31:f4b9b85c7b62 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 31:f4b9b85c7b62 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 31:f4b9b85c7b62 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 31:f4b9b85c7b62 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 31:f4b9b85c7b62 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 31:f4b9b85c7b62 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 31:f4b9b85c7b62 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 31:f4b9b85c7b62 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 31:f4b9b85c7b62 34 */
Pokitto 31:f4b9b85c7b62 35 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 36
Pokitto 31:f4b9b85c7b62 37 #ifndef POKITTO_CONSOLE_H
Pokitto 31:f4b9b85c7b62 38 #define POKITTO_CONSOLE_H
Pokitto 31:f4b9b85c7b62 39
Pokitto 31:f4b9b85c7b62 40 #include "Pokitto_settings.h"
Pokitto 31:f4b9b85c7b62 41 #include "PokittoButtons.h"
Pokitto 31:f4b9b85c7b62 42 #include <stdint.h>
Pokitto 31:f4b9b85c7b62 43
Pokitto 31:f4b9b85c7b62 44 struct consmsg {
Pokitto 31:f4b9b85c7b62 45 uint32_t val;
Pokitto 31:f4b9b85c7b62 46 uint8_t valtype;
Pokitto 31:f4b9b85c7b62 47 uint8_t msgsource;
Pokitto 31:f4b9b85c7b62 48 uint8_t msgtype;
Pokitto 31:f4b9b85c7b62 49 };
Pokitto 31:f4b9b85c7b62 50
Pokitto 31:f4b9b85c7b62 51 /** VAL TYPES **/
Pokitto 31:f4b9b85c7b62 52 #define V_UINT8 0
Pokitto 31:f4b9b85c7b62 53 #define V_INT8 1
Pokitto 31:f4b9b85c7b62 54 #define V_UINT16 2
Pokitto 31:f4b9b85c7b62 55 #define V_INT16 3
Pokitto 31:f4b9b85c7b62 56 #define V_UINT32 4
Pokitto 31:f4b9b85c7b62 57 #define V_INT32 5
Pokitto 31:f4b9b85c7b62 58 #define V_FLOAT 6
Pokitto 31:f4b9b85c7b62 59 #define V_STRING 7
Pokitto 31:f4b9b85c7b62 60 #define V_NONE 8
Pokitto 31:f4b9b85c7b62 61
Pokitto 31:f4b9b85c7b62 62 /** MESSAGE TYPE **/
Pokitto 31:f4b9b85c7b62 63 #define MSG_NULL 0
Pokitto 31:f4b9b85c7b62 64 #define MSG_OK 1
Pokitto 31:f4b9b85c7b62 65 #define MSG_WARNING 2
Pokitto 31:f4b9b85c7b62 66 #define MSG_FATAL 255
Pokitto 31:f4b9b85c7b62 67 #define MSG_INIT_OK 3
Pokitto 31:f4b9b85c7b62 68 #define MSG_INIT_FAIL 4
Pokitto 31:f4b9b85c7b62 69 #define MSG_NOT_ENOUGH_MEM 5
Pokitto 31:f4b9b85c7b62 70 #define MSG_GFX_MODE_CHANGE 6
Pokitto 31:f4b9b85c7b62 71 #define MSG_GFX_MODE_INVALID 7
Pokitto 31:f4b9b85c7b62 72 #define MSG_UP 8
Pokitto 31:f4b9b85c7b62 73 #define MSG_DOWN 9
Pokitto 31:f4b9b85c7b62 74 #define MSG_PRINT 10
Pokitto 31:f4b9b85c7b62 75 #define MSG_BREAK 11
Pokitto 31:f4b9b85c7b62 76 #define MSG_YESNO 12
Pokitto 31:f4b9b85c7b62 77 #define MSG_YES 13
Pokitto 31:f4b9b85c7b62 78 #define MSG_NO 14
Pokitto 31:f4b9b85c7b62 79 #define MSG_OBJECT 15
Pokitto 31:f4b9b85c7b62 80 #define MSG_OBJECT2 16
Pokitto 31:f4b9b85c7b62 81
Pokitto 31:f4b9b85c7b62 82 /** MESSAGE SOURCE **/
Pokitto 31:f4b9b85c7b62 83 #define MSOURCE_NULL 0
Pokitto 31:f4b9b85c7b62 84 #define MSOURCE_SD 1
Pokitto 31:f4b9b85c7b62 85 #define MSOURCE_LCD 2
Pokitto 31:f4b9b85c7b62 86 #define MSOURCE_SOUND 3
Pokitto 31:f4b9b85c7b62 87 #define MSOURCE_TIMER 4
Pokitto 31:f4b9b85c7b62 88 #define MSOURCE_BTNA 5
Pokitto 31:f4b9b85c7b62 89 #define MSOURCE_BTNB 6
Pokitto 31:f4b9b85c7b62 90 #define MSOURCE_BTNC 7
Pokitto 31:f4b9b85c7b62 91 #define MSOURCE_BTNU 8
Pokitto 31:f4b9b85c7b62 92 #define MSOURCE_BTND 9
Pokitto 31:f4b9b85c7b62 93 #define MSOURCE_BTNL 10
Pokitto 31:f4b9b85c7b62 94 #define MSOURCE_BTNR 11
Pokitto 31:f4b9b85c7b62 95 #define MSOURCE_BATT 12
Pokitto 31:f4b9b85c7b62 96 #define MSOURCE_APP 13
Pokitto 31:f4b9b85c7b62 97 #define MSOURCE_USER 14
Pokitto 31:f4b9b85c7b62 98 #define MSOURCE_COLLISION 15
Pokitto 31:f4b9b85c7b62 99
Pokitto 31:f4b9b85c7b62 100 /** CONSOLE MODES **/
Pokitto 31:f4b9b85c7b62 101 #define CONS_OVERLAY 0x1
Pokitto 31:f4b9b85c7b62 102 #define CONS_PAUSE 0x2
Pokitto 31:f4b9b85c7b62 103 #define CONS_STEP 0x4
Pokitto 31:f4b9b85c7b62 104 #define CONS_VISIBLE 0x8
Pokitto 31:f4b9b85c7b62 105
Pokitto 31:f4b9b85c7b62 106
Pokitto 31:f4b9b85c7b62 107 /** CONSOLE DEBOUNCE **/
Pokitto 31:f4b9b85c7b62 108 #define CONS_TIMEOUT 20
Pokitto 31:f4b9b85c7b62 109 extern uint16_t conscounter;
Pokitto 31:f4b9b85c7b62 110
Pokitto 31:f4b9b85c7b62 111
Pokitto 31:f4b9b85c7b62 112
Pokitto 31:f4b9b85c7b62 113 namespace Pokitto {
Pokitto 31:f4b9b85c7b62 114
Pokitto 31:f4b9b85c7b62 115 class Display;
Pokitto 31:f4b9b85c7b62 116
Pokitto 31:f4b9b85c7b62 117 class Console {
Pokitto 31:f4b9b85c7b62 118 public:
Pokitto 31:f4b9b85c7b62 119 /** Console class constructor */
Pokitto 31:f4b9b85c7b62 120 Console();
Pokitto 31:f4b9b85c7b62 121
Pokitto 31:f4b9b85c7b62 122 static uint8_t mode;
Pokitto 31:f4b9b85c7b62 123 static uint8_t visible;
Pokitto 31:f4b9b85c7b62 124 static unsigned char* font;
Pokitto 31:f4b9b85c7b62 125 static void Toggle();
Pokitto 31:f4b9b85c7b62 126 static void AddMessage(uint8_t, uint8_t, uint8_t, uint32_t);
Pokitto 31:f4b9b85c7b62 127 static void AddMessage(uint8_t, uint8_t);
Pokitto 31:f4b9b85c7b62 128 static void AddMessage(uint8_t, char*);
Pokitto 31:f4b9b85c7b62 129 static void AddMessage(uint8_t, uint8_t, uint32_t);
Pokitto 31:f4b9b85c7b62 130 static void Last();
Pokitto 31:f4b9b85c7b62 131 static void First();
Pokitto 31:f4b9b85c7b62 132 static void RemoveLast();
Pokitto 31:f4b9b85c7b62 133 static void Previous();
Pokitto 31:f4b9b85c7b62 134 static void Next();
Pokitto 31:f4b9b85c7b62 135 static consmsg GetMessage();
Pokitto 31:f4b9b85c7b62 136 static void PrintMessage();
Pokitto 31:f4b9b85c7b62 137 static void Purge();
Pokitto 31:f4b9b85c7b62 138 static void Draw(); // pokConsole
Pokitto 31:f4b9b85c7b62 139
Pokitto 31:f4b9b85c7b62 140 private:
Pokitto 31:f4b9b85c7b62 141 /** Message buffer */
Pokitto 31:f4b9b85c7b62 142 static consmsg msgbuf[CONSOLEBUFSIZE];
Pokitto 31:f4b9b85c7b62 143 static uint8_t conslast;
Pokitto 31:f4b9b85c7b62 144 static uint8_t consfirst;
Pokitto 31:f4b9b85c7b62 145 static uint8_t conspointer;
Pokitto 31:f4b9b85c7b62 146 public:
Pokitto 31:f4b9b85c7b62 147 static uint16_t conscounter;
Pokitto 31:f4b9b85c7b62 148 static uint16_t color;
Pokitto 31:f4b9b85c7b62 149 static Display* _display;
Pokitto 31:f4b9b85c7b62 150 static Buttons* _buttons;
Pokitto 31:f4b9b85c7b62 151 };
Pokitto 31:f4b9b85c7b62 152
Pokitto 31:f4b9b85c7b62 153
Pokitto 31:f4b9b85c7b62 154 } // namespace
Pokitto 31:f4b9b85c7b62 155
Pokitto 31:f4b9b85c7b62 156 // this is the console used by the core if POK_USE_CONSOLE is nonzero
Pokitto 31:f4b9b85c7b62 157 extern Pokitto::Console console;
Pokitto 31:f4b9b85c7b62 158
Pokitto 31:f4b9b85c7b62 159 #endif // POKITTO_CONSOLE_H
Pokitto 31:f4b9b85c7b62 160
Pokitto 31:f4b9b85c7b62 161