common
include
xmasMode.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 XMASMODE_H
19
#define XMASMODE_H
20
21
#include <
mode.h
>
22
#include <algorithm>
23
24
class
XMasMode
:
public
Mode
25
{
26
public
:
27
XMasMode
(
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),
_chucksize
(5)
29
{
30
_colors
.resize(num_leds);
31
if
(
_num_leds
>=
_chucksize
*2)
32
{
33
int
n_chunks =
_num_leds
/
_chucksize
+ (
_num_leds
%
_chucksize
? 1 : 0);
34
int
k = 0;
35
for
(
int
i = 0; i < n_chunks; i++)
36
{
37
for
(
int
j = 0; j <
_chucksize
; j++)
38
{
39
if
(k >=
_num_leds
)
40
break
;
41
if
(i%2 == 0)
42
{
43
_colors
.at(k).r = 1.0;
_colors
.at(k).g = 0.0;
_colors
.at(k).b = 0.0;
_colors
.at(k).a = 1.0;
44
}
45
else
46
{
47
_colors
.at(k).r = 1.0;
_colors
.at(k).g = 1.0;
_colors
.at(k).b = 1.0;
_colors
.at(k).a = 1.0;
48
}
49
k++;
50
}
51
}
52
}
53
else
54
{
55
for
(
int
i = 0; i <
_num_leds
; i++)
56
{
57
if
(i%2==0)
58
{
59
_colors
.at(i).r = 1.0;
_colors
.at(i).g = 0.0;
_colors
.at(i).b = 0.0;
_colors
.at(i).a = 1.0;
60
}
61
else
62
{
63
_colors
.at(i).r = 1.0;
_colors
.at(i).g = 1.0;
_colors
.at(i).b = 1.0;
_colors
.at(i).a = 1.0;
64
}
65
}
66
}
67
if
(
_pulses
!= 0)
68
{
69
_pulses
*=2;
70
_pulses
+=1;
71
}
72
_inc
= (1. /
UPDATE_RATE_HZ
) *
_freq
;
73
}
74
75
void
execute
()
76
{
77
if
(
_timer_inc
>= 1.0)
78
{
79
if
(
_num_leds
>=
_chucksize
*2)
80
std::rotate(
_colors
.begin(),
_colors
.begin()+
_chucksize
,
_colors
.end());
81
else
82
std::rotate(
_colors
.begin(),
_colors
.begin()+1,
_colors
.end());
83
_pulsed
++;
84
m_sigColorsReady
(
_colors
);
85
_timer_inc
= 0.0;
86
}
87
else
88
_timer_inc
+=
_inc
;
89
}
90
91
std::string
getName
(){
return
std::string(
"XMasMode"
); }
92
93
private
:
94
bool
_toggle
;
95
double
_timer_inc
;
96
double
_inc
;
97
size_t
_num_leds
;
98
size_t
_chucksize
;
99
};
100
101
#endif
XMasMode::_toggle
bool _toggle
Definition:
xmasMode.h:94
XMasMode::XMasMode
XMasMode(size_t num_leds, int priority=0, double freq=5, int pulses=0, double timeout=0)
Definition:
xmasMode.h:27
mode.h
XMasMode
Definition:
xmasMode.h:24
Mode::_colors
std::vector< color::rgba > _colors
Definition:
mode.h:122
Mode::m_sigColorsReady
boost::signals2::signal< void(std::vector< color::rgba > &colors)> m_sigColorsReady
Definition:
mode.h:129
XMasMode::_inc
double _inc
Definition:
xmasMode.h:96
XMasMode::_num_leds
size_t _num_leds
Definition:
xmasMode.h:97
Mode::UPDATE_RATE_HZ
static const unsigned int UPDATE_RATE_HZ
Definition:
mode.h:126
Mode::_pulses
int _pulses
Definition:
mode.h:115
XMasMode::_timer_inc
double _timer_inc
Definition:
xmasMode.h:95
Mode
Definition:
mode.h:26
XMasMode::execute
void execute()
Definition:
xmasMode.h:75
XMasMode::getName
std::string getName()
Definition:
xmasMode.h:91
Mode::_pulsed
int _pulsed
Definition:
mode.h:119
XMasMode::_chucksize
size_t _chucksize
Definition:
xmasMode.h:98
Mode::_freq
double _freq
Definition:
mode.h:114
cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Nov 8 2023 03:47:37