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

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
31:f4b9b85c7b62
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 31:f4b9b85c7b62 1 /**************************************************************************/
Pokitto 31:f4b9b85c7b62 2 /*!
Pokitto 31:f4b9b85c7b62 3 @file PokittoButtons.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
Pokitto 31:f4b9b85c7b62 38 #ifndef POKITTOBUTTONS_H
Pokitto 31:f4b9b85c7b62 39 #define POKITTOBUTTONS_H
Pokitto 31:f4b9b85c7b62 40
Pokitto 31:f4b9b85c7b62 41 #include <stdint.h>
Pokitto 31:f4b9b85c7b62 42 #include "Pokitto_settings.h"
Pokitto 31:f4b9b85c7b62 43 #include "GBcompatibility.h"
Pokitto 31:f4b9b85c7b62 44 #include "PokittoGlobs.h"
Pokitto 31:f4b9b85c7b62 45
Pokitto 31:f4b9b85c7b62 46 #ifndef POK_SIM
Pokitto 31:f4b9b85c7b62 47 #include "HWButtons.h"
Pokitto 31:f4b9b85c7b62 48 #define CHWLONGPRESSTIMEOUT 100
Pokitto 31:f4b9b85c7b62 49 #else
Pokitto 31:f4b9b85c7b62 50 #include "PokittoSimulator.h"
Pokitto 31:f4b9b85c7b62 51 #define CHWLONGPRESSTIMEOUT 1000
Pokitto 31:f4b9b85c7b62 52 #endif // POK_SIM
Pokitto 31:f4b9b85c7b62 53
Pokitto 31:f4b9b85c7b62 54
Pokitto 31:f4b9b85c7b62 55 namespace Pokitto {
Pokitto 31:f4b9b85c7b62 56
Pokitto 31:f4b9b85c7b62 57 class Buttons {
Pokitto 31:f4b9b85c7b62 58 public:
Pokitto 31:f4b9b85c7b62 59 // Original functions
Pokitto 31:f4b9b85c7b62 60 static uint8_t buttons_state, buttons_held, buttons_released;
Pokitto 31:f4b9b85c7b62 61 static void initButtons();
Pokitto 31:f4b9b85c7b62 62 static void pollButtons();
Pokitto 31:f4b9b85c7b62 63 static uint8_t leftBtn();
Pokitto 31:f4b9b85c7b62 64 static uint8_t rightBtn();
Pokitto 31:f4b9b85c7b62 65 static uint8_t upBtn();
Pokitto 31:f4b9b85c7b62 66 static uint8_t downBtn();
Pokitto 31:f4b9b85c7b62 67 static uint8_t aBtn();
Pokitto 31:f4b9b85c7b62 68 static uint8_t bBtn();
Pokitto 31:f4b9b85c7b62 69 static uint8_t cBtn();
Pokitto 31:f4b9b85c7b62 70 static uint8_t leftHeld();
Pokitto 31:f4b9b85c7b62 71 static uint8_t rightHeld();
Pokitto 31:f4b9b85c7b62 72 static uint8_t upHeld();
Pokitto 31:f4b9b85c7b62 73 static uint8_t downHeld();
Pokitto 31:f4b9b85c7b62 74 static uint8_t aHeld();
Pokitto 31:f4b9b85c7b62 75 static uint8_t bHeld();
Pokitto 31:f4b9b85c7b62 76 static uint8_t cHeld();
Pokitto 31:f4b9b85c7b62 77
Pokitto 31:f4b9b85c7b62 78 static uint8_t leftReleased();
Pokitto 31:f4b9b85c7b62 79 static uint8_t rightReleased();
Pokitto 31:f4b9b85c7b62 80 static uint8_t upReleased();
Pokitto 31:f4b9b85c7b62 81 static uint8_t downReleased();
Pokitto 31:f4b9b85c7b62 82 static uint8_t aReleased();
Pokitto 31:f4b9b85c7b62 83 static uint8_t bReleased();
Pokitto 31:f4b9b85c7b62 84 static uint8_t cReleased();
Pokitto 31:f4b9b85c7b62 85
Pokitto 31:f4b9b85c7b62 86 // GB compatibility functions
Pokitto 31:f4b9b85c7b62 87 static void begin();
Pokitto 31:f4b9b85c7b62 88 static void update();
Pokitto 31:f4b9b85c7b62 89 static bool pressed(uint8_t button);
Pokitto 31:f4b9b85c7b62 90 static bool released(uint8_t button);
Pokitto 31:f4b9b85c7b62 91 static bool held(uint8_t button, uint8_t time);
Pokitto 31:f4b9b85c7b62 92 static bool repeat(uint8_t button, uint8_t period);
Pokitto 31:f4b9b85c7b62 93 static uint8_t timeHeld(uint8_t button);
Pokitto 31:f4b9b85c7b62 94 static uint8_t pins[NUM_BTN];
Pokitto 31:f4b9b85c7b62 95 static uint8_t states[NUM_BTN];
Pokitto 31:f4b9b85c7b62 96 static uint8_t heldStates[NUM_BTN]; // additional, not GB based
Pokitto 31:f4b9b85c7b62 97 private:
Pokitto 31:f4b9b85c7b62 98 static uint16_t cHWLongPress; //forced hardware detection of C long press
Pokitto 31:f4b9b85c7b62 99 };
Pokitto 31:f4b9b85c7b62 100
Pokitto 31:f4b9b85c7b62 101 }
Pokitto 31:f4b9b85c7b62 102
Pokitto 31:f4b9b85c7b62 103 #endif // POKITTOBUTTONS_H
Pokitto 31:f4b9b85c7b62 104
Pokitto 31:f4b9b85c7b62 105
Pokitto 31:f4b9b85c7b62 106
Pokitto 31:f4b9b85c7b62 107
Pokitto 31:f4b9b85c7b62 108
Pokitto 31:f4b9b85c7b62 109
Pokitto 31:f4b9b85c7b62 110