Changeset 113
- Timestamp:
- 05/15/07 16:36:11 (2 years ago)
- Files:
-
- trunk/ChangeLog (modified) (2 diffs)
- trunk/libcwiid/cwiid.h (modified) (3 diffs)
- trunk/libcwiid/interface.c (modified) (2 diffs)
- trunk/wmgui/main.c (modified) (9 diffs)
- trunk/wminput/plugins/acc/acc.c (modified) (5 diffs)
- trunk/wminput/plugins/nunchuk_acc/nunchuk_acc.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r112 r113 2 2 libcwiid 3 3 * added timestamp to message interfaces 4 * added cwiid_get_acc_cal 4 5 5 6 wmdemo … … 8 9 wmgui 9 10 * updated for timestamp addition 11 * use cwiid_get_acc_cal to get acc calibration values 10 12 11 13 wminput 12 14 * updated for timestamp addition 15 * use cwiid_get_acc_cal to get acc calibration values (acc plugins) 13 16 14 17 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> trunk/libcwiid/cwiid.h
r112 r113 18 18 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 19 * * added timestamp to message functions 20 * * added cwiid_get_acc_cal 20 21 * 21 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> … … 174 175 }; 175 176 177 struct acc_cal { 178 uint8_t zero[3]; 179 uint8_t one[3]; 180 }; 181 176 182 /* Message Structs */ 177 183 struct cwiid_status_mesg { … … 307 313 union cwiid_mesg *mesg[], struct timespec *timestamp); 308 314 int cwiid_get_state(cwiid_wiimote_t *wiimote, struct cwiid_state *state); 315 int cwiid_get_acc_cal(struct wiimote *wiimote, enum cwiid_ext_type ext_type, 316 struct acc_cal *acc_cal); 309 317 310 318 /* Operations */ trunk/libcwiid/interface.c
r112 r113 18 18 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 19 * * added timestamp to cwiid_get_mesg 20 * * added cwiid_get_acc_cal 20 21 * 21 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> … … 141 142 return 0; 142 143 } 144 145 int cwiid_get_acc_cal(struct wiimote *wiimote, enum cwiid_ext_type ext_type, 146 struct acc_cal *acc_cal) 147 { 148 uint8_t flags; 149 uint32_t offset; 150 unsigned char buf[7]; 151 char *err_str; 152 153 switch (ext_type) { 154 case CWIID_EXT_NONE: 155 flags = CWIID_RW_EEPROM; 156 offset = 0x16; 157 err_str = ""; 158 break; 159 case CWIID_EXT_NUNCHUK: 160 flags = CWIID_RW_REG | CWIID_RW_DECODE; 161 offset = 0xA40020; 162 err_str = "nunchuk "; 163 break; 164 default: 165 cwiid_err(wiimote, "Unsupported calibration request"); 166 return -1; 167 } 168 if (cwiid_read(wiimote, flags, offset, 7, buf)) { 169 cwiid_err(wiimote, "Read error (%scal)", err_str); 170 return -1; 171 } 172 173 acc_cal->zero[CWIID_X] = buf[0]; 174 acc_cal->zero[CWIID_Y] = buf[1]; 175 acc_cal->zero[CWIID_Z] = buf[2]; 176 acc_cal->one[CWIID_X] = buf[4]; 177 acc_cal->one[CWIID_Y] = buf[5]; 178 acc_cal->one[CWIID_Z] = buf[6]; 179 180 return 0; 181 } trunk/wmgui/main.c
r112 r113 18 18 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 19 * * added timestamp to message callback 20 * * use cwiid_get_acc_cal to get acc calibration values 20 21 * 21 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> … … 64 65 #define PI 3.14159265358979323 65 66 66 struct acc {67 uint8_t x;68 uint8_t y;69 uint8_t z;70 };71 72 67 struct stick { 73 68 char valid; … … 80 75 cwiid_wiimote_t *wiimote = NULL; 81 76 bdaddr_t bdaddr; 82 struct acc acc_zero, acc_one;77 struct acc_cal wm_cal, nc_cal; 83 78 struct cwiid_ir_mesg ir_data; 84 struct acc nc_acc_zero, nc_acc_one;85 79 struct stick nc_stick; 86 80 struct stick cc_l_stick, cc_r_stick; … … 634 628 { 635 629 char reset_bdaddr = 0; 636 unsigned char buf[7];637 630 638 631 if (bacmp(&bdaddr, BDADDR_ANY) == 0) { … … 658 651 else { 659 652 status("Connected"); 660 if (cwiid_ read(wiimote, CWIID_RW_EEPROM, 0x16, 7, buf)) {653 if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NONE, &wm_cal)) { 661 654 message(GTK_MESSAGE_ERROR, "Unable to retrieve accelerometer " 662 655 "calibration", GTK_WINDOW(winMain)); 663 }664 else {665 acc_zero.x = buf[0];666 acc_zero.y = buf[1];667 acc_zero.z = buf[2];668 acc_one.x = buf[4];669 acc_one.y = buf[5];670 acc_one.z = buf[6];671 656 } 672 657 set_gui_state(); … … 1025 1010 char battery[BATTERY_STR_LEN]; 1026 1011 char *ext_str; 1027 unsigned char buf[7];1028 1012 static enum cwiid_ext_type ext_type = CWIID_EXT_NONE; 1029 1013 … … 1043 1027 ext_str = "Nunchuk"; 1044 1028 if (ext_type != CWIID_EXT_NUNCHUK) { 1045 if (cwiid_read(wiimote, 1046 CWIID_RW_REG | CWIID_RW_DECODE, 1047 0xA40020, 7, buf)) { 1048 message(GTK_MESSAGE_ERROR, "Unable to retrieve " 1049 "nunchuk calibration", GTK_WINDOW(winMain)); 1050 } 1051 else { 1052 nc_acc_zero.x = buf[0]; 1053 nc_acc_zero.y = buf[1]; 1054 nc_acc_zero.z = buf[2]; 1055 nc_acc_one.x = buf[4]; 1056 nc_acc_one.y = buf[5]; 1057 nc_acc_one.z = buf[6]; 1029 if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NUNCHUK, 1030 &nc_cal)) { 1031 message(GTK_MESSAGE_ERROR, 1032 "Unable to retrieve accelerometer calibration", 1033 GTK_WINDOW(winMain)); 1058 1034 } 1059 1035 } … … 1144 1120 (double)mesg->acc[CWIID_Z]/0xFF); 1145 1121 1146 a_x = ((double)mesg->acc[CWIID_X] - acc_zero.x) /1147 ( acc_one.x - acc_zero.x);1148 a_y = ((double)mesg->acc[CWIID_Y] - acc_zero.y) /1149 ( acc_one.y - acc_zero.y);1150 a_z = ((double)mesg->acc[CWIID_Z] - acc_zero.z) /1151 ( acc_one.z - acc_zero.z);1122 a_x = ((double)mesg->acc[CWIID_X] - wm_cal.zero[CWIID_X]) / 1123 (wm_cal.one[CWIID_X] - wm_cal.zero[CWIID_X]); 1124 a_y = ((double)mesg->acc[CWIID_Y] - wm_cal.zero[CWIID_Y]) / 1125 (wm_cal.one[CWIID_Y] - wm_cal.zero[CWIID_Y]); 1126 a_z = ((double)mesg->acc[CWIID_Z] - wm_cal.zero[CWIID_Z]) / 1127 (wm_cal.one[CWIID_Z] - wm_cal.zero[CWIID_Z]); 1152 1128 a = sqrt(pow(a_x,2)+pow(a_y,2)+pow(a_z,2)); 1153 1129 … … 1209 1185 1210 1186 /* TODO: get nunchuk calibration */ 1211 a_x = ((double)mesg->acc[CWIID_X] - nc_ acc_zero.x) /1212 (nc_ acc_one.x - nc_acc_zero.x);1213 a_y = ((double)mesg->acc[CWIID_Y] - nc_ acc_zero.y) /1214 (nc_ acc_one.y - nc_acc_zero.y);1215 a_z = ((double)mesg->acc[CWIID_Z] - nc_ acc_zero.z) /1216 (nc_ acc_one.z - nc_acc_zero.z);1187 a_x = ((double)mesg->acc[CWIID_X] - nc_cal.zero[CWIID_X]) / 1188 (nc_cal.one[CWIID_X] - nc_cal.zero[CWIID_X]); 1189 a_y = ((double)mesg->acc[CWIID_Y] - nc_cal.zero[CWIID_Y]) / 1190 (nc_cal.one[CWIID_Y] - nc_cal.zero[CWIID_Y]); 1191 a_z = ((double)mesg->acc[CWIID_Z] - nc_cal.zero[CWIID_Z]) / 1192 (nc_cal.one[CWIID_Z] - nc_cal.zero[CWIID_Z]); 1217 1193 a = sqrt(pow(a_x,2)+pow(a_y,2)+pow(a_z,2)); 1218 1194 roll = atan(a_x/a_z); trunk/wminput/plugins/acc/acc.c
r101 r113 16 16 * 17 17 * ChangeLog: 18 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * use cwiid_get_acc_cal to get acc calibration values 20 * 18 21 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * updated for API overhaul … … 43 46 #define PI 3.14159265358979323 44 47 45 struct acc {46 uint8_t x;47 uint8_t y;48 uint8_t z;49 };50 51 48 static unsigned char info_init = 0; 52 49 static struct wmplugin_info info; 53 50 static struct wmplugin_data data; 54 51 55 static struct acc acc_zero, acc_one;52 static struct acc_cal acc_cal; 56 53 57 54 static int plugin_id; … … 110 107 int wmplugin_init(int id, cwiid_wiimote_t *wiimote) 111 108 { 112 unsigned char buf[7];113 114 109 plugin_id = id; 115 110 … … 121 116 } 122 117 123 if (cwiid_ read(wiimote, CWIID_RW_EEPROM, 0x16, 7, buf)) {124 wmplugin_err(id, " unable to read wiimote info");118 if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NONE, &acc_cal)) { 119 wmplugin_err(id, "calibration error"); 125 120 return -1; 126 121 } 127 acc_zero.x = buf[0];128 acc_zero.y = buf[1];129 acc_zero.z = buf[2];130 acc_one.x = buf[4];131 acc_one.y = buf[5];132 acc_one.z = buf[6];133 122 134 123 return 0; … … 163 152 double roll, pitch; 164 153 165 a_x = (((double)mesg->acc[CWIID_X] - acc_zero.x) / 166 (acc_one.x - acc_zero.x))*NEW_AMOUNT + a_x*OLD_AMOUNT; 167 a_y = (((double)mesg->acc[CWIID_Y] - acc_zero.y) / 168 (acc_one.y - acc_zero.y))*NEW_AMOUNT + a_y*OLD_AMOUNT; 169 a_z = (((double)mesg->acc[CWIID_Z] - acc_zero.z) / 170 (acc_one.z - acc_zero.z))*NEW_AMOUNT + a_z*OLD_AMOUNT; 154 a_x = (((double)mesg->acc[CWIID_X] - acc_cal.zero[CWIID_X]) / 155 (acc_cal.one[CWIID_X] - acc_cal.zero[CWIID_X]))*NEW_AMOUNT + 156 a_x*OLD_AMOUNT; 157 a_y = (((double)mesg->acc[CWIID_Y] - acc_cal.zero[CWIID_Y]) / 158 (acc_cal.one[CWIID_Y] - acc_cal.zero[CWIID_Y]))*NEW_AMOUNT + 159 a_y*OLD_AMOUNT; 160 a_z = (((double)mesg->acc[CWIID_Z] - acc_cal.zero[CWIID_Z]) / 161 (acc_cal.one[CWIID_Z] - acc_cal.zero[CWIID_Z]))*NEW_AMOUNT + 162 a_z*OLD_AMOUNT; 171 163 172 164 a = sqrt(pow(a_x,2)+pow(a_y,2)+pow(a_z,2)); trunk/wminput/plugins/nunchuk_acc/nunchuk_acc.c
r101 r113 16 16 * 17 17 * ChangeLog: 18 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * use cwiid_get_acc_cal to get acc calibration values 20 * 18 21 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * updated for API overhaul … … 41 44 #define PI 3.14159265358979323 42 45 43 struct acc {44 uint8_t x;45 uint8_t y;46 uint8_t z;47 };48 49 46 static unsigned char info_init = 0; 50 47 static struct wmplugin_info info; … … 53 50 static cwiid_wiimote_t *wiimote; 54 51 55 static struct acc acc_zero, acc_one;52 static struct acc_cal acc_cal; 56 53 static int plugin_id; 57 54 … … 127 124 int i; 128 125 enum cwiid_ext_type ext_type = CWIID_EXT_NONE; 129 unsigned char buf[7];130 126 struct wmplugin_data *ret = NULL; 131 127 … … 135 131 if ((mesg[i]->status_mesg.ext_type == CWIID_EXT_NUNCHUK) && 136 132 (ext_type != CWIID_EXT_NUNCHUK)) { 137 if (cwiid_read(wiimote, CWIID_RW_REG | CWIID_RW_DECODE, 138 0xA40020, 7, buf)) { 139 wmplugin_err(plugin_id, "unable to read wiimote info"); 133 if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NUNCHUK, &acc_cal)) { 134 wmplugin_err(plugin_id, "calibration error"); 140 135 } 141 acc_zero.x = buf[0];142 acc_zero.y = buf[1];143 acc_zero.z = buf[2];144 acc_one.x = buf[4];145 acc_one.y = buf[5];146 acc_one.z = buf[6];147 136 } 148 137 ext_type = mesg[i]->status_mesg.ext_type; … … 169 158 double roll, pitch; 170 159 171 a_x = (((double)mesg->acc[CWIID_X] - acc_zero.x) / 172 (acc_one.x - acc_zero.x))*NEW_AMOUNT + a_x*OLD_AMOUNT; 173 a_y = (((double)mesg->acc[CWIID_Y] - acc_zero.y) / 174 (acc_one.y - acc_zero.y))*NEW_AMOUNT + a_y*OLD_AMOUNT; 175 a_z = (((double)mesg->acc[CWIID_Z] - acc_zero.z) / 176 (acc_one.z - acc_zero.z))*NEW_AMOUNT + a_z*OLD_AMOUNT; 160 a_x = (((double)mesg->acc[CWIID_X] - acc_cal.zero[CWIID_X]) / 161 (acc_cal.one[CWIID_X] - acc_cal.zero[CWIID_X]))*NEW_AMOUNT + 162 a_x*OLD_AMOUNT; 163 a_y = (((double)mesg->acc[CWIID_Y] - acc_cal.zero[CWIID_Y]) / 164 (acc_cal.one[CWIID_Y] - acc_cal.zero[CWIID_Y]))*NEW_AMOUNT + 165 a_y*OLD_AMOUNT; 166 a_z = (((double)mesg->acc[CWIID_Z] - acc_cal.zero[CWIID_Z]) / 167 (acc_cal.one[CWIID_Z] - acc_cal.zero[CWIID_Z]))*NEW_AMOUNT + 168 a_z*OLD_AMOUNT; 177 169 178 170 a = sqrt(pow(a_x,2)+pow(a_y,2)+pow(a_z,2));
