colorO.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #include <colorO.h>
00019 #include <ros/ros.h>
00020 
00021 ColorO::ColorO(SerialIO* serialIO)
00022 {
00023   _serialIO = serialIO;
00024 }
00025 
00026 ColorO::~ColorO()
00027 {
00028 }
00029 
00030 bool ColorO::init()
00031 {
00032   return true;
00033 }
00034 
00035 void ColorO::setColorMulti(std::vector<color::rgba> &colors)
00036 {
00037 
00038 }
00039 
00040 void ColorO::setColor(color::rgba color)
00041 {
00042   int bytes_wrote = 0;
00043 
00044   color::rgba color_tmp = color;
00045 
00046   //calculate rgb spektrum for spezific alpha value, because
00047   //led board is not supporting alpha values
00048   color.r *= color.a;
00049   color.g *= color.a;
00050   color.b *= color.a;
00051   //led board value spektrum is from 0 - 999.
00052   //at r@w's led strip, 0 means fully lighted and 999 light off(_invertMask)
00053   color.r = (fabs(_invertMask-color.r) * 999.0);
00054   color.g = (fabs(_invertMask-color.g) * 999.0);
00055   color.b = (fabs(_invertMask-color.b) * 999.0);
00056 
00057   _ssOut.clear();
00058   _ssOut.str("");
00059   _ssOut << (int)color.r << " " << (int)color.g << " " << (int)color.b << "\n\r";
00060 
00061   // send data over serial port
00062   bytes_wrote = _serialIO->sendData(_ssOut.str());
00063   if(bytes_wrote == -1)
00064   {
00065     ROS_WARN("Can not write to serial port. Port closed!");
00066   }
00067   else
00068   {
00069     ROS_DEBUG("Wrote [%s] with %i bytes from %i bytes", \
00070               _ssOut.str().c_str(), bytes_wrote, (int)_ssOut.str().length());
00071     m_sigColorSet(color_tmp);
00072   }
00073 }


cob_light
Author(s): Benjamin Maidel
autogenerated on Sat Jun 8 2019 21:02:07