ledcom.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <time.h>
00004 #include <unistd.h>
00005 #include <string.h>
00006 #include "ros/ros.h"
00007 #include "serial/serial.h"
00008 #include "rgbhsv.h"
00009 
00010 class LedCOM{
00011   private:
00012     static const uint8_t CLEAR_MSG[1];
00013     static const uint8_t FLUSH_MSG[1];
00014     serial::Serial* serial_conn;
00015     void write(const uint8_t[], uint32_t);
00016 
00017   public:
00018     void connect(const std::string, const unsigned long);
00019     void setRGB(const uint8_t, const uint8_t, const uint8_t, const uint8_t);
00020     void setHSV(const uint8_t, float, float, float);
00021     void clear();
00022     void flush();
00023     void setLEDCount(const uint8_t);
00024 };
00025 
00026 const uint8_t LedCOM::CLEAR_MSG[] = {'c'};
00027 const uint8_t LedCOM::FLUSH_MSG[] = {'f'};
00028 
00029 void LedCOM::write(const uint8_t data[], const uint32_t data_size) {
00030   serial_conn->write(data, data_size);
00031   serial_conn->flushOutput();
00032 }
00033 
00034 void LedCOM::connect(const std::string port, const unsigned long baud) {
00035   serial_conn = new serial::Serial(port, baud, serial::Timeout::simpleTimeout(1000));
00036 }
00037 
00038 void LedCOM::setRGB(const uint8_t index, const uint8_t r, const uint8_t g, const uint8_t b){
00039   uint8_t data[] = {'s',r,g,b,index};
00040   write(data, 5);
00041 }
00042 
00043 void LedCOM::setHSV(const uint8_t index, float h, float s, float v) {
00044   float rf, gf, bf;
00045 
00046   HSVtoRGB(rf,gf,bf,h,s,v);
00047 
00048   uint8_t r = 255 * rf;
00049   uint8_t g = 255 * gf;
00050   uint8_t b = 255 * bf;
00051 
00052   uint8_t data[] = {'s',r,g,b,index};
00053   write(data, 5);
00054 }
00055 
00056 void LedCOM::clear() { write(CLEAR_MSG, 1); }
00057 
00058 void LedCOM::flush() { write(FLUSH_MSG, 1); }
00059 
00060 void LedCOM::setLEDCount(const uint8_t led_count) {
00061   uint8_t data[] = {'l',led_count};
00062   write(data, 2);
00063 }


segbot_led
Author(s): Pato Lankenau , Rolando Fernandez
autogenerated on Thu Jun 6 2019 21:37:07