Move functions into .cpp file

This commit is contained in:
Kristian Sloth Lauszus 2015-04-16 17:00:07 +02:00
parent 7acf598a59
commit d2511df4a1
2 changed files with 28 additions and 21 deletions

29
Wii.cpp
View file

@ -880,8 +880,8 @@ void WII::Run() {
/************************************************************/ /************************************************************/
/* HID Commands */ /* HID Commands */
/************************************************************/ /************************************************************/
void WII::HID_Command(uint8_t* data, uint8_t nbytes) { void WII::HID_Command(uint8_t* data, uint8_t nbytes) {
if(motionPlusInside) if(motionPlusInside)
pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // It's the new Wiimote with the Motion Plus Inside or Wii U Pro controller pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // It's the new Wiimote with the Motion Plus Inside or Wii U Pro controller
@ -982,8 +982,8 @@ void WII::statusRequest() {
/************************************************************/ /************************************************************/
/* Memmory Commands */ /* Memmory Commands */
/************************************************************/ /************************************************************/
void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) { void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) {
uint8_t cmd_buf[23]; uint8_t cmd_buf[23];
cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02) cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
@ -1077,7 +1077,6 @@ void WII::calibrateWiiBalanceBoard() {
/************************************************************/ /************************************************************/
/* WII Commands */ /* WII Commands */
/************************************************************/ /************************************************************/
bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed
@ -1129,6 +1128,30 @@ void WII::onInit() {
setLedStatus(); setLedStatus();
} }
/************************************************************/
/* Wii Balance Board Commands */
/************************************************************/
float WII::getWeight(BalanceBoardEnum pos) {
// Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py
// calibration[pos][0] is calibration values for 0 kg
// calibration[pos][1] is calibration values for 17 kg
// calibration[pos][2] is calibration values for 34 kg
float val = 0;
if(balanceBoardRaw[pos] < balanceBoardCal[0][pos])
return val;
else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos])
val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos])));
else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos])
val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos])));
return val;
};
float WII::getTotalWeight() {
return getWeight(TopRight) + getWeight(BotRight) + getWeight(TopLeft) + getWeight(BotLeft);
};
/************************************************************/ /************************************************************/
/* The following functions are for the IR camera */ /* The following functions are for the IR camera */
/************************************************************/ /************************************************************/

20
Wii.h
View file

@ -278,29 +278,13 @@ public:
* @param ::BalanceBoardEnum to read from. * @param ::BalanceBoardEnum to read from.
* @return Returns the weight in kg. * @return Returns the weight in kg.
*/ */
float getWeight(BalanceBoardEnum pos) { float getWeight(BalanceBoardEnum pos);
// Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py
// calibration[pos][0] is calibration values for 0 kg
// calibration[pos][1] is calibration values for 17 kg
// calibration[pos][2] is calibration values for 34 kg
float val = 0;
if(balanceBoardRaw[pos] < balanceBoardCal[0][pos])
return val;
else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos])
val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos])));
else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos])
val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos])));
return val;
};
/** /**
* Used to get total weight on the Wii Balance Board. * Used to get total weight on the Wii Balance Board.
* @returnReturns the weight in kg. * @returnReturns the weight in kg.
*/ */
float getTotalWeight() { float getTotalWeight();
return getWeight(TopRight) + getWeight(BotRight) + getWeight(TopLeft) + getWeight(BotLeft);
};
/** /**
* Used to get the raw reading at the specific position on the Wii Balance Board. * Used to get the raw reading at the specific position on the Wii Balance Board.