示例#1
0
int setactive_mouse(usbdevice* kb, int active){
    if(NEEDS_FW_UPDATE(kb))
        return 0;
    uchar msg[2][MSG_SIZE] = {
        { 0x07, 0x04, 0 },                                                          // Disables or enables HW control for DPI and Sniper button
        { 0x07, 0x40, 0x08, 0,
          1, 0x80, 2, 0x80, 3, 0x80, 4, 0x80, 5, 0x80, 6, 0x80, 7, 0x80, 8, 0x80 }, // Enable button input. This is similar to the keyboard input selection, but we want everything to come through the HID reports.
    };
    if(active)
        // Put the mouse into SW mode
        msg[0][2] = 2;
    else
        // Restore HW mode
        msg[0][2] = 1;
    pthread_mutex_lock(imutex(kb));
    kb->active = !!active;
    kb->profile->lastlight.forceupdate = 1;
    // Clear input
    memset(&kb->input.keys, 0, sizeof(kb->input.keys));
    inputupdate(kb);
    pthread_mutex_unlock(imutex(kb));
    if(!usbsend(kb, msg[0], 1))
        return -1;
    if(active && !usbsend(kb, msg[1], 1))
        return -1;
    return 0;
}
示例#2
0
int cmd_hwsave_mouse(usbdevice* kb, usbmode* dummy1, int dummy2, int dummy3, const char* dummy4){
    DELAY_LONG(kb);
    hwprofile* hw = kb->hw;
    if(!hw)
        hw = kb->hw = calloc(1, sizeof(hwprofile));
    nativetohw(kb->profile, hw, 1);
    // Save the profile and mode names
    uchar data_pkt[2][MSG_SIZE] = {
        { 0x07, 0x16, 0x01, 0 },
        { 0x07, 0x15, 0x01, 0 },
    };
    for(int i = 0; i <= 1; i++){
        data_pkt[0][3] = i;
        memcpy(data_pkt[0] + 4, hw->name[i], MD_NAME_LEN * 2);
        if(!usbsend(kb, data_pkt[0], 1))
            return -1;
    }
    // Save the IDs
    for(int i = 0; i <= 1; i++){
        data_pkt[1][3] = i;
        memcpy(data_pkt[1] + 4, hw->id + i, sizeof(usbid));
        if(!usbsend(kb, data_pkt[1], 1))
            return -1;
    }
    // Save the RGB data for the non-DPI zones
    if(savergb_mouse(kb, hw->light, 0))
        return -1;
    // Save the DPI data (also saves RGB for those states)
    if(savedpi(kb, hw->dpi, hw->light))
        return -1;
    DELAY_LONG(kb);
    return 0;
}
示例#3
0
void servos()
{
int val=0;
caracter=usbread();
	switch(caracter) 
	{
	case '1':  
		val=10;
		break;
	case '2':
		val=11;  
		break;
	case '3':
		val=12;  
		break;
	case '4':
		val=8;  
		break;
	case '5': 
		val=9; 
		break;
	default:
		usbsend("error", 5);
		break;

	}
Delayms(10);	
caracter=' ';
caracter=usbread();
ServoWrite(val,caracter);
return;
}
示例#4
0
int updatergb_mouse(usbdevice* kb, int force){
    if(!kb->active)
        return 0;
    lighting* lastlight = &kb->profile->lastlight;
    lighting* newlight = &kb->profile->currentmode->light;
    // Don't do anything if the lighting hasn't changed
    if(!force && !lastlight->forceupdate && !newlight->forceupdate
            && !rgbcmp(lastlight, newlight))
        return 0;
    lastlight->forceupdate = newlight->forceupdate = 0;

    // Prevent writing to DPI LEDs or non-existent LED zones for the Glaive.
    int num_zones = IS_GLAIVE(kb) ? 3 : N_MOUSE_ZONES;
    // Send the RGB values for each zone to the mouse
    uchar data_pkt[2][MSG_SIZE] = {
        { 0x07, 0x22, num_zones, 0x01, 0 }, // RGB colors
        { 0x07, 0x05, 0x02, 0 }                 // Lighting on/off
    };
    uchar* rgb_data = &data_pkt[0][4];
    for(int i = 0; i < N_MOUSE_ZONES; i++){
        if (IS_GLAIVE(kb) && i != 0 && i != 1 && i != 5)
	    continue;
        *rgb_data++ = i + 1;
        *rgb_data++ = newlight->r[LED_MOUSE + i];
        *rgb_data++ = newlight->g[LED_MOUSE + i];
        *rgb_data++ = newlight->b[LED_MOUSE + i];
    }
    // Send RGB data
    if(!usbsend(kb, data_pkt[0], 1))
        return -1;
    int was_black = isblack(kb, lastlight), is_black = isblack(kb, newlight);
    if(is_black){
        // If the lighting is black, send the deactivation packet (M65 only)
        if(!usbsend(kb, data_pkt[1], 1))
            return -1;
    } else if(was_black || force){
        // If the lighting WAS black, or if we're on forced update, send the activation packet
        data_pkt[1][4] = 1;
        if(!usbsend(kb, data_pkt[1], 1))
            return -1;
    }

    memcpy(lastlight, newlight, sizeof(lighting));
    return 0;
}
示例#5
0
文件: led_mouse.c 项目: akosipc/ckb
int savergb_mouse(usbdevice* kb, lighting* light, int mode){
    uchar data_pkt[MSG_SIZE] = { 0x07, 0x13, 0x10, 1, 0 };
    // Zone 1
    data_pkt[4] = light->r[LED_MOUSE];
    data_pkt[5] = light->g[LED_MOUSE];
    data_pkt[6] = light->b[LED_MOUSE];
    if(!usbsend(kb, data_pkt, 1))
        return -1;
    // Zone 2
    data_pkt[2]++;
    data_pkt[4] = light->r[LED_MOUSE + 1];
    data_pkt[5] = light->g[LED_MOUSE + 1];
    data_pkt[6] = light->b[LED_MOUSE + 1];
    if(!usbsend(kb, data_pkt, 1))
        return -1;
    // TODO: zone 4 for Sabre?
    return 0;
}
示例#6
0
int cmd_pollrate(usbdevice* kb, usbmode* dummy1, int dummy2, int rate, const char* dummy3){
    uchar msg[MSG_SIZE] = {
        0x07, 0x0a, 0, 0, (uchar)rate
    };
    if(!usbsend(kb, msg, 1))
        return -1;
    // Device should disconnect+reconnect, but update the poll rate field in case it doesn't
    kb->pollrate = rate;
    return 0;
}
示例#7
0
文件: led_mouse.c 项目: akosipc/ckb
int updatergb_mouse(usbdevice* kb, int force){
    if(!kb->active)
        return 0;
    lighting* lastlight = &kb->profile->lastlight;
    lighting* newlight = &kb->profile->currentmode->light;
    // Don't do anything if the lighting hasn't changed
    if(!force && !lastlight->forceupdate && !newlight->forceupdate
            && !rgbcmp(lastlight, newlight))
        return 0;
    lastlight->forceupdate = newlight->forceupdate = 0;

    // Send the RGB values for each zone to the mouse
    uchar data_pkt[2][MSG_SIZE] = {
        { 0x07, 0x22, 0x04, 0x01, 0 },      // RGB colors
        { 0x07, 0x05, 0x02, 0 }             // Lighting on/off
    };
    uchar* rgb_data = &data_pkt[0][4];
    for(int i = 0; i < N_MOUSE_ZONES; i++){
        *rgb_data++ = i + 1;
        *rgb_data++ = newlight->r[LED_MOUSE + i];
        *rgb_data++ = newlight->g[LED_MOUSE + i];
        *rgb_data++ = newlight->b[LED_MOUSE + i];
    }
    int was_black = isblack(lastlight), is_black = isblack(newlight);
    // Send RGB data
    if(!usbsend(kb, data_pkt[0], 1))
        return -1;
    if(is_black){
        // If the lighting is black, send the deactivation packet
        if(!usbsend(kb, data_pkt[1], 1))
            return -1;
    } else if(was_black || force){
        // If the lighting WAS black, send the activation packet
        data_pkt[1][4] = 1;
        if(!usbsend(kb, data_pkt[1], 1))
            return -1;
    }

    memcpy(lastlight, newlight, sizeof(lighting));
    return 0;
}
示例#8
0
void loop()
{

if (usbavailable())
{
caracter=usbread();
	switch(caracter) 
	{
	case 'b':  
		usbsend("icaro", 5);
		break;
	case 'm':  
		servos();
		break;
	default:
		usbsend("error", 5);
		break;

	}
  Delayms(10);	
caracter=' ';
}

}
示例#9
0
void loop()
{
int valor[8];
int a=0;
u8 buf[80];
for(a=0;a<8;a++)
{
valor[a]=analogread(13+a);
Delayus(1);
}

sprintf(buf, " %i,%i,%i,%i,%i,%i,%i,%i\n\r", valor[0],valor[1],valor[2],valor[3],valor[4],valor[5],valor[6],valor[7]);

    usbsend(buf,39);
    Delayms(1);
}
示例#10
0
int savergb_mouse(usbdevice* kb, lighting* light, int mode){
    (void)mode;

    uchar data_pkt[MSG_SIZE] = { 0x07, 0x13, 0x10, 1, 0 };
    // Save each RGB zone, minus the DPI light which is sent in the DPI packets
    int zonecount = IS_SCIMITAR(kb) ? 4 : IS_SABRE(kb) ? 3 : 2;
    for(int i = 0; i < zonecount; i++){
        int led = LED_MOUSE + i;
        if(led >= LED_DPI)
            led++;          // Skip DPI light
        data_pkt[4] = light->r[led];
        data_pkt[5] = light->g[led];
        data_pkt[6] = light->b[led];
        if(!usbsend(kb, data_pkt, 1))
            return -1;
        // Set packet for next zone
        data_pkt[2]++;
    }
    return 0;
}