static void change_color(struct usb_dev_handle *handle, unsigned char *color) { unsigned char usb_data[] = { 0x10, 0x00, 0x80, 0x57, 0x00, 0x00, 0x00 }; usb_data[4] = get_hex8(color); usb_data[5] = get_hex8(color+2); usb_data[6] = get_hex8(color+4); usb_control_msg(handle, 0x34, 0x9, 0x210, 0x01, (char*)usb_data, 0x7, 5000); }
void parse_serial(void) { int a = (serial_buf[1] - '0'); if (a >= NACTIONS) a = 0; Action *ap = &action[a]; switch(serial_buf[0]) { case '+': // command '+': start action start_action(a); return; case '-': // command '-': stop action stop_action(a); return; case '=': // command '=': define action ap->i_active = false; // deactivate redefined action uchar i = 2; while (i < serial_len) switch(serial_buf[i++]) { case 'p': // p 0000 = pattern ap->d_pattern = get_hex16(serial_buf+i); i += 4; break; case 's': // s 0000 = speed ap->d_speed = get_hex16(serial_buf+i); i += 4; break; case 'l': // l 00 = length ap->d_length = get_hex8(serial_buf+i); i += 2; case 'o': // o 00 = override length ap->d_override = get_hex8(serial_buf+i); i += 2; break; case 'r': // r 00 = repeat ap->d_repeat = get_hex8(serial_buf+i); i += 2; break; case 'f': // f 000000 = fg color ap->d_color1[0] = get_hex8(serial_buf+i); ap->d_color1[1] = get_hex8(serial_buf+i+2); ap->d_color1[2] = get_hex8(serial_buf+i+4); i += 6; break; case 'b': // b 000000 = bg color ap->d_color0[0] = get_hex8(serial_buf+i); ap->d_color0[1] = get_hex8(serial_buf+i+2); ap->d_color0[2] = get_hex8(serial_buf+i+4); i += 6; break; case 'S': // S = soft ap->d_soft = true; break; case 'H': // H = hard ap->d_soft = false; break; case 'C': // C = clear {int j; for (j=0; j < sizeof(Action); j++) ((char *)ap)[i] = 0; break;} case 'A': // A = activate start_action(a); } } }
ushort get_hex16( uchar *p) // convert this hex string to unsigned integer { return (get_hex8(p) << 8) + get_hex8(p+2); }