Jubeat (ユビート Yubīto?), stylized as jubeat, is a series of arcade music video games developed by Konami Computer Entertainment Japan, and is a part of Konami's Bemani line of music video games. The series uses an arrangement of 16 buttons in a 4x4 grid for gameplay, a grid also used for the displaying of cues and part of the user interface.

Dependencies:   4DGL-uLCD-SE SDFileSystem TextLCD mbed-rtos mbed wave_player

Fork of ECE4180_Lab4 by Zhihan Jiang

Committer:
ToHellWithGeorgi
Date:
Wed Mar 16 13:38:50 2016 +0000
Revision:
0:c3c8793d0091
ECE 4180 jubeat;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ToHellWithGeorgi 0:c3c8793d0091 1 /*
ToHellWithGeorgi 0:c3c8793d0091 2 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
ToHellWithGeorgi 0:c3c8793d0091 3
ToHellWithGeorgi 0:c3c8793d0091 4 Permission is hereby granted, free of charge, to any person obtaining a copy
ToHellWithGeorgi 0:c3c8793d0091 5 of this software and associated documentation files (the "Software"), to deal
ToHellWithGeorgi 0:c3c8793d0091 6 in the Software without restriction, including without limitation the rights
ToHellWithGeorgi 0:c3c8793d0091 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ToHellWithGeorgi 0:c3c8793d0091 8 copies of the Software, and to permit persons to whom the Software is
ToHellWithGeorgi 0:c3c8793d0091 9 furnished to do so, subject to the following conditions:
ToHellWithGeorgi 0:c3c8793d0091 10
ToHellWithGeorgi 0:c3c8793d0091 11 The above copyright notice and this permission notice shall be included in
ToHellWithGeorgi 0:c3c8793d0091 12 all copies or substantial portions of the Software.
ToHellWithGeorgi 0:c3c8793d0091 13
ToHellWithGeorgi 0:c3c8793d0091 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ToHellWithGeorgi 0:c3c8793d0091 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ToHellWithGeorgi 0:c3c8793d0091 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ToHellWithGeorgi 0:c3c8793d0091 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ToHellWithGeorgi 0:c3c8793d0091 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ToHellWithGeorgi 0:c3c8793d0091 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ToHellWithGeorgi 0:c3c8793d0091 20 THE SOFTWARE.
ToHellWithGeorgi 0:c3c8793d0091 21 */
ToHellWithGeorgi 0:c3c8793d0091 22
ToHellWithGeorgi 0:c3c8793d0091 23 #include <mbed.h>
ToHellWithGeorgi 0:c3c8793d0091 24 #include <sstream>
ToHellWithGeorgi 0:c3c8793d0091 25 #include <string>
ToHellWithGeorgi 0:c3c8793d0091 26 #include <list>
ToHellWithGeorgi 0:c3c8793d0091 27
ToHellWithGeorgi 0:c3c8793d0091 28 #include <mpr121.h>
ToHellWithGeorgi 0:c3c8793d0091 29
ToHellWithGeorgi 0:c3c8793d0091 30 Mpr121::Mpr121(I2C *i2c, Address i2cAddress)
ToHellWithGeorgi 0:c3c8793d0091 31 {
ToHellWithGeorgi 0:c3c8793d0091 32 this->i2c = i2c;
ToHellWithGeorgi 0:c3c8793d0091 33
ToHellWithGeorgi 0:c3c8793d0091 34 address = i2cAddress;
ToHellWithGeorgi 0:c3c8793d0091 35
ToHellWithGeorgi 0:c3c8793d0091 36 // Configure the MPR121 settings to default
ToHellWithGeorgi 0:c3c8793d0091 37 this->configureSettings();
ToHellWithGeorgi 0:c3c8793d0091 38 }
ToHellWithGeorgi 0:c3c8793d0091 39
ToHellWithGeorgi 0:c3c8793d0091 40
ToHellWithGeorgi 0:c3c8793d0091 41 void Mpr121::configureSettings()
ToHellWithGeorgi 0:c3c8793d0091 42 {
ToHellWithGeorgi 0:c3c8793d0091 43 // Put the MPR into setup mode
ToHellWithGeorgi 0:c3c8793d0091 44 this->write(ELE_CFG,0x00);
ToHellWithGeorgi 0:c3c8793d0091 45
ToHellWithGeorgi 0:c3c8793d0091 46 // Electrode filters for when data is > baseline
ToHellWithGeorgi 0:c3c8793d0091 47 unsigned char gtBaseline[] = {
ToHellWithGeorgi 0:c3c8793d0091 48 0x01, //MHD_R
ToHellWithGeorgi 0:c3c8793d0091 49 0x01, //NHD_R
ToHellWithGeorgi 0:c3c8793d0091 50 0x00, //NCL_R
ToHellWithGeorgi 0:c3c8793d0091 51 0x00 //FDL_R
ToHellWithGeorgi 0:c3c8793d0091 52 };
ToHellWithGeorgi 0:c3c8793d0091 53
ToHellWithGeorgi 0:c3c8793d0091 54 writeMany(MHD_R,gtBaseline,4);
ToHellWithGeorgi 0:c3c8793d0091 55
ToHellWithGeorgi 0:c3c8793d0091 56 // Electrode filters for when data is < baseline
ToHellWithGeorgi 0:c3c8793d0091 57 unsigned char ltBaseline[] = {
ToHellWithGeorgi 0:c3c8793d0091 58 0x01, //MHD_F
ToHellWithGeorgi 0:c3c8793d0091 59 0x01, //NHD_F
ToHellWithGeorgi 0:c3c8793d0091 60 0xFF, //NCL_F
ToHellWithGeorgi 0:c3c8793d0091 61 0x02 //FDL_F
ToHellWithGeorgi 0:c3c8793d0091 62 };
ToHellWithGeorgi 0:c3c8793d0091 63
ToHellWithGeorgi 0:c3c8793d0091 64 writeMany(MHD_F,ltBaseline,4);
ToHellWithGeorgi 0:c3c8793d0091 65
ToHellWithGeorgi 0:c3c8793d0091 66 // Electrode touch and release thresholds
ToHellWithGeorgi 0:c3c8793d0091 67 unsigned char electrodeThresholds[] = {
ToHellWithGeorgi 0:c3c8793d0091 68 E_THR_T, // Touch Threshhold
ToHellWithGeorgi 0:c3c8793d0091 69 E_THR_R // Release Threshold
ToHellWithGeorgi 0:c3c8793d0091 70 };
ToHellWithGeorgi 0:c3c8793d0091 71
ToHellWithGeorgi 0:c3c8793d0091 72 for(int i=0; i<12; i++){
ToHellWithGeorgi 0:c3c8793d0091 73 int result = writeMany((ELE0_T+(i*2)),electrodeThresholds,2);
ToHellWithGeorgi 0:c3c8793d0091 74 }
ToHellWithGeorgi 0:c3c8793d0091 75
ToHellWithGeorgi 0:c3c8793d0091 76 // Proximity Settings
ToHellWithGeorgi 0:c3c8793d0091 77 unsigned char proximitySettings[] = {
ToHellWithGeorgi 0:c3c8793d0091 78 0xff, //MHD_Prox_R
ToHellWithGeorgi 0:c3c8793d0091 79 0xff, //NHD_Prox_R
ToHellWithGeorgi 0:c3c8793d0091 80 0x00, //NCL_Prox_R
ToHellWithGeorgi 0:c3c8793d0091 81 0x00, //FDL_Prox_R
ToHellWithGeorgi 0:c3c8793d0091 82 0x01, //MHD_Prox_F
ToHellWithGeorgi 0:c3c8793d0091 83 0x01, //NHD_Prox_F
ToHellWithGeorgi 0:c3c8793d0091 84 0xFF, //NCL_Prox_F
ToHellWithGeorgi 0:c3c8793d0091 85 0xff, //FDL_Prox_F
ToHellWithGeorgi 0:c3c8793d0091 86 0x00, //NHD_Prox_T
ToHellWithGeorgi 0:c3c8793d0091 87 0x00, //NCL_Prox_T
ToHellWithGeorgi 0:c3c8793d0091 88 0x00 //NFD_Prox_T
ToHellWithGeorgi 0:c3c8793d0091 89 };
ToHellWithGeorgi 0:c3c8793d0091 90 writeMany(MHDPROXR,proximitySettings,11);
ToHellWithGeorgi 0:c3c8793d0091 91
ToHellWithGeorgi 0:c3c8793d0091 92 unsigned char proxThresh[] = {
ToHellWithGeorgi 0:c3c8793d0091 93 PROX_THR_T, // Touch Threshold
ToHellWithGeorgi 0:c3c8793d0091 94 PROX_THR_R // Release Threshold
ToHellWithGeorgi 0:c3c8793d0091 95 };
ToHellWithGeorgi 0:c3c8793d0091 96 writeMany(EPROXTTH,proxThresh,2);
ToHellWithGeorgi 0:c3c8793d0091 97
ToHellWithGeorgi 0:c3c8793d0091 98 this->write(FIL_CFG,0x04);
ToHellWithGeorgi 0:c3c8793d0091 99
ToHellWithGeorgi 0:c3c8793d0091 100 // Set the electrode config to transition to active mode
ToHellWithGeorgi 0:c3c8793d0091 101 this->write(ELE_CFG,0x0c);
ToHellWithGeorgi 0:c3c8793d0091 102 }
ToHellWithGeorgi 0:c3c8793d0091 103
ToHellWithGeorgi 0:c3c8793d0091 104 void Mpr121::setElectrodeThreshold(int electrode, unsigned char touch, unsigned char release){
ToHellWithGeorgi 0:c3c8793d0091 105
ToHellWithGeorgi 0:c3c8793d0091 106 if(electrode > 11) return;
ToHellWithGeorgi 0:c3c8793d0091 107
ToHellWithGeorgi 0:c3c8793d0091 108 // Get the current mode
ToHellWithGeorgi 0:c3c8793d0091 109 unsigned char mode = this->read(ELE_CFG);
ToHellWithGeorgi 0:c3c8793d0091 110
ToHellWithGeorgi 0:c3c8793d0091 111 // Put the MPR into setup mode
ToHellWithGeorgi 0:c3c8793d0091 112 this->write(ELE_CFG,0x00);
ToHellWithGeorgi 0:c3c8793d0091 113
ToHellWithGeorgi 0:c3c8793d0091 114 // Write the new threshold
ToHellWithGeorgi 0:c3c8793d0091 115 this->write((ELE0_T+(electrode*2)), touch);
ToHellWithGeorgi 0:c3c8793d0091 116 this->write((ELE0_T+(electrode*2)+1), release);
ToHellWithGeorgi 0:c3c8793d0091 117
ToHellWithGeorgi 0:c3c8793d0091 118 //Restore the operating mode
ToHellWithGeorgi 0:c3c8793d0091 119 this->write(ELE_CFG, mode);
ToHellWithGeorgi 0:c3c8793d0091 120 }
ToHellWithGeorgi 0:c3c8793d0091 121
ToHellWithGeorgi 0:c3c8793d0091 122
ToHellWithGeorgi 0:c3c8793d0091 123 unsigned char Mpr121::read(int key){
ToHellWithGeorgi 0:c3c8793d0091 124
ToHellWithGeorgi 0:c3c8793d0091 125 unsigned char data[2];
ToHellWithGeorgi 0:c3c8793d0091 126
ToHellWithGeorgi 0:c3c8793d0091 127 //Start the command
ToHellWithGeorgi 0:c3c8793d0091 128 i2c->start();
ToHellWithGeorgi 0:c3c8793d0091 129
ToHellWithGeorgi 0:c3c8793d0091 130 // Address the target (Write mode)
ToHellWithGeorgi 0:c3c8793d0091 131 int ack1= i2c->write(address);
ToHellWithGeorgi 0:c3c8793d0091 132
ToHellWithGeorgi 0:c3c8793d0091 133 // Set the register key to read
ToHellWithGeorgi 0:c3c8793d0091 134 int ack2 = i2c->write(key);
ToHellWithGeorgi 0:c3c8793d0091 135
ToHellWithGeorgi 0:c3c8793d0091 136 // Re-start for read of data
ToHellWithGeorgi 0:c3c8793d0091 137 i2c->start();
ToHellWithGeorgi 0:c3c8793d0091 138
ToHellWithGeorgi 0:c3c8793d0091 139 // Re-send the target address in read mode
ToHellWithGeorgi 0:c3c8793d0091 140 int ack3 = i2c->write(address+1);
ToHellWithGeorgi 0:c3c8793d0091 141
ToHellWithGeorgi 0:c3c8793d0091 142 // Read in the result
ToHellWithGeorgi 0:c3c8793d0091 143 data[0] = i2c->read(0);
ToHellWithGeorgi 0:c3c8793d0091 144
ToHellWithGeorgi 0:c3c8793d0091 145 // Reset the bus
ToHellWithGeorgi 0:c3c8793d0091 146 i2c->stop();
ToHellWithGeorgi 0:c3c8793d0091 147
ToHellWithGeorgi 0:c3c8793d0091 148 return data[0];
ToHellWithGeorgi 0:c3c8793d0091 149 }
ToHellWithGeorgi 0:c3c8793d0091 150
ToHellWithGeorgi 0:c3c8793d0091 151
ToHellWithGeorgi 0:c3c8793d0091 152 int Mpr121::write(int key, unsigned char value){
ToHellWithGeorgi 0:c3c8793d0091 153
ToHellWithGeorgi 0:c3c8793d0091 154 //Start the command
ToHellWithGeorgi 0:c3c8793d0091 155 i2c->start();
ToHellWithGeorgi 0:c3c8793d0091 156
ToHellWithGeorgi 0:c3c8793d0091 157 // Address the target (Write mode)
ToHellWithGeorgi 0:c3c8793d0091 158 int ack1= i2c->write(address);
ToHellWithGeorgi 0:c3c8793d0091 159
ToHellWithGeorgi 0:c3c8793d0091 160 // Set the register key to write
ToHellWithGeorgi 0:c3c8793d0091 161 int ack2 = i2c->write(key);
ToHellWithGeorgi 0:c3c8793d0091 162
ToHellWithGeorgi 0:c3c8793d0091 163 // Read in the result
ToHellWithGeorgi 0:c3c8793d0091 164 int ack3 = i2c->write(value);
ToHellWithGeorgi 0:c3c8793d0091 165
ToHellWithGeorgi 0:c3c8793d0091 166 // Reset the bus
ToHellWithGeorgi 0:c3c8793d0091 167 i2c->stop();
ToHellWithGeorgi 0:c3c8793d0091 168
ToHellWithGeorgi 0:c3c8793d0091 169 return (ack1+ack2+ack3)-3;
ToHellWithGeorgi 0:c3c8793d0091 170 }
ToHellWithGeorgi 0:c3c8793d0091 171
ToHellWithGeorgi 0:c3c8793d0091 172
ToHellWithGeorgi 0:c3c8793d0091 173 int Mpr121::writeMany(int start, unsigned char* dataSet, int length){
ToHellWithGeorgi 0:c3c8793d0091 174 //Start the command
ToHellWithGeorgi 0:c3c8793d0091 175 i2c->start();
ToHellWithGeorgi 0:c3c8793d0091 176
ToHellWithGeorgi 0:c3c8793d0091 177 // Address the target (Write mode)
ToHellWithGeorgi 0:c3c8793d0091 178 int ack= i2c->write(address);
ToHellWithGeorgi 0:c3c8793d0091 179 if(ack!=1){
ToHellWithGeorgi 0:c3c8793d0091 180 return -1;
ToHellWithGeorgi 0:c3c8793d0091 181 }
ToHellWithGeorgi 0:c3c8793d0091 182
ToHellWithGeorgi 0:c3c8793d0091 183 // Set the register key to write
ToHellWithGeorgi 0:c3c8793d0091 184 ack = i2c->write(start);
ToHellWithGeorgi 0:c3c8793d0091 185 if(ack!=1){
ToHellWithGeorgi 0:c3c8793d0091 186 return -1;
ToHellWithGeorgi 0:c3c8793d0091 187 }
ToHellWithGeorgi 0:c3c8793d0091 188
ToHellWithGeorgi 0:c3c8793d0091 189 // Write the date set
ToHellWithGeorgi 0:c3c8793d0091 190 int count = 0;
ToHellWithGeorgi 0:c3c8793d0091 191 while(ack==1 && (count < length)){
ToHellWithGeorgi 0:c3c8793d0091 192 ack = i2c->write(dataSet[count]);
ToHellWithGeorgi 0:c3c8793d0091 193 count++;
ToHellWithGeorgi 0:c3c8793d0091 194 }
ToHellWithGeorgi 0:c3c8793d0091 195 // Stop the cmd
ToHellWithGeorgi 0:c3c8793d0091 196 i2c->stop();
ToHellWithGeorgi 0:c3c8793d0091 197
ToHellWithGeorgi 0:c3c8793d0091 198 return count;
ToHellWithGeorgi 0:c3c8793d0091 199 }
ToHellWithGeorgi 0:c3c8793d0091 200
ToHellWithGeorgi 0:c3c8793d0091 201
ToHellWithGeorgi 0:c3c8793d0091 202 bool Mpr121::getProximityMode(){
ToHellWithGeorgi 0:c3c8793d0091 203 if(this->read(ELE_CFG) > 0x0c)
ToHellWithGeorgi 0:c3c8793d0091 204 return true;
ToHellWithGeorgi 0:c3c8793d0091 205 else
ToHellWithGeorgi 0:c3c8793d0091 206 return false;
ToHellWithGeorgi 0:c3c8793d0091 207 }
ToHellWithGeorgi 0:c3c8793d0091 208
ToHellWithGeorgi 0:c3c8793d0091 209 void Mpr121::setProximityMode(bool mode){
ToHellWithGeorgi 0:c3c8793d0091 210 this->write(ELE_CFG,0x00);
ToHellWithGeorgi 0:c3c8793d0091 211 if(mode){
ToHellWithGeorgi 0:c3c8793d0091 212 this->write(ELE_CFG,0x30); //Sense proximity from ALL pads
ToHellWithGeorgi 0:c3c8793d0091 213 } else {
ToHellWithGeorgi 0:c3c8793d0091 214 this->write(ELE_CFG,0x0c); //Sense touch, all 12 pads active.
ToHellWithGeorgi 0:c3c8793d0091 215 }
ToHellWithGeorgi 0:c3c8793d0091 216 }
ToHellWithGeorgi 0:c3c8793d0091 217
ToHellWithGeorgi 0:c3c8793d0091 218
ToHellWithGeorgi 0:c3c8793d0091 219 int Mpr121::readTouchData(){
ToHellWithGeorgi 0:c3c8793d0091 220 return this->read(0x00);
ToHellWithGeorgi 0:c3c8793d0091 221 }