3 #include "pixyinterpreter.hpp" 
   74   } PIXY_ERROR_TABLE[] = {
 
   76     { PIXY_ERROR_USB_IO,          
"USB Error: I/O" },
 
   77     { PIXY_ERROR_USB_BUSY,        
"USB Error: Busy" },
 
   78     { PIXY_ERROR_USB_NO_DEVICE,   
"USB Error: No device" },
 
   79     { PIXY_ERROR_USB_NOT_FOUND,   
"USB Error: Target not found" },
 
   80     { PIXY_ERROR_CHIRP,           
"Chirp Protocol Error" },
 
   81     { PIXY_ERROR_INVALID_COMMAND, 
"Pixy Error: Invalid command" },
 
   85   static int pixy_initialized = 
false;
 
   95       pixy_initialized = 
true;
 
  116     if(!pixy_initialized) 
return -1;
 
  118     va_start(arguments, name);
 
  119     return_value = 
interpreter.send_command(name, arguments);
 
  127     if(!pixy_initialized) 
return;
 
  140     while(PIXY_ERROR_TABLE[index].
text != 0) {
 
  142       if(PIXY_ERROR_TABLE[index].
error == error_code) {
 
  143         printf(
"%s\n", PIXY_ERROR_TABLE[index].
text);
 
  150     printf(
"Undefined error: [%d]\n", error_code);
 
  160     RGB = blue + (green << 8) + (red << 16);
 
  162     return_value = 
pixy_command(
"led_set", CRP_INT32, RGB, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  172     return_value = 
pixy_command(
"led_setMaxCurrent", CRP_INT32, current, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  180     uint32_t chirp_response;
 
  182     return_value = 
pixy_command(
"led_getMaxCurrent", END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  184     if (return_value < 0) {
 
  189       return chirp_response;
 
  196     uint32_t chirp_response;
 
  198     return_value = 
pixy_command(
"cam_setAWB", CRP_UINT8, enable, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  206     uint32_t chirp_response;
 
  208     return_value = 
pixy_command(
"cam_getAWB", END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  210     if (return_value < 0) {
 
  215       return chirp_response;
 
  222     uint32_t chirp_response;
 
  224     return_value = 
pixy_command(
"cam_getWBV", END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  226     return chirp_response;
 
  232     uint32_t chirp_response;
 
  233     uint32_t white_balance;
 
  235     white_balance = green + (red << 8) + (blue << 16);
 
  237     return_value = 
pixy_command(
"cam_setAWB", CRP_UINT32, white_balance, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  245     uint32_t chirp_response;
 
  247     return_value = 
pixy_command(
"cam_setAEC", CRP_UINT8, enable, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  255     uint32_t chirp_response;
 
  257     return_value = 
pixy_command(
"cam_getAEC", END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  259     if (return_value < 0) {
 
  264       return chirp_response;
 
  271     uint32_t chirp_response;
 
  274     exposure = gain + (compensation << 8);
 
  276     return_value = 
pixy_command(
"cam_setECV", CRP_UINT32, exposure, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  286     return_value = 
pixy_command(
"cam_getECV", END_OUT_ARGS, &exposure, END_IN_ARGS);
 
  288     if (return_value < 0) {
 
  293     if(gain == 0 || compensation == 0) {
 
  295       return PIXY_ERROR_INVALID_PARAMETER;
 
  298     printf(
"exp:%08x\n", exposure);
 
  300     *gain         = exposure & 0xFF;
 
  301     *compensation = 0xFFFF & (exposure >> 8);
 
  311     return_value = 
pixy_command(
"cam_setBrightness", CRP_INT8, brightness, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  321     return_value = 
pixy_command(
"cam_getBrightness", END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  323     if (return_value < 0) {
 
  328       return chirp_response;
 
  337     return_value = 
pixy_command(
"rcs_getPos", CRP_INT8, channel, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  339     if (return_value < 0) {
 
  344       return chirp_response;
 
  353     if(channel > 1 || position > 999) {
 
  354       return PIXY_ERROR_INVALID_PARAMETER;
 
  357     return_value = 
pixy_command(
"rcs_setPos", CRP_INT8, channel, CRP_INT16, position, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  367     if(frequency < 20 || frequency > 300) {
 
  368       return PIXY_ERROR_INVALID_PARAMETER;
 
  371     return_value = 
pixy_command(
"rcs_setFreq", CRP_INT16, frequency, END_OUT_ARGS, &chirp_response, END_IN_ARGS);
 
  378     uint16_t * pixy_version;
 
  379     uint32_t   version_length;
 
  385     if(major == 0 || minor == 0 || build == 0) {
 
  387       return PIXY_ERROR_INVALID_PARAMETER;
 
  390     return_value = 
pixy_command(
"version",  END_OUT_ARGS, &response, &version_length, &pixy_version, END_IN_ARGS);
 
  392     if (return_value < 0) {
 
  397     memcpy((
void *) version, pixy_version, 3 * 
sizeof(uint16_t));
 
int pixy_rcs_set_frequency(uint16_t frequency)
Set pixy servo pulse width modulation (PWM) frequency. 
int pixy_cam_get_exposure_compensation(uint8_t *gain, uint16_t *compensation)
Get pixy camera exposure compensation. 
int pixy_get_blocks(uint16_t max_blocks, struct Block *blocks)
Copies up to 'max_blocks' number of Blocks to the address pointed to by 'blocks'. ...
void pixy_close()
Terminates connection with Pixy. 
int pixy_rcs_get_position(uint8_t channel)
Get pixy servo axis position. 
int pixy_cam_get_auto_white_balance()
Get pixy camera auto white balance setting. 
void pixy_error(int error_code)
Send description of pixy error to stdout. 
int pixy_cam_set_white_balance_value(uint8_t red, uint8_t green, uint8_t blue)
Set pixy camera white balance. 
int pixy_cam_set_auto_white_balance(uint8_t enable)
Enable or disable pixy camera auto white balance. 
int pixy_led_set_max_current(uint32_t current)
Set pixy LED maximum current. 
int pixy_led_get_max_current()
Get pixy LED maximum current. 
int pixy_init()
Creates a connection with Pixy and listens for Pixy messages. 
PixyInterpreter interpreter
int pixy_blocks_are_new()
Indicates when new block data from Pixy is received. 
int pixy_rcs_set_position(uint8_t channel, uint16_t position)
Set pixy servo axis position. 
int pixy_get_firmware_version(uint16_t *major, uint16_t *minor, uint16_t *build)
Get pixy firmware version. 
int pixy_cam_get_brightness()
Get pixy camera brightness. 
int pixy_cam_set_brightness(uint8_t brightness)
Set pixy camera brightness. 
int pixy_cam_set_exposure_compensation(uint8_t gain, uint16_t compensation)
Set pixy camera exposure compensation. 
int pixy_led_set_RGB(uint8_t red, uint8_t green, uint8_t blue)
Set color of pixy LED. 
int pixy_cam_set_auto_exposure_compensation(uint8_t enable)
Enable or disable pixy camera auto exposure compensation. 
int pixy_cam_get_auto_exposure_compensation()
Get pixy camera auto exposure compensation setting. 
int pixy_command(const char *name,...)
Send a command to Pixy. 
uint32_t pixy_cam_get_white_balance_value()
Get pixy camera white balance()