fadeColorMode.h
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 #ifndef FADECOLORMODE_H
00019 #define FADECOLORMODE_H
00020 
00021 #include <mode.h>
00022 
00023 class FadeColorMode : public Mode
00024 {
00025 public:
00026         FadeColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
00027                 :Mode(priority, freq, pulses, timeout)
00028         {
00029                 _color = color;
00030 
00031                 doOnce = true;
00032                 h = 0.0;
00033                 h_s = 0.0;
00034                 h_t = 0.0;
00035 
00036                 _inc = (1. / UPDATE_RATE_HZ) * _freq;
00037         }
00038 
00039         void execute()
00040         {
00041                 float r = 0;
00042                 float g = 0;
00043                 float b = 0;
00044                 float s, v;
00045 
00046                 if(doOnce == true)
00047                 {
00048                         color::Color::rgb2hsv(_color.r, _color.g, _color.b, h, s, v);
00049                         h_s = h;
00050                         h_t = h;
00051                         h_s += 1;
00052                         doOnce = false;
00053                 }
00054 
00055                 color::Color::hsv2rgb(h, 1.0, 1.0, r, g, b);
00056 
00057                 h += _inc;
00058                 h_t += _inc;
00059                 if(h > 1.0)
00060                         h = 0.0;
00061 
00062                 if(h_t >= h_s)
00063                 {
00064                         _pulsed++; h_s+=1;
00065                 }
00066 
00067                 color::rgba col;
00068                 col.r = r;
00069                 col.g = g;
00070                 col.b = b;
00071                 col.a = _color.a;
00072 
00073                 m_sigColorReady(col);
00074         }
00075 
00076         std::string getName(){ return std::string("FadeColorMode"); }
00077 
00078 private:
00079         bool doOnce;
00080         float h;
00081         float h_s;
00082         float h_t;
00083         double _inc;
00084 };
00085 
00086 #endif


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