fadeColorMode.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef FADECOLORMODE_H
19 #define FADECOLORMODE_H
20 
21 #include <mode.h>
22 
23 class FadeColorMode : public Mode
24 {
25 public:
26  FadeColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27  :Mode(priority, freq, pulses, timeout)
28  {
29  _color = color;
30 
31  doOnce = true;
32  h = 0.0;
33  h_s = 0.0;
34  h_t = 0.0;
35 
36  _inc = (1. / UPDATE_RATE_HZ) * _freq;
37  }
38 
39  void execute()
40  {
41  float r = 0;
42  float g = 0;
43  float b = 0;
44  float s, v;
45 
46  if(doOnce == true)
47  {
49  h_s = h;
50  h_t = h;
51  h_s += 1;
52  doOnce = false;
53  }
54 
55  color::Color::hsv2rgb(h, 1.0, 1.0, r, g, b);
56 
57  h += _inc;
58  h_t += _inc;
59  if(h > 1.0)
60  h = 0.0;
61 
62  if(h_t >= h_s)
63  {
64  _pulsed++; h_s+=1;
65  }
66 
67  color::rgba col;
68  col.r = r;
69  col.g = g;
70  col.b = b;
71  col.a = _color.a;
72 
73  m_sigColorReady(col);
74  }
75 
76  std::string getName(){ return std::string("FadeColorMode"); }
77 
78 private:
79  bool doOnce;
80  float h;
81  float h_s;
82  float h_t;
83  double _inc;
84 };
85 
86 #endif
std::string getName()
Definition: fadeColorMode.h:76
color::rgba _color
Definition: mode.h:121
static void rgb2hsv(float r, float g, float b, float &h, float &s, float &v)
Definition: colorUtils.h:54
Definition: mode.h:26
XmlRpcServer s
int _pulsed
Definition: mode.h:119
static void hsv2rgb(float h, float s, float v, float &r, float &g, float &b)
Definition: colorUtils.h:81
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
FadeColorMode(color::rgba color, int priority=0, double freq=0.25, int pulses=0, double timeout=0)
Definition: fadeColorMode.h:26
double _freq
Definition: mode.h:114
boost::signals2::signal< void(color::rgba color)> m_sigColorReady
Definition: mode.h:128


cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Apr 7 2021 02:11:39