flashMode.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 FLASHMODE_H
19 #define FLASHMODE_H
20 
21 #include <mode.h>
22 
23 class FlashMode : public Mode
24 {
25 public:
26  FlashMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27  :Mode(priority, freq, pulses, timeout), _toggle(false), _timer_inc(0)
28  {
29  _color = color;
30  if(_pulses != 0)
31  {
32  _pulses *=2;
33  _pulses +=1;
34  }
35  _inc = (1. / UPDATE_RATE_HZ) * _freq;
36  }
37 
38  void execute()
39  {
40  color::rgba col;
41  col.r = _color.r;
42  col.g = _color.g;
43  col.b = _color.b;
44  if(_timer_inc >= 1.0)
45  {
46  col.a = _color.a * (int)_toggle;
47  _pulsed++;
48  _toggle = !_toggle;
49  m_sigColorReady(col);
50  _timer_inc = 0.0;
51  }
52  else
53  _timer_inc += _inc;
54  }
55 
56  std::string getName(){ return std::string("FlashMode"); }
57 
58 private:
59  bool _toggle;
60  double _timer_inc;
61  double _inc;
62 };
63 
64 #endif
color::rgba _color
Definition: mode.h:121
std::string getName()
Definition: flashMode.h:56
double _inc
Definition: flashMode.h:61
Definition: mode.h:26
int _pulsed
Definition: mode.h:119
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
bool _toggle
Definition: flashMode.h:59
double _freq
Definition: mode.h:114
void execute()
Definition: flashMode.h:38
boost::signals2::signal< void(color::rgba color)> m_sigColorReady
Definition: mode.h:128
FlashMode(color::rgba color, int priority=0, double freq=0.25, int pulses=0, double timeout=0)
Definition: flashMode.h:26
double _timer_inc
Definition: flashMode.h:60
int _pulses
Definition: mode.h:115


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