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

Committer:
Pokitto
Date:
Fri Dec 29 05:17:38 2017 +0000
Revision:
24:9561281d0378
PokittoLib synced with Github and all Spianl & Hanski contributions so far

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 24:9561281d0378 1 /**************************************************************************/
Pokitto 24:9561281d0378 2 /*!
Pokitto 24:9561281d0378 3 @file HWButtons.cpp
Pokitto 24:9561281d0378 4 @author Jonne Valola
Pokitto 24:9561281d0378 5
Pokitto 24:9561281d0378 6 @section LICENSE
Pokitto 24:9561281d0378 7
Pokitto 24:9561281d0378 8 Software License Agreement (BSD License)
Pokitto 24:9561281d0378 9
Pokitto 24:9561281d0378 10 Copyright (c) 2016, Jonne Valola
Pokitto 24:9561281d0378 11 All rights reserved.
Pokitto 24:9561281d0378 12
Pokitto 24:9561281d0378 13 Redistribution and use in source and binary forms, with or without
Pokitto 24:9561281d0378 14 modification, are permitted provided that the following conditions are met:
Pokitto 24:9561281d0378 15 1. Redistributions of source code must retain the above copyright
Pokitto 24:9561281d0378 16 notice, this list of conditions and the following disclaimer.
Pokitto 24:9561281d0378 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 24:9561281d0378 18 notice, this list of conditions and the following disclaimer in the
Pokitto 24:9561281d0378 19 documentation and/or other materials provided with the distribution.
Pokitto 24:9561281d0378 20 3. Neither the name of the copyright holders nor the
Pokitto 24:9561281d0378 21 names of its contributors may be used to endorse or promote products
Pokitto 24:9561281d0378 22 derived from this software without specific prior written permission.
Pokitto 24:9561281d0378 23
Pokitto 24:9561281d0378 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 24:9561281d0378 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 24:9561281d0378 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 24:9561281d0378 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 24:9561281d0378 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 24:9561281d0378 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 24:9561281d0378 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 24:9561281d0378 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 24:9561281d0378 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 24:9561281d0378 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 24:9561281d0378 34 */
Pokitto 24:9561281d0378 35 /**************************************************************************/
Pokitto 24:9561281d0378 36
Pokitto 24:9561281d0378 37 #include "HWButtons.h"
Pokitto 24:9561281d0378 38 #include "PokittoCore.h"
Pokitto 24:9561281d0378 39 #include "PokittoSound.h"
Pokitto 24:9561281d0378 40 #include "PokittoDisplay.h"
Pokitto 24:9561281d0378 41
Pokitto 24:9561281d0378 42 Pokitto::Sound _s;
Pokitto 24:9561281d0378 43 Pokitto::Display _bd;
Pokitto 24:9561281d0378 44
Pokitto 24:9561281d0378 45 using namespace mbed;
Pokitto 24:9561281d0378 46
Pokitto 24:9561281d0378 47 InterruptIn ABtn(POK_BTN_A_PIN);
Pokitto 24:9561281d0378 48 InterruptIn BBtn(POK_BTN_B_PIN);
Pokitto 24:9561281d0378 49 InterruptIn CBtn(POK_BTN_C_PIN);
Pokitto 24:9561281d0378 50 InterruptIn UBtn(POK_BTN_UP_PIN);
Pokitto 24:9561281d0378 51 InterruptIn DBtn(POK_BTN_DOWN_PIN);
Pokitto 24:9561281d0378 52 InterruptIn LBtn(POK_BTN_LEFT_PIN);
Pokitto 24:9561281d0378 53 InterruptIn RBtn(POK_BTN_RIGHT_PIN);
Pokitto 24:9561281d0378 54
Pokitto 24:9561281d0378 55 #define BS_IDLE 0
Pokitto 24:9561281d0378 56 #define BS_DOWN 1
Pokitto 24:9561281d0378 57 #define BS_UP 2
Pokitto 24:9561281d0378 58
Pokitto 24:9561281d0378 59 uint8_t Pokitto::heldStates[NUM_BTN];
Pokitto 24:9561281d0378 60
Pokitto 24:9561281d0378 61 void APressed() { Pokitto::heldStates[BTN_A] = 1; }
Pokitto 24:9561281d0378 62 void AReleased() { Pokitto::heldStates[BTN_A] = 0; }
Pokitto 24:9561281d0378 63 void BPressed() { Pokitto::heldStates[BTN_B] = 1; }
Pokitto 24:9561281d0378 64 void BReleased() { Pokitto::heldStates[BTN_B] = 0; }
Pokitto 24:9561281d0378 65 void CPressed() {
Pokitto 24:9561281d0378 66 Pokitto::heldStates[BTN_C] = 1;
Pokitto 24:9561281d0378 67 }
Pokitto 24:9561281d0378 68 void CReleased() { Pokitto::heldStates[BTN_C] = 0; }
Pokitto 24:9561281d0378 69 void UPressed() { Pokitto::heldStates[BTN_UP] = 1; }
Pokitto 24:9561281d0378 70 void UReleased() { Pokitto::heldStates[BTN_UP] = 0; }
Pokitto 24:9561281d0378 71 void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; }
Pokitto 24:9561281d0378 72 void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; }
Pokitto 24:9561281d0378 73 void RPressed() {
Pokitto 24:9561281d0378 74 /* Hardware volume control */
Pokitto 24:9561281d0378 75 if (Pokitto::heldStates[BTN_C]) _s.volumeUp();
Pokitto 24:9561281d0378 76 else Pokitto::heldStates[BTN_RIGHT] = 1;
Pokitto 24:9561281d0378 77 }
Pokitto 24:9561281d0378 78 void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; }
Pokitto 24:9561281d0378 79 void LPressed() {
Pokitto 24:9561281d0378 80 /* Hardware volume control */
Pokitto 24:9561281d0378 81 if (Pokitto::heldStates[BTN_C]) _s.volumeDown();
Pokitto 24:9561281d0378 82 else Pokitto::heldStates[BTN_LEFT] = 1;
Pokitto 24:9561281d0378 83 }
Pokitto 24:9561281d0378 84 void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; }
Pokitto 24:9561281d0378 85
Pokitto 24:9561281d0378 86 void Pokitto::initButtons() {
Pokitto 24:9561281d0378 87 ABtn.fall(&AReleased);
Pokitto 24:9561281d0378 88 ABtn.rise(&APressed);
Pokitto 24:9561281d0378 89 BBtn.fall(&BReleased);
Pokitto 24:9561281d0378 90 BBtn.rise(&BPressed);
Pokitto 24:9561281d0378 91 CBtn.fall(&CReleased);
Pokitto 24:9561281d0378 92 CBtn.rise(&CPressed);
Pokitto 24:9561281d0378 93 UBtn.fall(&UReleased);
Pokitto 24:9561281d0378 94 UBtn.rise(&UPressed);
Pokitto 24:9561281d0378 95 DBtn.fall(&DReleased);
Pokitto 24:9561281d0378 96 DBtn.rise(&DPressed);
Pokitto 24:9561281d0378 97 LBtn.fall(&LReleased);
Pokitto 24:9561281d0378 98 LBtn.rise(&LPressed);
Pokitto 24:9561281d0378 99 RBtn.fall(&RReleased);
Pokitto 24:9561281d0378 100 RBtn.rise(&RPressed);
Pokitto 24:9561281d0378 101 }
Pokitto 24:9561281d0378 102
Pokitto 24:9561281d0378 103 uint8_t Pokitto::Core::aBtn() {
Pokitto 24:9561281d0378 104 return Pokitto::heldStates[BTN_A];
Pokitto 24:9561281d0378 105 }
Pokitto 24:9561281d0378 106
Pokitto 24:9561281d0378 107 uint8_t Pokitto::Core::bBtn() {
Pokitto 24:9561281d0378 108 return Pokitto::heldStates[BTN_B];
Pokitto 24:9561281d0378 109 }
Pokitto 24:9561281d0378 110
Pokitto 24:9561281d0378 111 uint8_t Pokitto::Core::cBtn() {
Pokitto 24:9561281d0378 112 return Pokitto::heldStates[BTN_C];
Pokitto 24:9561281d0378 113 }
Pokitto 24:9561281d0378 114
Pokitto 24:9561281d0378 115 uint8_t Pokitto::Core::upBtn() {
Pokitto 24:9561281d0378 116 return Pokitto::heldStates[BTN_UP];
Pokitto 24:9561281d0378 117 }
Pokitto 24:9561281d0378 118 uint8_t Pokitto::Core::downBtn() {
Pokitto 24:9561281d0378 119 return Pokitto::heldStates[BTN_DOWN];
Pokitto 24:9561281d0378 120 }
Pokitto 24:9561281d0378 121
Pokitto 24:9561281d0378 122 uint8_t Pokitto::Core::leftBtn() {
Pokitto 24:9561281d0378 123 return Pokitto::heldStates[BTN_LEFT];
Pokitto 24:9561281d0378 124 }
Pokitto 24:9561281d0378 125 uint8_t Pokitto::Core::rightBtn() {
Pokitto 24:9561281d0378 126 return Pokitto::heldStates[BTN_RIGHT];
Pokitto 24:9561281d0378 127 }
Pokitto 24:9561281d0378 128
Pokitto 24:9561281d0378 129