Revision 61b0791a components/bluetooth/bluetooth-wiimote.cpp
| components/bluetooth/bluetooth-wiimote.cpp | ||
|---|---|---|
| 3 | 3 |
|
| 4 | 4 |
#include <amiro/bluetooth/bluetooth-wiimote.hpp> |
| 5 | 5 |
|
| 6 |
#include <global.hpp> |
|
| 7 |
|
|
| 6 | 8 |
using namespace chibios_rt; |
| 7 | 9 |
using namespace amiro; |
| 8 | 10 |
|
| 11 |
extern Global global; |
|
| 12 |
|
|
| 9 | 13 |
/* |
| 10 | 14 |
* Class constructor |
| 11 | 15 |
*/ |
| ... | ... | |
| 39 | 43 |
size_t length; |
| 40 | 44 |
msg_t msg; |
| 41 | 45 |
|
| 42 |
static uint8_t button_up; |
|
| 43 |
static uint8_t button_down; |
|
| 44 |
static uint8_t button_right; |
|
| 45 |
static uint8_t button_left; |
|
| 46 |
static uint8_t button_plus; |
|
| 47 |
static uint8_t button_home; |
|
| 48 |
static uint8_t button_minus; |
|
| 49 |
static uint8_t button_A; |
|
| 50 |
static uint8_t button_B; |
|
| 51 |
static uint8_t button_1; |
|
| 52 |
static uint8_t button_2; |
|
| 53 |
|
|
| 54 | 46 |
msg = mailbox.fetch((msg_t*) &recv_descriptor, TIME_INFINITE); |
| 55 | 47 |
if ((msg == RDY_RESET) || stopflag) |
| 56 | 48 |
return RDY_RESET; |
| ... | ... | |
| 58 | 50 |
buffer = recv_descriptor->bluetoothDescriptorGetPayload(); |
| 59 | 51 |
length = recv_descriptor->bluetoothDescriptorGetPayloadLength(); |
| 60 | 52 |
|
| 61 |
if (buffer[0] == 0xA1 && buffer[1] == 0x31) {
|
|
| 62 |
accelerometer.x_axis = (buffer[4] << 2) + ((buffer[2] & 0x60) >> 5) - 0x1EC; |
|
| 63 |
accelerometer.y_axis = (buffer[5] << 2) + ((buffer[3] & 0x20) >> 4) - 0x1EA; |
|
| 64 |
accelerometer.z_axis = (buffer[6] << 2) + ((buffer[3] & 0x40) >> 5) - 0x1EE; |
|
| 65 |
|
|
| 66 |
if (buffer[3] & 0x80) { // Press home to return button reporting
|
|
| 67 |
bluetoothWiimoteDataBtn(); |
|
| 68 |
accelerometer.x_axis = 0; |
|
| 69 |
accelerometer.y_axis = 0; |
|
| 70 |
accelerometer.z_axis = 0; |
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
} else if (buffer[0] == 0xA1 && buffer[1] == 0x30) {
|
|
| 74 |
button_up = (buffer[2] & 0x08) >> 3; |
|
| 75 |
button_down = (buffer[2] & 0x04) >> 2; |
|
| 76 |
button_right = (buffer[2] & 0x02) >> 1; |
|
| 77 |
button_left = (buffer[2] & 0x01) >> 0; |
|
| 78 |
button_plus = (buffer[2] & 0x10) >> 4; |
|
| 79 |
button_home = (buffer[3] & 0x80) >> 7; |
|
| 80 |
button_minus = (buffer[3] & 0x10) >> 4; |
|
| 81 |
button_A = (buffer[3] & 0x08) >> 3; |
|
| 82 |
button_B = (buffer[3] & 0x04) >> 2; |
|
| 83 |
button_1 = (buffer[3] & 0x02) >> 1; |
|
| 84 |
button_2 = (buffer[3] & 0x01) >> 0; |
|
| 85 |
|
|
| 86 |
if (button_up) |
|
| 87 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'U'); |
|
| 88 |
|
|
| 89 |
if (button_down) |
|
| 90 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'D'); |
|
| 91 |
|
|
| 92 |
if (button_right) |
|
| 93 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'R'); |
|
| 94 |
|
|
| 95 |
if (button_left) |
|
| 96 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'L'); |
|
| 53 |
if (buffer[0] == 0xA1 && (buffer[1] == 0x30 || buffer[1] == 0x31)) {
|
|
| 54 |
buttons.left = (buffer[2] & 0x01) ? 1 : 0; |
|
| 55 |
buttons.right = (buffer[2] & 0x02) ? 1 : 0; |
|
| 56 |
buttons.down = (buffer[2] & 0x04) ? 1 : 0; |
|
| 57 |
buttons.up = (buffer[2] & 0x08) ? 1 : 0; |
|
| 58 |
buttons.plus = (buffer[2] & 0x10) ? 1 : 0; |
|
| 59 |
buttons.two = (buffer[3] & 0x01) ? 1 : 0; |
|
| 60 |
buttons.one = (buffer[3] & 0x02) ? 1 : 0; |
|
| 61 |
buttons.B = (buffer[3] & 0x04) ? 1 : 0; |
|
| 62 |
buttons.A = (buffer[3] & 0x08) ? 1 : 0; |
|
| 63 |
buttons.minus = (buffer[3] & 0x10) ? 1 : 0; |
|
| 64 |
buttons.home = (buffer[3] & 0x80) ? 1 : 0; |
|
| 65 |
|
|
| 66 |
accelerometer.x_axis = (buffer[4] << 2) + ((buffer[2] & 0x60) >> 5) - 0x1FF; |
|
| 67 |
accelerometer.y_axis = (buffer[5] << 2) + ((buffer[3] & 0x20) >> 4) - 0x1FF; |
|
| 68 |
accelerometer.z_axis = (buffer[6] << 2) + ((buffer[3] & 0x40) >> 5) - 0x1FF; |
|
| 97 | 69 |
|
| 98 |
if (button_plus) |
|
| 99 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, '+'); |
|
| 100 |
|
|
| 101 |
if (button_home) |
|
| 102 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'H'); |
|
| 103 |
|
|
| 104 |
if (button_minus) |
|
| 105 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, '-'); |
|
| 106 |
|
|
| 107 |
if (button_A) |
|
| 108 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'A'); |
|
| 109 |
|
|
| 110 |
if (button_B) |
|
| 111 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, 'B'); |
|
| 112 |
|
|
| 113 |
if (button_1) |
|
| 114 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, '1'); |
|
| 115 |
|
|
| 116 |
if (button_2) |
|
| 117 |
chSequentialStreamPut((BaseSequentialStream*) &SD1, '2'); |
|
| 118 |
|
|
| 119 |
if (button_minus && button_plus) // Press minus and plue to return accelerometer reporting |
|
| 120 | 70 |
bluetoothWiimoteDataBtnAcc(); |
| 121 | 71 |
} else {
|
| 122 |
chSequentialStreamWrite((BaseSequentialStream*) &SD1, buffer, length);
|
|
| 72 |
chSequentialStreamWrite((BaseSequentialStream*) &global.sercanmux1, buffer, length);
|
|
| 123 | 73 |
} |
| 124 | 74 |
|
| 125 | 75 |
msg = iwrap->transport.bluetoothTransportGetStorageMailbox()->post((msg_t) recv_descriptor, TIME_INFINITE); |
| ... | ... | |
| 179 | 129 |
return &accelerometer; |
| 180 | 130 |
} |
| 181 | 131 |
|
| 132 |
BluetoothWiimote::Buttons * BluetoothWiimote::getButtons() {
|
|
| 133 |
return &buttons; |
|
| 134 |
} |
|
| 135 |
|
|
| 182 | 136 |
/* |
| 183 | 137 |
* @brief : On-off LEDs and Motor of Wiimote. |
| 184 | 138 |
* |
Also available in: Unified diff