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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HWButtons.cpp Source File

HWButtons.cpp

Go to the documentation of this file.
00001 /**************************************************************************/
00002 /*!
00003     @file     HWButtons.cpp
00004     @author   Jonne Valola
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2016, Jonne Valola
00011     All rights reserved.
00012 
00013     Redistribution and use in source and binary forms, with or without
00014     modification, are permitted provided that the following conditions are met:
00015     1. Redistributions of source code must retain the above copyright
00016     notice, this list of conditions and the following disclaimer.
00017     2. Redistributions in binary form must reproduce the above copyright
00018     notice, this list of conditions and the following disclaimer in the
00019     documentation and/or other materials provided with the distribution.
00020     3. Neither the name of the copyright holders nor the
00021     names of its contributors may be used to endorse or promote products
00022     derived from this software without specific prior written permission.
00023 
00024     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00025     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00028     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 */
00035 /**************************************************************************/
00036 
00037 #include "HWButtons.h "
00038 #include "PokittoCore.h "
00039 #include "PokittoSound.h "
00040 #include "PokittoDisplay.h "
00041 
00042 Pokitto::Sound _s;
00043 Pokitto::Display _bd;
00044 
00045 using namespace mbed;
00046 
00047 InterruptIn ABtn(POK_BTN_A_PIN);
00048 InterruptIn BBtn(POK_BTN_B_PIN);
00049 InterruptIn CBtn(POK_BTN_C_PIN);
00050 InterruptIn UBtn(POK_BTN_UP_PIN);
00051 InterruptIn DBtn(POK_BTN_DOWN_PIN);
00052 InterruptIn LBtn(POK_BTN_LEFT_PIN);
00053 InterruptIn RBtn(POK_BTN_RIGHT_PIN);
00054 
00055 #define BS_IDLE 0
00056 #define BS_DOWN 1
00057 #define BS_UP 2
00058 
00059 uint8_t Pokitto::heldStates[NUM_BTN];
00060 
00061 void APressed() { Pokitto::heldStates[BTN_A] = 1; }
00062 void AReleased() { Pokitto::heldStates[BTN_A] = 0; }
00063 void BPressed() { Pokitto::heldStates[BTN_B] = 1; }
00064 void BReleased() { Pokitto::heldStates[BTN_B] = 0; }
00065 void CPressed() { Pokitto::heldStates[BTN_C] = 1;}
00066 void CReleased() { Pokitto::heldStates[BTN_C] = 0; }
00067 void UPressed() { Pokitto::heldStates[BTN_UP] = 1; }
00068 void UReleased() { Pokitto::heldStates[BTN_UP] = 0; }
00069 void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; }
00070 void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; }
00071 void RPressed() {
00072     /* Hardware volume control */
00073     if (Pokitto::heldStates[BTN_C]) _s.volumeUp();
00074     else Pokitto::heldStates[BTN_RIGHT] = 1;
00075     }
00076 void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; }
00077 void LPressed() {
00078     /* Hardware volume control */
00079     if (Pokitto::heldStates[BTN_C]) _s.volumeDown();
00080     else Pokitto::heldStates[BTN_LEFT] = 1;
00081     }
00082 void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; }
00083 
00084 void Pokitto::initButtons() {  
00085   ABtn.fall(&AReleased);
00086   ABtn.rise(&APressed);
00087   BBtn.fall(&BReleased);
00088   BBtn.rise(&BPressed);
00089   CBtn.fall(&CReleased);
00090   CBtn.rise(&CPressed);
00091   UBtn.fall(&UReleased);
00092   UBtn.rise(&UPressed);
00093   DBtn.fall(&DReleased);
00094   DBtn.rise(&DPressed);
00095   LBtn.fall(&LReleased);
00096   LBtn.rise(&LPressed);
00097   RBtn.fall(&RReleased);
00098   RBtn.rise(&RPressed);
00099 }
00100 
00101 uint8_t Pokitto::Core::aBtn() {
00102     return Pokitto::heldStates[BTN_A];
00103 }
00104 
00105 uint8_t Pokitto::Core::bBtn() {
00106     return Pokitto::heldStates[BTN_B];
00107 }
00108 
00109 uint8_t Pokitto::Core::cBtn() {
00110     return Pokitto::heldStates[BTN_C];
00111 }
00112 
00113 uint8_t Pokitto::Core::upBtn() {
00114     return Pokitto::heldStates[BTN_UP];
00115 }
00116 uint8_t Pokitto::Core::downBtn() {
00117     return Pokitto::heldStates[BTN_DOWN];
00118 }
00119 
00120 uint8_t Pokitto::Core::leftBtn() {
00121     return Pokitto::heldStates[BTN_LEFT];
00122 }
00123 uint8_t Pokitto::Core::rightBtn() {
00124     return Pokitto::heldStates[BTN_RIGHT];
00125 }
00126