sweepColorMode.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 SWEEPCOLORMODE_H
19 #define SWEEPCOLORMODE_H
20 
21 #include <mode.h>
22 #include <algorithm>
23 
24 class SweepColorMode : public Mode
25 {
26 public:
27  SweepColorMode(std::vector<color::rgba> colors, size_t num_leds, int priority = 0, double freq = 5, int pulses = 0, double timeout = 0)
28  :Mode(priority, freq, pulses, timeout), _toggle(false), _timer_inc(0), _num_leds(num_leds)
29  {
30  _colors = colors;
31 
32  _startcolor.r = 0.0;
33  _startcolor.g = 0.4;
34  _startcolor.b = 0.28;
35  _startcolor.a = 1.0;
36  if(_colors.size() == 1)
37  _startcolor = _colors[0];
38  _colors.resize(_num_leds);
39  if(_num_leds%2 == 0)
40  {
43  }
44  else
46  _pos = 0;
47 
48  _inc = (1. / UPDATE_RATE_HZ) * _freq;
49  }
50 
51  void execute()
52  {
53  if(_timer_inc >= 1.0)
54  {
55  for(int i = _num_leds/2; i < _num_leds; i++)
56  {
57  _colors[i].a *= 0.7;
58  }
59  for(int i = _num_leds/2-1; i >= 0; i--)
60  {
61  _colors[i].a *= 0.7;
62  }
63  _colors[(_num_leds/2)+_pos] = _startcolor;
64  _colors[(_num_leds/2)-1-_pos] = _startcolor;
65 
66  _pos++;
67  if(_pos >= (_num_leds/2))
68  _pos = 0;
69 
70  _pulsed++;
72  _timer_inc = 0.0;
73  }
74  else
75  _timer_inc += _inc;
76  }
77 
78  std::string getName(){ return std::string("SweepColorMode"); }
79 
80 private:
81  bool _toggle;
82  double _timer_inc;
83  double _inc;
84  size_t _num_leds;
85  int _pos;
87 };
88 
89 #endif
SweepColorMode(std::vector< color::rgba > colors, size_t num_leds, int priority=0, double freq=5, int pulses=0, double timeout=0)
std::vector< color::rgba > _colors
Definition: mode.h:122
Definition: mode.h:26
int _pulsed
Definition: mode.h:119
std::string getName()
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
color::rgba _startcolor
double _freq
Definition: mode.h:114
boost::signals2::signal< void(std::vector< color::rgba > &colors)> m_sigColorsReady
Definition: mode.h:129


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