Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Pokitto by
POKITTO_HW/HWButtons.cpp@0:e8b8f36b4505, 2017-09-18 (annotated)
- Committer:
- Pokitto
- Date:
- Mon Sep 18 11:47:51 2017 +0000
- Revision:
- 0:e8b8f36b4505
- Child:
- 2:968589ca3484
Initial;
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 HWButtons.cpp |
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 | #include "HWButtons.h" |
Pokitto | 0:e8b8f36b4505 | 38 | #include "PokittoCore.h" |
Pokitto | 0:e8b8f36b4505 | 39 | #include "PokittoSound.h" |
Pokitto | 0:e8b8f36b4505 | 40 | |
Pokitto | 0:e8b8f36b4505 | 41 | Pokitto::Sound _s; |
Pokitto | 0:e8b8f36b4505 | 42 | |
Pokitto | 0:e8b8f36b4505 | 43 | using namespace mbed; |
Pokitto | 0:e8b8f36b4505 | 44 | |
Pokitto | 0:e8b8f36b4505 | 45 | InterruptIn ABtn(POK_BTN_A_PIN); |
Pokitto | 0:e8b8f36b4505 | 46 | InterruptIn BBtn(POK_BTN_B_PIN); |
Pokitto | 0:e8b8f36b4505 | 47 | InterruptIn CBtn(POK_BTN_C_PIN); |
Pokitto | 0:e8b8f36b4505 | 48 | InterruptIn UBtn(POK_BTN_UP_PIN); |
Pokitto | 0:e8b8f36b4505 | 49 | InterruptIn DBtn(POK_BTN_DOWN_PIN); |
Pokitto | 0:e8b8f36b4505 | 50 | InterruptIn LBtn(POK_BTN_LEFT_PIN); |
Pokitto | 0:e8b8f36b4505 | 51 | InterruptIn RBtn(POK_BTN_RIGHT_PIN); |
Pokitto | 0:e8b8f36b4505 | 52 | |
Pokitto | 0:e8b8f36b4505 | 53 | #define BS_IDLE 0 |
Pokitto | 0:e8b8f36b4505 | 54 | #define BS_DOWN 1 |
Pokitto | 0:e8b8f36b4505 | 55 | #define BS_UP 2 |
Pokitto | 0:e8b8f36b4505 | 56 | |
Pokitto | 0:e8b8f36b4505 | 57 | uint8_t Pokitto::heldStates[NUM_BTN]; |
Pokitto | 0:e8b8f36b4505 | 58 | |
Pokitto | 0:e8b8f36b4505 | 59 | void APressed() { Pokitto::heldStates[BTN_A] = 1; } |
Pokitto | 0:e8b8f36b4505 | 60 | void AReleased() { Pokitto::heldStates[BTN_A] = 0; } |
Pokitto | 0:e8b8f36b4505 | 61 | void BPressed() { Pokitto::heldStates[BTN_B] = 1; } |
Pokitto | 0:e8b8f36b4505 | 62 | void BReleased() { Pokitto::heldStates[BTN_B] = 0; } |
Pokitto | 0:e8b8f36b4505 | 63 | void CPressed() { |
Pokitto | 0:e8b8f36b4505 | 64 | Pokitto::heldStates[BTN_C] = 1; |
Pokitto | 0:e8b8f36b4505 | 65 | } |
Pokitto | 0:e8b8f36b4505 | 66 | void CReleased() { Pokitto::heldStates[BTN_C] = 0; } |
Pokitto | 0:e8b8f36b4505 | 67 | void UPressed() { Pokitto::heldStates[BTN_UP] = 1; } |
Pokitto | 0:e8b8f36b4505 | 68 | void UReleased() { Pokitto::heldStates[BTN_UP] = 0; } |
Pokitto | 0:e8b8f36b4505 | 69 | void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; } |
Pokitto | 0:e8b8f36b4505 | 70 | void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; } |
Pokitto | 0:e8b8f36b4505 | 71 | void RPressed() { |
Pokitto | 0:e8b8f36b4505 | 72 | /* Hardware volume control */ |
Pokitto | 0:e8b8f36b4505 | 73 | if (Pokitto::heldStates[BTN_C]) _s.volumeUp(); |
Pokitto | 0:e8b8f36b4505 | 74 | else Pokitto::heldStates[BTN_RIGHT] = 1; |
Pokitto | 0:e8b8f36b4505 | 75 | } |
Pokitto | 0:e8b8f36b4505 | 76 | void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; } |
Pokitto | 0:e8b8f36b4505 | 77 | void LPressed() { |
Pokitto | 0:e8b8f36b4505 | 78 | /* Hardware volume control */ |
Pokitto | 0:e8b8f36b4505 | 79 | if (Pokitto::heldStates[BTN_C]) _s.volumeDown(); |
Pokitto | 0:e8b8f36b4505 | 80 | else Pokitto::heldStates[BTN_LEFT] = 1; |
Pokitto | 0:e8b8f36b4505 | 81 | } |
Pokitto | 0:e8b8f36b4505 | 82 | void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; } |
Pokitto | 0:e8b8f36b4505 | 83 | |
Pokitto | 0:e8b8f36b4505 | 84 | void Pokitto::initButtons() { |
Pokitto | 0:e8b8f36b4505 | 85 | ABtn.fall(&AReleased); |
Pokitto | 0:e8b8f36b4505 | 86 | ABtn.rise(&APressed); |
Pokitto | 0:e8b8f36b4505 | 87 | BBtn.fall(&BReleased); |
Pokitto | 0:e8b8f36b4505 | 88 | BBtn.rise(&BPressed); |
Pokitto | 0:e8b8f36b4505 | 89 | CBtn.fall(&CReleased); |
Pokitto | 0:e8b8f36b4505 | 90 | CBtn.rise(&CPressed); |
Pokitto | 0:e8b8f36b4505 | 91 | UBtn.fall(&UReleased); |
Pokitto | 0:e8b8f36b4505 | 92 | UBtn.rise(&UPressed); |
Pokitto | 0:e8b8f36b4505 | 93 | DBtn.fall(&DReleased); |
Pokitto | 0:e8b8f36b4505 | 94 | DBtn.rise(&DPressed); |
Pokitto | 0:e8b8f36b4505 | 95 | LBtn.fall(&LReleased); |
Pokitto | 0:e8b8f36b4505 | 96 | LBtn.rise(&LPressed); |
Pokitto | 0:e8b8f36b4505 | 97 | RBtn.fall(&RReleased); |
Pokitto | 0:e8b8f36b4505 | 98 | RBtn.rise(&RPressed); |
Pokitto | 0:e8b8f36b4505 | 99 | } |
Pokitto | 0:e8b8f36b4505 | 100 | |
Pokitto | 0:e8b8f36b4505 | 101 | uint8_t Pokitto::Core::aBtn() { |
Pokitto | 0:e8b8f36b4505 | 102 | return Pokitto::heldStates[BTN_A]; |
Pokitto | 0:e8b8f36b4505 | 103 | } |
Pokitto | 0:e8b8f36b4505 | 104 | |
Pokitto | 0:e8b8f36b4505 | 105 | uint8_t Pokitto::Core::bBtn() { |
Pokitto | 0:e8b8f36b4505 | 106 | return Pokitto::heldStates[BTN_B]; |
Pokitto | 0:e8b8f36b4505 | 107 | } |
Pokitto | 0:e8b8f36b4505 | 108 | |
Pokitto | 0:e8b8f36b4505 | 109 | uint8_t Pokitto::Core::cBtn() { |
Pokitto | 0:e8b8f36b4505 | 110 | return Pokitto::heldStates[BTN_C]; |
Pokitto | 0:e8b8f36b4505 | 111 | } |
Pokitto | 0:e8b8f36b4505 | 112 | |
Pokitto | 0:e8b8f36b4505 | 113 | uint8_t Pokitto::Core::upBtn() { |
Pokitto | 0:e8b8f36b4505 | 114 | return Pokitto::heldStates[BTN_UP]; |
Pokitto | 0:e8b8f36b4505 | 115 | } |
Pokitto | 0:e8b8f36b4505 | 116 | uint8_t Pokitto::Core::downBtn() { |
Pokitto | 0:e8b8f36b4505 | 117 | return Pokitto::heldStates[BTN_DOWN]; |
Pokitto | 0:e8b8f36b4505 | 118 | } |
Pokitto | 0:e8b8f36b4505 | 119 | |
Pokitto | 0:e8b8f36b4505 | 120 | uint8_t Pokitto::Core::leftBtn() { |
Pokitto | 0:e8b8f36b4505 | 121 | return Pokitto::heldStates[BTN_LEFT]; |
Pokitto | 0:e8b8f36b4505 | 122 | } |
Pokitto | 0:e8b8f36b4505 | 123 | uint8_t Pokitto::Core::rightBtn() { |
Pokitto | 0:e8b8f36b4505 | 124 | return Pokitto::heldStates[BTN_RIGHT]; |
Pokitto | 0:e8b8f36b4505 | 125 | } |
Pokitto | 0:e8b8f36b4505 | 126 |