Jonne Valola / PokittoLib Featured

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:
Fri Dec 29 02:55:34 2017 +0000
Revision:
22:e826f80d8582
Parent:
6:72f87b7c7400
PokittoLib with @Spinalcodes direct non-buffered tricks

Who changed what in which revision?

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