/** * Write device file "set_key_row" * * Writes the colour rows on the keyboard. Takes in all the colours for the keyboard */ static ssize_t razer_attr_write_set_key_row(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { size_t offset = 0; unsigned char row_index; struct usb_interface *intf = to_usb_interface(dev->parent); struct usb_device *usb_dev = interface_to_usbdev(intf); size_t buf_size = RAZER_BLACKWIDOW_CHROMA_ROW_LEN * 3 + 1; while(offset < count) { if((count-offset) < buf_size) { printk(KERN_ALERT "Wrong Amount of RGB data provided: %d of %d\n",(int)(count-offset), (int)buf_size); return -EINVAL; } row_index = (unsigned char)buf[offset]; razer_set_key_row(usb_dev, row_index, (unsigned char*)&buf[offset + 1]); offset += buf_size; } return count; }
static ssize_t razer_attr_write_set_key_row(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct usb_interface *intf = to_usb_interface(dev->parent); //struct razer_kbd_device *widow = usb_get_intfdata(intf); struct usb_device *usb_dev = interface_to_usbdev(intf); size_t buf_size = (RAZER_BLACKWIDOW_CHROMA_ROW_LEN+1)*3 + 1; //printk(KERN_ALERT "sizeof(razer_row_rgb): %d\n",sizeof(struct razer_row_rgb)); size_t offset = 0; while(offset<count) { unsigned char row_index = (unsigned char)buf[offset]; if(count-offset < buf_size) { printk(KERN_ALERT "Wrong Amount of RGB data provided: %d of %d\n",(int)count,(int)buf_size); return 0; } razer_set_key_row(usb_dev,row_index,(struct razer_row_rgb*)&buf[offset+1]); offset += buf_size; } return count; }