Ticket #63: balance.diff
| File balance.diff, 17.4 kB (added by TBBle, 4 years ago) |
|---|
-
python/cwiidmodule.c
96 96 CWIID_CONST_MACRO(RPT_IR), 97 97 CWIID_CONST_MACRO(RPT_NUNCHUK), 98 98 CWIID_CONST_MACRO(RPT_CLASSIC), 99 CWIID_CONST_MACRO(RPT_BALANCE), 99 100 CWIID_CONST_MACRO(RPT_EXT), 100 101 CWIID_CONST_MACRO(LED1_ON), 101 102 CWIID_CONST_MACRO(LED2_ON), … … 153 154 CWIID_CONST_MACRO(MESG_IR), 154 155 CWIID_CONST_MACRO(MESG_NUNCHUK), 155 156 CWIID_CONST_MACRO(MESG_CLASSIC), 157 CWIID_CONST_MACRO(MESG_BALANCE), 156 158 CWIID_CONST_MACRO(MESG_ERROR), 157 159 CWIID_CONST_MACRO(MESG_UNKNOWN), 158 160 CWIID_CONST_MACRO(EXT_NONE), 159 161 CWIID_CONST_MACRO(EXT_NUNCHUK), 160 162 CWIID_CONST_MACRO(EXT_CLASSIC), 163 CWIID_CONST_MACRO(EXT_BALANCE), 161 164 CWIID_CONST_MACRO(EXT_UNKNOWN), 162 165 CWIID_CONST_MACRO(ERROR_DISCONNECT), 163 166 CWIID_CONST_MACRO(ERROR_COMM), -
python/Wiimote.c
84 84 static PyObject *Wiimote_get_state(Wiimote *self, void *closure); 85 85 static PyObject *Wiimote_get_acc_cal(Wiimote *self, PyObject *args, 86 86 PyObject *kwds); 87 static PyObject *Wiimote_get_balance_cal(Wiimote *self); 87 88 88 89 static PyObject *Wiimote_request_status(Wiimote *self); 89 90 static int Wiimote_set_led(Wiimote *self, PyObject *PyLed, void *closure); … … 112 113 {"get_acc_cal", (PyCFunction)Wiimote_get_acc_cal, 113 114 METH_VARARGS | METH_KEYWORDS, 114 115 "get_acc_cal(extension) -> calibration tuple\n\n" 115 "retrieve calibration information"}, 116 "retrieve accelerometer calibration information"}, 117 {"get_balance_cal", (PyCFunction)Wiimote_get_balance_cal, METH_NOARGS, 118 "get_balance_cal() -> calibration tuple\n\n" 119 "retrieve Balance Board calibration information"}, 116 120 {"request_status", (PyCFunction)Wiimote_request_status, METH_NOARGS, 117 121 "request_status()\n\nrequest status message"}, 118 122 {"read", (PyCFunction)Wiimote_read, METH_VARARGS | METH_KEYWORDS, … … 521 525 Py_DECREF(PyExt); 522 526 } 523 527 break; 528 case CWIID_EXT_BALANCE: 529 if (state.rpt_mode & CWIID_RPT_BALANCE) { 530 PyExt = Py_BuildValue("{s:I,s:I,s:I,s:I}", 531 "right_top", 532 state.ext.balance.right_top, 533 "right_bottom", 534 state.ext.balance.right_bottom, 535 "left_top", 536 state.ext.balance.left_top, 537 "left_bottom", 538 state.ext.balance.left_bottom); 539 540 if (!PyExt) { 541 Py_DECREF(PyState); 542 return NULL; 543 } 544 545 if (PyDict_SetItemString(PyState, "balance", PyExt)) { 546 Py_DECREF(PyState); 547 Py_DECREF(PyExt); 548 return NULL; 549 } 550 551 Py_DECREF(PyExt); 552 } 553 break; 524 554 default: 525 555 break; 526 556 } … … 558 588 return PyAccCal; 559 589 } 560 590 591 static PyObject *Wiimote_get_balance_cal(Wiimote *self) 592 { 593 struct balance_cal balance_cal; 594 PyObject *PyBalCal; 595 596 if (cwiid_get_balance_cal(self->wiimote, &balance_cal)) { 597 PyErr_SetString(PyExc_RuntimeError, 598 "Error getting balance board calibration"); 599 return NULL; 600 } 601 602 if (!(PyBalCal = Py_BuildValue("([i,i,i],[i,i,i],[i,i,i],[i,i,i])", 603 balance_cal.right_top[0], 604 balance_cal.right_top[1], 605 balance_cal.right_top[2], 606 balance_cal.right_bottom[0], 607 balance_cal.right_bottom[1], 608 balance_cal.right_bottom[2], 609 balance_cal.left_top[0], 610 balance_cal.left_top[1], 611 balance_cal.left_top[2], 612 balance_cal.left_bottom[0], 613 balance_cal.left_bottom[1], 614 balance_cal.left_bottom[2]))) { 615 return NULL; 616 } 617 618 return PyBalCal; 619 } 620 561 621 static PyObject *Wiimote_request_status(Wiimote *self) 562 622 { 563 623 if (cwiid_request_status(self->wiimote)) { … … 728 788 * "buttons":buttons}, 729 789 * (cwiid.CLASSIC_MESG,{"l_stick":(x,y),"r_stick":(x,y),"l":l,"r":r, 730 790 * "buttons":buttons}, 791 * (cwiid.BALANCE_MESG,{"right_top":right_top, 792 * "right_bottom":right_bottom, 793 * "left_top":left_top, 794 * "left_bottom":left_bottom}, 731 795 * (cwiid.ERROR_MESG,error)] 732 796 */ 733 797 PyObject *ConvertMesgArray(int mesg_count, union cwiid_mesg mesg[]) … … 834 898 "r", mesg[i].classic_mesg.r, 835 899 "buttons", mesg[i].classic_mesg.buttons); 836 900 break; 901 case CWIID_MESG_BALANCE: 902 mesgVal = Py_BuildValue("{s:I,s:I,s:I,s:I}", 903 "right_top", 904 mesg[i].balance_mesg.right_top, 905 "right_bottom", 906 mesg[i].balance_mesg.right_bottom, 907 "left_top", 908 mesg[i].balance_mesg.left_top, 909 "left_bottom", 910 mesg[i].balance_mesg.left_bottom); 911 break; 837 912 case CWIID_MESG_ERROR: 838 913 mesgVal = Py_BuildValue("i", mesg[i].error_mesg.error); 839 914 break; -
libcwiid/process.c
182 182 { 183 183 struct cwiid_nunchuk_mesg *nunchuk_mesg; 184 184 struct cwiid_classic_mesg *classic_mesg; 185 struct cwiid_balance_mesg *balance_mesg; 185 186 int i; 186 187 187 188 switch (wiimote->state.ext_type) { … … 224 225 (uint16_t)data[5]); 225 226 } 226 227 break; 228 case CWIID_EXT_BALANCE: 229 if (wiimote->state.rpt_mode & CWIID_RPT_BALANCE) { 230 balance_mesg = &ma->array[ma->count++].balance_mesg; 231 balance_mesg->type = CWIID_MESG_BALANCE; 232 balance_mesg->right_top = ((uint16_t)data[0]<<8 | 233 (uint16_t)data[1]); 234 balance_mesg->right_bottom = ((uint16_t)data[2]<<8 | 235 (uint16_t)data[3]); 236 balance_mesg->left_top = ((uint16_t)data[4]<<8 | 237 (uint16_t)data[5]); 238 balance_mesg->left_bottom = ((uint16_t)data[6]<<8 | 239 (uint16_t)data[7]); 240 } 241 break; 227 242 } 228 243 229 244 return 0; -
libcwiid/cwiid_internal.h
73 73 74 74 /* Wiimote specific magic numbers */ 75 75 #define WIIMOTE_NAME "Nintendo RVL-CNT-01" 76 #define WIIBALANCE_NAME "Nintendo RVL-WBC-01" 76 77 #define WIIMOTE_CLASS_0 0x04 77 78 #define WIIMOTE_CLASS_1 0x25 78 79 #define WIIMOTE_CLASS_2 0x00 … … 114 115 115 116 /* Extension Values */ 116 117 #define EXT_NONE 0x2E 117 #define EXT_PARTIAL 0xFF 118 #define EXT_NUNCHUK 0x00 119 #define EXT_CLASSIC 0x01 118 #define EXT_PARTIAL 0xFF 119 #define EXT_NUNCHUK 0x00 120 #define EXT_CLASSIC 0x01 121 #define EXT_BALANCE 0x2A 120 122 121 123 /* IR Enable blocks */ 122 124 #define MARCAN_IR_BLOCK_1 "\x00\x00\x00\x00\x00\x00\x90\x00\xC0" -
libcwiid/interface.c
179 179 180 180 return 0; 181 181 } 182 183 int cwiid_get_balance_cal(struct wiimote *wiimote, 184 struct balance_cal *balance_cal) 185 { 186 unsigned char buf[24]; 187 188 if (cwiid_read(wiimote, CWIID_RW_REG, 0xa40024, 24, buf)) { 189 cwiid_err(wiimote, "Read error (balancecal)"); 190 return -1; 191 } 192 balance_cal->right_top[0] = ((uint16_t)buf[0]<<8 | (uint16_t)buf[1]); 193 balance_cal->right_bottom[0] = ((uint16_t)buf[2]<<8 | (uint16_t)buf[3]); 194 balance_cal->left_top[0] = ((uint16_t)buf[4]<<8 | (uint16_t)buf[5]); 195 balance_cal->left_bottom[0] = ((uint16_t)buf[6]<<8 | (uint16_t)buf[7]); 196 balance_cal->right_top[1] = ((uint16_t)buf[8]<<8 | (uint16_t)buf[9]); 197 balance_cal->right_bottom[1] = ((uint16_t)buf[10]<<8 | (uint16_t)buf[11]); 198 balance_cal->left_top[1] = ((uint16_t)buf[12]<<8 | (uint16_t)buf[13]); 199 balance_cal->left_bottom[1] = ((uint16_t)buf[14]<<8 | (uint16_t)buf[15]); 200 balance_cal->right_top[2] = ((uint16_t)buf[16]<<8 | (uint16_t)buf[17]); 201 balance_cal->right_bottom[2] = ((uint16_t)buf[18]<<8 | (uint16_t)buf[19]); 202 balance_cal->left_top[2] = ((uint16_t)buf[20]<<8 | (uint16_t)buf[21]); 203 balance_cal->left_bottom[2] = ((uint16_t)buf[22]<<8 | (uint16_t)buf[23]); 204 205 return 0; 206 } -
libcwiid/state.c
75 75 wiimote->state.ext.classic.r = mesg->classic_mesg.r; 76 76 wiimote->state.ext.classic.buttons = mesg->classic_mesg.buttons; 77 77 break; 78 case CWIID_MESG_BALANCE: 79 wiimote->state.ext.balance.right_top = mesg->balance_mesg.right_top; 80 wiimote->state.ext.balance.right_bottom = mesg->balance_mesg.right_bottom; 81 wiimote->state.ext.balance.left_top = mesg->balance_mesg.left_top; 82 wiimote->state.ext.balance.left_bottom = mesg->balance_mesg.left_bottom; 83 break; 78 84 case CWIID_MESG_ERROR: 79 85 wiimote->state.error = mesg->error_mesg.error; 80 86 break; … … 166 172 rpt_type = RPT_EXT21; 167 173 } 168 174 } 175 else if ((rpt_mode & CWIID_RPT_EXT) && 176 wiimote->state.ext_type == CWIID_EXT_BALANCE) { 177 rpt_type = RPT_BTN_EXT8; 178 } 169 179 else { 170 180 if (rpt_mode & CWIID_RPT_IR) { 171 181 rpt_type = RPT_BTN_ACC_IR12; … … 223 233 (CWIID_RPT_CLASSIC & ~rpt_mode & wiimote->state.rpt_mode)) { 224 234 memset(&wiimote->state.ext, 0, sizeof wiimote->state.ext); 225 235 } 236 else if ((wiimote->state.ext_type == CWIID_EXT_BALANCE) && 237 (CWIID_RPT_BALANCE & ~rpt_mode & wiimote->state.rpt_mode)) { 238 memset(&wiimote->state.ext, 0, sizeof wiimote->state.ext); 239 } 226 240 227 241 wiimote->state.rpt_mode = rpt_mode; 228 242 -
libcwiid/cwiid.h
75 75 #define CWIID_RPT_IR 0x08 76 76 #define CWIID_RPT_NUNCHUK 0x10 77 77 #define CWIID_RPT_CLASSIC 0x20 78 #define CWIID_RPT_EXT (CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC) 78 #define CWIID_RPT_BALANCE 0x40 79 #define CWIID_RPT_EXT (CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC | CWIID_RPT_BALANCE) 79 80 80 81 /* LED flags */ 81 82 #define CWIID_LED1_ON 0x01 … … 165 166 CWIID_MESG_IR, 166 167 CWIID_MESG_NUNCHUK, 167 168 CWIID_MESG_CLASSIC, 169 CWIID_MESG_BALANCE, 168 170 CWIID_MESG_ERROR, 169 171 CWIID_MESG_UNKNOWN 170 172 }; … … 173 175 CWIID_EXT_NONE, 174 176 CWIID_EXT_NUNCHUK, 175 177 CWIID_EXT_CLASSIC, 178 CWIID_EXT_BALANCE, 176 179 CWIID_EXT_UNKNOWN 177 180 }; 178 181 … … 187 190 uint8_t one[3]; 188 191 }; 189 192 193 struct balance_cal { 194 uint16_t right_top[3]; 195 uint16_t right_bottom[3]; 196 uint16_t left_top[3]; 197 uint16_t left_bottom[3]; 198 }; 199 190 200 /* Message Structs */ 191 201 struct cwiid_status_mesg { 192 202 enum cwiid_mesg_type type; … … 231 241 uint16_t buttons; 232 242 }; 233 243 244 struct cwiid_balance_mesg { 245 enum cwiid_mesg_type type; 246 uint16_t right_top; 247 uint16_t right_bottom; 248 uint16_t left_top; 249 uint16_t left_bottom; 250 }; 251 234 252 struct cwiid_error_mesg { 235 253 enum cwiid_mesg_type type; 236 254 enum cwiid_error error; … … 244 262 struct cwiid_ir_mesg ir_mesg; 245 263 struct cwiid_nunchuk_mesg nunchuk_mesg; 246 264 struct cwiid_classic_mesg classic_mesg; 265 struct cwiid_balance_mesg balance_mesg; 247 266 struct cwiid_error_mesg error_mesg; 248 267 }; 249 268 … … 262 281 uint16_t buttons; 263 282 }; 264 283 284 struct balance_state { 285 uint16_t right_top; 286 uint16_t right_bottom; 287 uint16_t left_top; 288 uint16_t left_bottom; 289 }; 290 265 291 union ext_state { 266 292 struct nunchuk_state nunchuk; 267 293 struct classic_state classic; 294 struct balance_state balance; 268 295 }; 269 296 270 297 struct cwiid_state { … … 325 352 int cwiid_get_state(cwiid_wiimote_t *wiimote, struct cwiid_state *state); 326 353 int cwiid_get_acc_cal(struct wiimote *wiimote, enum cwiid_ext_type ext_type, 327 354 struct acc_cal *acc_cal); 355 int cwiid_get_balance_cal(struct wiimote *wiimote, 356 struct balance_cal *balance_cal); 328 357 329 358 /* Operations */ 330 359 int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command, -
libcwiid/bluetooth.c
131 131 132 132 /* Filter by name */ 133 133 if (!(flags & BT_NO_WIIMOTE_FILTER) && 134 strncmp((*bdinfo)[bdinfo_count].name, WIIMOTE_NAME, BT_NAME_LEN)) { 134 strncmp((*bdinfo)[bdinfo_count].name, WIIMOTE_NAME, BT_NAME_LEN) && 135 strncmp((*bdinfo)[bdinfo_count].name, WIIBALANCE_NAME, BT_NAME_LEN)) { 135 136 continue; 136 137 } 137 138 -
libcwiid/thread.c
216 216 case EXT_CLASSIC: 217 217 status_mesg->ext_type = CWIID_EXT_CLASSIC; 218 218 break; 219 case EXT_BALANCE: 220 status_mesg->ext_type = CWIID_EXT_BALANCE; 221 break; 219 222 default: 220 223 status_mesg->ext_type = CWIID_EXT_UNKNOWN; 221 224 break; -
wmdemo/wmdemo.py
26 26 27 27 #Connect to address given on command-line, if present 28 28 print 'Put Wiimote in discoverable mode now (press 1+2)...' 29 global wiimote 29 30 if len(sys.argv) > 1: 30 31 wiimote = cwiid.Wiimote(sys.argv[1]) 31 32 else: … … 91 92 92 93 def print_state(state): 93 94 print 'Report Mode:', 94 for r in ['STATUS', 'BTN', 'ACC', 'IR', 'NUNCHUK', 'CLASSIC' ]:95 for r in ['STATUS', 'BTN', 'ACC', 'IR', 'NUNCHUK', 'CLASSIC', 'BALANCE']: 95 96 if state['rpt_mode'] & eval('cwiid.RPT_' + r): 96 97 print r, 97 98 print … … 142 143 (state['classic']['buttons'], 143 144 state['classic']['l_stick'], state['classic']['r_stick'], 144 145 state['classic']['l'], state['classic']['r']) 146 elif state['ext_type'] == cwiid.EXT_BALANCE: 147 print 'Balance: right_top=%d right_bottom=%d left_top=%d left_bottom=%d' % \ 148 (state['balance']['right_top'], state['balance']['right_bottom'], 149 state['balance']['left_top'], state['balance']['left_bottom']) 145 150 146 151 def callback(mesg_list): 147 152 for mesg in mesg_list: … … 154 159 print 'Nunchuk' 155 160 elif mesg[1]['ext_type'] == cwiid.EXT_CLASSIC: 156 161 print 'Classic Controller' 162 elif mesg[1]['ext_type'] == cwiid.EXT_BALANCE: 163 print 'Balance Board' 157 164 else: 158 165 print 'Unknown Extension' 159 166 … … 190 197 state['classic']['l_stick'], state['classic']['r_stick'], 191 198 state['classic']['l'], state['classic']['r']) 192 199 elif mesg[0] == cwiid.MESG_ERROR: 200 print "Error message received" 201 global wiimote 193 202 wiimote.close() 194 203 exit(-1) 195 204 else: -
wmdemo/wmdemo.c
124 124 break; 125 125 case 'e': 126 126 /* CWIID_RPT_EXT is actually 127 * CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC */127 * CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC | CWIID_RPT_BALANCE */ 128 128 toggle_bit(rpt_mode, CWIID_RPT_EXT); 129 129 set_rpt_mode(wiimote, rpt_mode); 130 130 break; … … 215 215 if (state->rpt_mode & CWIID_RPT_IR) printf(" IR"); 216 216 if (state->rpt_mode & CWIID_RPT_NUNCHUK) printf(" NUNCHUK"); 217 217 if (state->rpt_mode & CWIID_RPT_CLASSIC) printf(" CLASSIC"); 218 if (state->rpt_mode & CWIID_RPT_BALANCE) printf(" BALANCE"); 218 219 printf("\n"); 219 220 220 221 printf("Active LEDs:"); … … 272 273 state->ext.classic.r_stick[CWIID_Y], 273 274 state->ext.classic.l, state->ext.classic.r); 274 275 break; 276 case CWIID_EXT_BALANCE: 277 printf("Balance: right_top=%d right_bottom=%d " 278 "left_top=%d left_bottom=%d\n", 279 state->ext.balance.right_top, 280 state->ext.balance.right_bottom, 281 state->ext.balance.left_top, 282 state->ext.balance.left_bottom); 283 break; 275 284 } 276 285 } 277 286 … … 290 299 { 291 300 int i, j; 292 301 int valid_source; 302 struct balance_cal balance_cal; 293 303 294 304 for (i=0; i < mesg_count; i++) 295 305 { … … 307 317 case CWIID_EXT_CLASSIC: 308 318 printf("Classic Controller"); 309 319 break; 320 case CWIID_EXT_BALANCE: 321 if(cwiid_get_balance_cal(wiimote, &balance_cal)) { 322 printf("Balance board: Failed to fetch calibration data"); 323 } 324 else { 325 printf("Balance board: right_top=(%d,%d,%d), " 326 "right_bottom=(%d,%d,%d), left_top=(%d,%d,%d), " 327 "left_bottom=(%d,%d,%d)", 328 balance_cal.right_top[0], 329 balance_cal.right_top[1], 330 balance_cal.right_top[2], 331 balance_cal.right_bottom[0], 332 balance_cal.right_bottom[1], 333 balance_cal.right_bottom[2], 334 balance_cal.left_top[0], 335 balance_cal.left_top[1], 336 balance_cal.left_top[2], 337 balance_cal.left_bottom[0], 338 balance_cal.left_bottom[1], 339 balance_cal.left_bottom[2]); 340 } 341 break; 310 342 default: 311 343 printf("Unknown Extension"); 312 344 break; … … 355 387 mesg[i].classic_mesg.r_stick[CWIID_Y], 356 388 mesg[i].classic_mesg.l, mesg[i].classic_mesg.r); 357 389 break; 390 case CWIID_MESG_BALANCE: 391 printf("Balance Report: right_top=%d right_bottom=%d " 392 "left_top=%d left_bottom=%d\n", 393 mesg[i].balance_mesg.right_top, 394 mesg[i].balance_mesg.right_bottom, 395 mesg[i].balance_mesg.left_top, 396 mesg[i].balance_mesg.left_bottom); 397 break; 358 398 case CWIID_MESG_ERROR: 359 399 if (cwiid_close(wiimote)) { 360 400 fprintf(stderr, "Error on wiimote disconnect\n");
