Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
dd2dc383
Commit
dd2dc383
authored
Aug 20, 2019
by
trilader
Browse files
feat(leds), feat(personal-state): Add hardware locking
parent
b27d436c
Changes
3
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/leds.c
View file @
dd2dc383
...
...
@@ -11,12 +11,16 @@
#define NUM_LEDS 15
/* Take from lib/card10/leds.c */
static
void
update
_if_needed
()
static
void
do_
update
()
{
if
(
personal_state_enabled
()
==
0
)
{
leds_update_power
();
leds_update
();
while
(
hwlock_acquire
(
HWLOCK_LED
,
pdMS_TO_TICKS
(
1
))
<
0
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
1
));
}
leds_update_power
();
leds_update
();
hwlock_release
(
HWLOCK_LED
);
}
void
epic_leds_set
(
int
led
,
uint8_t
r
,
uint8_t
g
,
uint8_t
b
)
...
...
@@ -25,8 +29,7 @@ void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b)
return
;
leds_prep
(
led
,
r
,
g
,
b
);
leds_update_power
();
leds_update
();
do_update
();
}
void
epic_leds_set_hsv
(
int
led
,
float
h
,
float
s
,
float
v
)
...
...
@@ -35,7 +38,7 @@ void epic_leds_set_hsv(int led, float h, float s, float v)
return
;
leds_prep_hsv
(
led
,
h
,
s
,
v
);
update
_if_needed
();
do_
update
();
}
void
epic_leds_prep
(
int
led
,
uint8_t
r
,
uint8_t
g
,
uint8_t
b
)
...
...
@@ -63,7 +66,7 @@ void epic_leds_set_all(uint8_t *pattern_ptr, uint8_t len)
leds_prep
(
i
,
pattern
[
i
][
0
],
pattern
[
i
][
1
],
pattern
[
i
][
2
]);
}
update
_if_needed
();
do_
update
();
}
void
epic_leds_set_all_hsv
(
float
*
pattern_ptr
,
uint8_t
len
)
...
...
@@ -75,7 +78,7 @@ void epic_leds_set_all_hsv(float *pattern_ptr, uint8_t len)
leds_prep_hsv
(
i
,
pattern
[
i
][
0
],
pattern
[
i
][
1
],
pattern
[
i
][
2
]);
}
update
_if_needed
();
do_
update
();
}
void
epic_leds_dim_top
(
uint8_t
value
)
...
...
@@ -105,7 +108,7 @@ void epic_set_flashlight(bool power)
void
epic_leds_update
(
void
)
{
update
_if_needed
();
do_
update
();
}
void
epic_leds_set_powersave
(
bool
eco
)
...
...
@@ -127,6 +130,5 @@ void epic_leds_clear_all(uint8_t r, uint8_t g, uint8_t b)
leds_prep
(
i
,
r
,
g
,
b
);
}
leds_update_power
();
leds_update
();
do_update
();
}
epicardium/modules/modules.h
View file @
dd2dc383
...
...
@@ -48,6 +48,7 @@ void hwlock_init(void);
enum
hwlock_periph
{
HWLOCK_I2C
=
0
,
HWLOCK_ADC
,
HWLOCK_LED
,
_HWLOCK_MAX
,
};
...
...
epicardium/modules/personal_state.c
View file @
dd2dc383
...
...
@@ -31,9 +31,15 @@ int epic_personal_state_set(uint8_t state, bool persistent)
personal_state_persistent
=
persistent
;
if
(
was_enabled
&&
!
_personal_state_enabled
)
{
while
(
hwlock_acquire
(
HWLOCK_LED
,
pdMS_TO_TICKS
(
1
))
<
0
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
1
));
}
leds_prep
(
PERSONAL_STATE_LED
,
0
,
0
,
0
);
leds_update_power
();
leds_update
();
hwlock_release
(
HWLOCK_LED
);
}
return
0
;
...
...
@@ -54,6 +60,11 @@ void vLedTask(void *pvParameters)
const
int
led_animation_rate
=
1000
/
25
;
/* 25Hz -> 40ms*/
while
(
1
)
{
if
(
_personal_state_enabled
)
{
while
(
hwlock_acquire
(
HWLOCK_LED
,
pdMS_TO_TICKS
(
1
))
<
0
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
1
));
}
led_animation_ticks
++
;
if
(
personal_state
==
STATE_NO_CONTACT
)
{
leds_prep
(
PERSONAL_STATE_LED
,
255
,
0
,
0
);
...
...
@@ -121,6 +132,8 @@ void vLedTask(void *pvParameters)
}
leds_update_power
();
leds_update
();
hwlock_release
(
HWLOCK_LED
);
}
vTaskDelay
(
led_animation_rate
/
portTICK_PERIOD_MS
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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