Skip to content

Instantly share code, notes, and snippets.

/gist:4446906
Created Jan 3, 2013

Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "hidapi.h"
#define PPVIP 0x0e8f
#define PPPID 0x0025
// 1 byte for for report id
// 2 bytes for packets marker
// next 30 bytes for 10 channels in RGB (0 ... 255)
#define PPBUFFERSIZE 33
#define PPCAPZONES 10
unsigned char buffer[PPBUFFERSIZE];
// set zone RGB color in buffer
int pp_setzone(int zone, unsigned char r, unsigned char g, unsigned char b) {
if (zone > PPCAPZONES) return 1;
int z = zone * 3 - 1;
buffer[++z] = r;
buffer[++z] = g;
buffer[++z] = b;
return 0;
}
// put paintpack into the bootloader mode
int pp_bootloader (hid_device *handle) {
buffer[1] = 15;
pp_setzone(1, 1, 2, 3);
pp_setzone(2, 4, 5, 6);
return hid_write(handle, buffer, sizeof(buffer));
}
// send color update buffer to the device
int pp_sendzones(hid_device *handle) {
buffer[1] = 3;
return hid_write(handle, buffer, sizeof(buffer));
}
// turn off all lights
void pp_blackout() {
for (int zone=1; zone <= PPCAPZONES; zone++) {
pp_setzone(zone, 0, 0, 0);
}
}
int main(int argc, char const *argv[])
{
hid_device *handle;
handle = hid_open(PPVIP, PPPID, NULL);
if (handle == NULL) {
return 1;
}
pp_setzone(1, 255, 0, 0);
pp_sendzones(handle);
sleep(1);
pp_setzone(1, 0, 255, 0);
pp_sendzones(handle);
sleep(1);
pp_setzone(1, 0, 0, 255);
pp_sendzones(handle);
sleep(1);
pp_blackout();
pp_sendzones(handle);
hid_close(handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.