common
include
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
{
41
_colors
[
_num_leds
/2] =
_startcolor
;
42
_colors
[
_num_leds
/2-1] =
_startcolor
;
43
}
44
else
45
_colors
[
_num_leds
/2] =
_startcolor
;
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
++;
71
m_sigColorsReady
(
_colors
);
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
;
86
color::rgba
_startcolor
;
87
};
88
89
#endif
SweepColorMode::_inc
double _inc
Definition:
sweepColorMode.h:83
mode.h
Mode::_colors
std::vector< color::rgba > _colors
Definition:
mode.h:122
SweepColorMode::_toggle
bool _toggle
Definition:
sweepColorMode.h:81
SweepColorMode
Definition:
sweepColorMode.h:24
color::rgba
Definition:
colorUtils.h:26
Mode::m_sigColorsReady
boost::signals2::signal< void(std::vector< color::rgba > &colors)> m_sigColorsReady
Definition:
mode.h:129
SweepColorMode::execute
void execute()
Definition:
sweepColorMode.h:51
color::rgba::g
float g
Definition:
colorUtils.h:30
SweepColorMode::_num_leds
size_t _num_leds
Definition:
sweepColorMode.h:84
Mode::UPDATE_RATE_HZ
static const unsigned int UPDATE_RATE_HZ
Definition:
mode.h:126
color::rgba::b
float b
Definition:
colorUtils.h:31
SweepColorMode::_timer_inc
double _timer_inc
Definition:
sweepColorMode.h:82
Mode
Definition:
mode.h:26
color::rgba::r
float r
Definition:
colorUtils.h:29
SweepColorMode::_startcolor
color::rgba _startcolor
Definition:
sweepColorMode.h:86
SweepColorMode::SweepColorMode
SweepColorMode(std::vector< color::rgba > colors, size_t num_leds, int priority=0, double freq=5, int pulses=0, double timeout=0)
Definition:
sweepColorMode.h:27
Mode::_pulsed
int _pulsed
Definition:
mode.h:119
SweepColorMode::getName
std::string getName()
Definition:
sweepColorMode.h:78
color::rgba::a
float a
Definition:
colorUtils.h:32
SweepColorMode::_pos
int _pos
Definition:
sweepColorMode.h:85
Mode::_freq
double _freq
Definition:
mode.h:114
cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Nov 8 2023 03:47:37