Changeset 130
- Timestamp:
- 06/28/07 18:25:39 (2 years ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/wminput/plugins/ir_ptr/ir_ptr.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r128 r130 1 2007-06-27 L. Donnie Smith <cwiid@abstrakraft.org> 2 wminput 3 * rewrote ir_ptr plugin 4 5 libcwiid 6 * changed version 7 1 8 2007-06-18 L. Donnie Smith <cwiid@abstrakraft.org> 2 9 wminput trunk/wminput/plugins/ir_ptr/ir_ptr.c
r125 r130 16 16 * 17 17 * ChangeLog: 18 * 2007-06-28 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * Converted to single source 20 * * Added deadspace at edges 21 * 18 22 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * updated for wmplugin_exec prototype change (&mesg->mesg) … … 45 49 #include "wmplugin.h" 46 50 51 #define DEBOUNCE_THRESHOLD 50 52 #define NEW_AMOUNT 0.3 53 #define OLD_AMOUNT (1.0 - NEW_AMOUNT) 54 #define X_EDGE 50 55 #define Y_EDGE 50 56 47 57 cwiid_wiimote_t *wiimote; 48 58 49 struct cursor {50 unsigned char valid;51 uint16_t pos[2];52 };53 int a_debounce, b_debounce;54 55 /* static objects are initialized to 0 by default */56 static int a_index = -1, b_index = -1;57 static struct cwiid_ir_src a, b, prev_a, prev_b;58 59 static unsigned char info_init = 0;60 59 static struct wmplugin_info info; 61 60 static struct wmplugin_data data; 62 63 static struct cursor c, prev_c;64 61 65 62 wmplugin_info_t wmplugin_info; … … 68 65 69 66 struct wmplugin_info *wmplugin_info() { 67 static unsigned char info_init = 0; 68 70 69 if (!info_init) { 71 70 info.button_count = 0; … … 73 72 info.axis_info[0].name = "X"; 74 73 info.axis_info[0].type = WMPLUGIN_ABS; 75 info.axis_info[0].max = 1024;76 info.axis_info[0].min = 0;74 info.axis_info[0].max = CWIID_IR_X_MAX - X_EDGE; 75 info.axis_info[0].min = X_EDGE; 77 76 info.axis_info[0].fuzz = 0; 78 77 info.axis_info[0].flat = 0; 79 78 info.axis_info[1].name = "Y"; 80 79 info.axis_info[1].type = WMPLUGIN_ABS; 81 info.axis_info[1].max = 768;82 info.axis_info[1].min = 0;80 info.axis_info[1].max = CWIID_IR_Y_MAX - Y_EDGE; 81 info.axis_info[1].min = Y_EDGE; 83 82 info.axis_info[1].fuzz = 0; 84 83 info.axis_info[1].flat = 0; … … 104 103 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) 105 104 { 105 static int src_index = -1; 106 static int debounce = 0; 107 static uint8_t old_flag; 108 106 109 int i; 107 uint8_t flags; 108 static uint8_t old_flags; 110 uint8_t flag; 109 111 struct cwiid_ir_mesg *ir_mesg; 110 112 … … 120 122 } 121 123 122 /* update history*/123 prev_a = a;124 prev_b = b;125 prev_c = c;126 127 /* invalidate a & b indices if sources are no longer present */128 if ((a_index != -1) && (!ir_mesg->src[a_index].valid)) {129 a_index = -1;124 /* invalidate src index if source is no longer present */ 125 if ((src_index != -1) && !ir_mesg->src[src_index].valid) { 126 if (debounce > DEBOUNCE_THRESHOLD) { 127 src_index = -1; 128 } 129 else { 130 debounce++; 131 } 130 132 } 131 if ((b_index != -1) && (!ir_mesg->src[b_index].valid)){132 b_index = -1;133 else { 134 debounce = 0; 133 135 } 134 136 135 /* of not set, pick largest available source for a & b*/136 if ( a_index == -1) {137 /* of not set, pick largest available source */ 138 if (src_index == -1) { 137 139 for (i=0; i < CWIID_IR_SRC_COUNT; i++) { 138 if ((ir_mesg->src[i].valid) && (i != b_index)) { 139 if ((a_index == -1) || 140 (ir_mesg->src[i].size > ir_mesg->src[a_index].size)) { 141 a_index = i; 142 } 143 } 144 } 145 } 146 /* if there is no current src_b, pick the largest valid one */ 147 if (b_index == -1) { 148 for (i=0; i < CWIID_IR_SRC_COUNT; i++) { 149 if ((ir_mesg->src[i].valid) && (i != a_index)) { 150 if ((b_index == -1) || 151 (ir_mesg->src[i].size > ir_mesg->src[b_index].size)) { 152 b_index = i; 140 if (ir_mesg->src[i].valid) { 141 if ((src_index == -1) || 142 (ir_mesg->src[i].size > ir_mesg->src[src_index].size)) { 143 src_index = i; 153 144 } 154 145 } … … 156 147 } 157 148 158 #define DEBOUNCE_THRESHOLD 50 149 /* LEDs */ 150 switch (src_index) { 151 case 0: 152 flag = CWIID_LED1_ON; 153 break; 154 case 1: 155 flag = CWIID_LED2_ON; 156 break; 157 case 2: 158 flag = CWIID_LED3_ON; 159 break; 160 case 3: 161 flag = CWIID_LED4_ON; 162 break; 163 default: 164 flag = 0; 165 break; 166 } 167 if (flag != old_flag) { 168 cwiid_set_led(wiimote, flag); 169 old_flag = flag; 170 } 159 171 160 /* set a & b, mirror the x coordinates */ 161 if (a_index == -1) { 162 a_debounce++; 163 if( a_debounce > DEBOUNCE_THRESHOLD ) { 164 a.valid = 0; 172 if ((src_index == -1) || !ir_mesg->src[src_index].valid) { 173 data.axes[0].valid = data.axes[1].valid = 0; 174 } 175 else { 176 data.axes[0].valid = data.axes[1].valid = 1; 177 data.axes[0].value = NEW_AMOUNT * (CWIID_IR_X_MAX - 178 ir_mesg->src[src_index].pos[CWIID_X]) 179 + OLD_AMOUNT * data.axes[0].value; 180 data.axes[1].value = NEW_AMOUNT * ir_mesg->src[src_index].pos[CWIID_Y] 181 + OLD_AMOUNT * data.axes[1].value; 182 183 if (data.axes[0].value > CWIID_IR_X_MAX - X_EDGE) { 184 data.axes[0].value = CWIID_IR_X_MAX - X_EDGE; 165 185 } 166 else { 167 a = prev_a; 186 else if (data.axes[0].value < X_EDGE) { 187 data.axes[0].value = X_EDGE; 188 } 189 if (data.axes[1].value > CWIID_IR_Y_MAX - Y_EDGE) { 190 data.axes[1].value = CWIID_IR_Y_MAX - Y_EDGE; 191 } 192 else if (data.axes[1].value < Y_EDGE) { 193 data.axes[1].value = Y_EDGE; 168 194 } 169 195 } 170 else {171 a = ir_mesg->src[a_index];172 a.pos[CWIID_X] = CWIID_IR_X_MAX - a.pos[CWIID_X];173 a_debounce = 0;174 }175 if (b_index == -1) {176 b_debounce++;177 if( b_debounce > DEBOUNCE_THRESHOLD ) {178 b.valid = 0;179 }180 else {181 b = prev_b;182 }183 }184 else {185 b = ir_mesg->src[b_index];186 b.pos[CWIID_X] = CWIID_IR_X_MAX - b.pos[CWIID_X];187 b_debounce = 0;188 }189 190 /* if both sources are valid, calculate the center */191 if (a.valid && b.valid) {192 c.valid = 1;193 for (i=0; i < 2; i++) {194 c.pos[i] = (a.pos[i] + b.pos[i])/2;195 }196 }197 /* if either source is valid, use best guess */198 else if (a.valid) {199 /* if a isn't new, and we have a previous center,200 * assume source-center relationship holds */201 if (prev_a.valid && prev_c.valid) {202 c.valid = 1;203 for (i=0; i < 2; i++) {204 c.pos[i] = a.pos[i] + (prev_c.pos[i] - prev_a.pos[i]);205 }206 }207 /* if a is new or we don't have a previous center,208 * use a as the center */209 else {210 c.valid = 1;211 for (i=0; i < 2; i++) {212 c.pos[i] = a.pos[i];213 }214 }215 }216 else if (b.valid) {217 /* if b isn't new, and we have a previous center,218 * assume source-center relationship holds */219 if (prev_b.valid && prev_c.valid) {220 c.valid = 1;221 for (i=0; i < 2; i++) {222 c.pos[i] = b.pos[i] + (prev_c.pos[i] - prev_b.pos[i]);223 }224 }225 /* if b is new or we don't have a previous center,226 * use b as the center */227 else {228 c.valid = 1;229 for (i=0; i < 2; i++) {230 c.pos[i] = b.pos[i];231 }232 }233 }234 /* no sources, no guesses */235 else {236 c.valid = 0;237 }238 239 /* LEDs */240 flags = 0;241 if ((a_index == 1) || (b_index == 1)) {242 flags |= CWIID_LED1_ON;243 }244 else if ((a_index == 2) || (b_index == 2)) {245 flags |= CWIID_LED2_ON;246 }247 else if ((a_index == 3) || (b_index == 3)) {248 flags |= CWIID_LED3_ON;249 }250 else if ((a_index == 4) || (b_index == 4)) {251 flags |= CWIID_LED4_ON;252 }253 if (flags != old_flags) {254 cwiid_set_led(wiimote, flags);255 }256 old_flags = flags;257 258 data.axes[0].valid = data.axes[1].valid = c.valid;259 260 #define NEW_AMOUNT 0.6261 #define OLD_AMOUNT (1.0-NEW_AMOUNT)262 263 data.axes[0].value = c.pos[CWIID_X]*NEW_AMOUNT +264 data.axes[0].value*OLD_AMOUNT;265 data.axes[1].value = c.pos[CWIID_Y]*NEW_AMOUNT +266 data.axes[1].value*OLD_AMOUNT;267 196 268 197 return &data;
