Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
cdfe3b70
Commit
cdfe3b70
authored
Feb 08, 2022
by
Eric Duminil
Browse files
Max and min brightness
parent
c1fa76f3
Pipeline
#5762
passed with stage
in 2 minutes and 5 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
ampel-firmware/led_effects.cpp
View file @
cdfe3b70
#include
"led_effects.h"
#include
"led_effects.h"
#include
"config.h"
#include
"config.h"
#include
"web_config.h"
#include
"sensor_console.h"
#include
"sensor_console.h"
// Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip)
// Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip)
...
@@ -12,13 +13,6 @@
...
@@ -12,13 +13,6 @@
* Configuration *
* Configuration *
*****************************************************************/
*****************************************************************/
namespace
config
{
namespace
config
{
const
uint8_t
max_brightness
=
MAX_BRIGHTNESS
;
#if defined(MIN_BRIGHTNESS)
const
uint8_t
min_brightness
=
MIN_BRIGHTNESS
;
#else
const
uint8_t
min_brightness
=
MAX_BRIGHTNESS
;
#endif
const
uint8_t
brightness_amplitude
=
config
::
max_brightness
-
config
::
min_brightness
;
const
int
kitt_tail
=
3
;
// How many dimmer LEDs follow in K.I.T.T. wheel
const
int
kitt_tail
=
3
;
// How many dimmer LEDs follow in K.I.T.T. wheel
const
uint16_t
poor_air_quality_ppm
=
1600
;
// Above this threshold, LED breathing effect is faster.
const
uint16_t
poor_air_quality_ppm
=
1600
;
// Above this threshold, LED breathing effect is faster.
bool
display_led
=
true
;
// Will be set to false during "night mode".
bool
display_led
=
true
;
// Will be set to false during "night mode".
...
@@ -36,10 +30,41 @@ namespace config {
...
@@ -36,10 +30,41 @@ namespace config {
// LEDs >= 1600ppm will be pure red (hue angle 0°), LEDs in-between will be yellowish.
// LEDs >= 1600ppm will be pure red (hue angle 0°), LEDs in-between will be yellowish.
const
uint16_t
led_hues
[
led_count
]
=
{
21845U
,
19114U
,
16383U
,
13653U
,
10922U
,
8191U
,
5461U
,
2730U
,
0
,
0
,
0
,
0
};
// [hue angle]
const
uint16_t
led_hues
[
led_count
]
=
{
21845U
,
19114U
,
16383U
,
13653U
,
10922U
,
8191U
,
5461U
,
2730U
,
0
,
0
,
0
,
0
};
// [hue angle]
#elif LED_COUNT == 16
#elif LED_COUNT == 16
const
uint16_t
co2_ticks
[
led_count
+
1
]
=
{
0
,
500
,
600
,
700
,
800
,
900
,
1000
,
1100
,
1200
,
const
uint16_t
co2_ticks
[
led_count
+
1
]
=
{
1300
,
1400
,
1500
,
1600
,
1700
,
1800
,
2000
,
2200
};
// [ppm]
0
,
const
uint16_t
led_hues
[
led_count
]
=
{
21845U
,
19859U
,
17873U
,
15887U
,
13901U
,
11915U
,
9929U
,
7943U
,
500
,
5957U
,
3971U
,
1985U
,
0
,
0
,
0
,
0
,
0
};
// [hue angle]
600
,
700
,
800
,
900
,
1000
,
1100
,
1200
,
1300
,
1400
,
1500
,
1600
,
1700
,
1800
,
2000
,
2200
};
// [ppm]
const
uint16_t
led_hues
[
led_count
]
=
{
21845U
,
19859U
,
17873U
,
15887U
,
13901U
,
11915U
,
9929U
,
7943U
,
5957U
,
3971U
,
1985U
,
0
,
0
,
0
,
0
,
0
};
// [hue angle]
#else
#else
# error "Only 12 and 16 LEDs rings are currently supported."
# error "Only 12 and 16 LEDs rings are currently supported."
#endif
#endif
...
@@ -95,7 +120,7 @@ namespace led_effects {
...
@@ -95,7 +120,7 @@ namespace led_effects {
void
setupRing
()
{
void
setupRing
()
{
pixels
.
begin
();
pixels
.
begin
();
pixels
.
setBrightness
(
config
::
max_brightness
);
pixels
.
setBrightness
(
*
config
::
max_brightness
);
LEDsOff
();
LEDsOff
();
sensor_console
::
defineIntCommand
(
"led"
,
turnLEDsOnOff
,
F
(
"0/1 (Turns LEDs on/off)"
));
sensor_console
::
defineIntCommand
(
"led"
,
turnLEDsOnOff
,
F
(
"0/1 (Turns LEDs on/off)"
));
sensor_console
::
defineIntCommand
(
"color"
,
showColor
,
F
(
"0xFF0015 (Shows color, specified as RGB, for debugging)"
));
sensor_console
::
defineIntCommand
(
"color"
,
showColor
,
F
(
"0xFF0015 (Shows color, specified as RGB, for debugging)"
));
...
@@ -136,7 +161,7 @@ namespace led_effects {
...
@@ -136,7 +161,7 @@ namespace led_effects {
// Simulate a moving LED with tail. First LED starts at 0, and moves along a triangular function. The tail follows, with decreasing brightness.
// Simulate a moving LED with tail. First LED starts at 0, and moves along a triangular function. The tail follows, with decreasing brightness.
// Takes approximately 1s for each direction.
// Takes approximately 1s for each direction.
void
showKITTWheel
(
uint32_t
color
,
uint16_t
duration_s
)
{
void
showKITTWheel
(
uint32_t
color
,
uint16_t
duration_s
)
{
pixels
.
setBrightness
(
config
::
max_brightness
);
pixels
.
setBrightness
(
*
config
::
max_brightness
);
for
(
int
i
=
0
;
i
<
duration_s
*
config
::
led_count
;
++
i
)
{
for
(
int
i
=
0
;
i
<
duration_s
*
config
::
led_count
;
++
i
)
{
showWaitingLED
(
color
);
showWaitingLED
(
color
);
}
}
...
@@ -165,7 +190,8 @@ namespace led_effects {
...
@@ -165,7 +190,8 @@ namespace led_effects {
*/
*/
void
breathe
(
int16_t
co2
)
{
void
breathe
(
int16_t
co2
)
{
static
uint8_t
breathing_offset
=
0
;
static
uint8_t
breathing_offset
=
0
;
uint16_t
brightness
=
config
::
min_brightness
+
pixels
.
sine8
(
breathing_offset
)
*
config
::
brightness_amplitude
/
255
;
uint8_t
brightness_amplitude
=
*
config
::
max_brightness
-
*
config
::
min_brightness
;
uint16_t
brightness
=
*
config
::
min_brightness
+
pixels
.
sine8
(
breathing_offset
)
*
brightness_amplitude
/
255
;
pixels
.
setBrightness
(
brightness
);
pixels
.
setBrightness
(
brightness
);
pixels
.
show
();
pixels
.
show
();
breathing_offset
+=
co2
>
config
::
poor_air_quality_ppm
?
6
:
3
;
// breathing speed. +3 looks like slow human breathing.
breathing_offset
+=
co2
>
config
::
poor_air_quality_ppm
?
6
:
3
;
// breathing speed. +3 looks like slow human breathing.
...
@@ -178,13 +204,13 @@ namespace led_effects {
...
@@ -178,13 +204,13 @@ namespace led_effects {
if
(
!
config
::
display_led
)
{
if
(
!
config
::
display_led
)
{
return
;
return
;
}
}
pixels
.
setBrightness
(
config
::
max_brightness
);
pixels
.
setBrightness
(
*
config
::
max_brightness
);
for
(
int
ledId
=
0
;
ledId
<
config
::
led_count
;
++
ledId
)
{
for
(
int
ledId
=
0
;
ledId
<
config
::
led_count
;
++
ledId
)
{
uint8_t
brightness
=
getLedBrightness
(
co2
,
ledId
);
uint8_t
brightness
=
getLedBrightness
(
co2
,
ledId
);
pixels
.
setPixelColor
(
ledId
,
pixels
.
ColorHSV
(
config
::
led_hues
[
ledId
],
255
,
brightness
));
pixels
.
setPixelColor
(
ledId
,
pixels
.
ColorHSV
(
config
::
led_hues
[
ledId
],
255
,
brightness
));
}
}
pixels
.
show
();
pixels
.
show
();
if
(
config
::
brightness
_amplitude
>
0
)
{
if
(
*
config
::
max_
brightness
>
*
config
::
min_brightness
)
{
breathe
(
co2
);
breathe
(
co2
);
}
}
}
}
...
@@ -196,7 +222,7 @@ namespace led_effects {
...
@@ -196,7 +222,7 @@ namespace led_effects {
static
uint16_t
wheel_offset
=
0
;
static
uint16_t
wheel_offset
=
0
;
static
uint16_t
sine_offset
=
0
;
static
uint16_t
sine_offset
=
0
;
unsigned
long
t0
=
millis
();
unsigned
long
t0
=
millis
();
pixels
.
setBrightness
(
config
::
max_brightness
);
pixels
.
setBrightness
(
*
config
::
max_brightness
);
while
(
millis
()
-
t0
<
duration_ms
)
{
while
(
millis
()
-
t0
<
duration_ms
)
{
for
(
int
i
=
0
;
i
<
config
::
led_count
;
i
++
)
{
for
(
int
i
=
0
;
i
<
config
::
led_count
;
i
++
)
{
pixels
.
setPixelColor
(
i
,
pixels
.
ColorHSV
(
i
*
65535
/
config
::
led_count
+
wheel_offset
));
pixels
.
setPixelColor
(
i
,
pixels
.
ColorHSV
(
i
*
65535
/
config
::
led_count
+
wheel_offset
));
...
@@ -216,7 +242,7 @@ namespace led_effects {
...
@@ -216,7 +242,7 @@ namespace led_effects {
return
;
return
;
}
}
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
pixels
.
setBrightness
(
static_cast
<
int
>
(
config
::
max_brightness
*
(
1
-
i
*
0.1
)));
pixels
.
setBrightness
(
static_cast
<
int
>
(
*
config
::
max_brightness
*
(
1
-
i
*
0.1
)));
delay
(
50
);
delay
(
50
);
pixels
.
fill
(
color
::
red
);
pixels
.
fill
(
color
::
red
);
pixels
.
show
();
pixels
.
show
();
...
...
ampel-firmware/web_config.cpp
View file @
cdfe3b70
...
@@ -279,4 +279,7 @@ namespace config {
...
@@ -279,4 +279,7 @@ namespace config {
uint16_t
*
co2_calibration_level
=
&
web_config
::
atmosphericCO2Param
.
value
();
// [ppm]
uint16_t
*
co2_calibration_level
=
&
web_config
::
atmosphericCO2Param
.
value
();
// [ppm]
bool
*
auto_calibrate_sensor
=
&
web_config
::
autoCalibrateParam
.
value
();
// [true / false]
bool
*
auto_calibrate_sensor
=
&
web_config
::
autoCalibrateParam
.
value
();
// [true / false]
float
*
temperature_offset
=
&
web_config
::
temperatureOffsetParam
.
value
();
// [K] Sign isn't relevant.
float
*
temperature_offset
=
&
web_config
::
temperatureOffsetParam
.
value
();
// [K] Sign isn't relevant.
uint8_t
*
max_brightness
=
&
web_config
::
maxBrightnessParam
.
value
();
uint8_t
*
min_brightness
=
&
web_config
::
minBrightnessParam
.
value
();
}
}
ampel-firmware/web_config.h
View file @
cdfe3b70
...
@@ -18,6 +18,10 @@ namespace config {
...
@@ -18,6 +18,10 @@ namespace config {
extern
uint16_t
*
co2_calibration_level
;
// [ppm]
extern
uint16_t
*
co2_calibration_level
;
// [ppm]
extern
bool
*
auto_calibrate_sensor
;
// [true / false]
extern
bool
*
auto_calibrate_sensor
;
// [true / false]
extern
float
*
temperature_offset
;
// [K] Sign isn't relevant.
extern
float
*
temperature_offset
;
// [K] Sign isn't relevant.
// LED
extern
uint8_t
*
max_brightness
;
extern
uint8_t
*
min_brightness
;
}
}
namespace
web_config
{
namespace
web_config
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment