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
fleur
firmware
Commits
9c473c65
Commit
9c473c65
authored
Aug 28, 2019
by
fleur
Browse files
epicardium.h still missing but getting there
parent
76a51b64
Changes
3
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/buttons.c
View file @
9c473c65
...
...
@@ -15,10 +15,11 @@ static const uint8_t pin_mask[] = {
[
BUTTON_RIGHT_BOTTOM
]
=
1
<<
3
,
[
BUTTON_RIGHT_TOP
]
=
1
<<
6
,
};
static
uint8_t
last
;
static
uint8_t
last
=
0
;
static
uint8_t
memory
=
0
;
static
uint8_t
display_wake_mask
=
0xF
;
static
Timer_Handle_t
poll_timer
;
static
uint8_t
memory_mask
=
0xF
;
static
TimerHandle_t
poll_timer
;
static
StaticTimer_t
poll_timer_buffer
;
uint8_t
epic_buttons_read
(
uint8_t
mask
)
...
...
@@ -54,6 +55,9 @@ uint8_t epic_buttons_read(uint8_t mask)
static
void
CALLBACK_buttons
(){
last
=
epic_buttons_read
(
0xF
);
if
(
last
&
memory_mask
){
memory
=
last
;
}
if
(
last
&
display_wake_mask
){
epic_disp_wake
();
}
...
...
@@ -77,6 +81,9 @@ void epic_buttons_set_display_wake_mask(uint8_t mask){
}
uint8_t
epic_buttons_get
(){
if
(
!
poll_timer
||
!
xTimerIsTimerActive
(
poll_timer
))
{
return
-
ENODATA
;
}
return
last
;
}
...
...
@@ -84,3 +91,11 @@ void epic_buttons_stop(){
if
(
!
poll_timer
||
xTimerIsTimerActive
(
poll_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll_timer
,
0
);
}
void
epic_buttons_reset_memory
(){
memory
=
0
;
}
uint8_t
epic_buttons_get_memory
(){
return
memory
;
}
epicardium/modules/meson.build
View file @
9c473c65
...
...
@@ -21,5 +21,6 @@ module_sources = files(
'trng.c',
'vibra.c',
'watchdog.c',
'usb.c'
'usb.c',
'status.c'
)
epicardium/modules/status.c
0 → 100644
View file @
9c473c65
#include "epicardium.h"
#include "modules/modules.h"
#include "modules/log.h"
#include "portexpander.h"
#include "MAX77650-Arduino-Library.h"
#include "FreeRTOS.h"
#include "timers.h"
#include <stdint.h>
#define POWERLED 10
#define FREQ 100
#define PULSEWIDTH 2
#define PULSELENGTH 10
static
uint8_t
status
=
0
;
// 0: discharging, 1: below 3.8V, 2: below 3.6V, 254: charging, 255: full and connected to charger (or error) (yeah i know bad collision) (i'll fix this)
static
float
bat_volt
=
0
;
static
float
bat_cur
=
0
;
static
float
char_volt
=
0
;
static
float
char_cur
=
0
;
static
bool
led_on
=
true
;
static
TimerHandle_t
poll_timer
;
static
StaticTimer_t
poll_timer_buffer
;
static
void
get_power_status
(){
epic_read_battery_voltage
(
&
bat_volt
);
epic_read_battery_current
(
&
bat_cur
);
epic_read_chargein_voltage
(
&
char_volt
);
epic_read_chargein_current
(
&
char_cur
);
if
(
char_volt
>
4
){
if
(
char_cur
>
0
.
1
){
status
=
254
;
}
else
{
status
=
255
;
}
}
else
if
(
bat_volt
>
3
.
8
){
status
=
0
;
}
else
if
(
bat_volt
>
3
.
6
){
status
=
1
;
}
else
{
status
=
2
;
}
}
static
void
update_led
(){
static
uint8_t
counter
=
0
;
switch
(
status
){
case
0
:
case
1
:
epic_leds_set
(
POWERLED
,
0
,
0
,
0
);
return
;
case
254
:
epic_leds_set
(
POWERLED
,
0
,
0
,
200
);
return
;
case
255
:
epic_leds_set
(
POWERLED
,
0
,
200
,
0
);
return
;
case
2
:
if
(
counter
<
PULSEWIDTH
){
epic_leds_set
(
POWERLED
,
200
,
0
,
0
);
}
else
{
epic_leds_set
(
POWERLED
,
0
,
0
,
0
);
}
counter
++
;
counter
=
counter
%
PULSELENGTH
;
}
}
static
void
CALLBACK_led
(){
get_power_status
();
if
(
led_on
){
update_led
();
}
}
void
epic_status_start
(){
if
(
!
poll_timer
)
{
poll_timer
=
xTimerCreateStatic
(
"status_led"
,
FREQ
,
pdTRUE
,
NULL
,
CALLBACK_led
,
&
poll_timer_buffer
);
}
}
uint8_t
epic_status_get
(){
if
(
!
poll_timer
||
!
xTimerIsTimerActive
(
poll_timer
))
{
return
-
ENODATA
;
}
return
status
;
}
void
epic_status_stop
(){
if
(
!
poll_timer
||
xTimerIsTimerActive
(
poll_timer
)
==
pdFALSE
)
{
return
;
}
xTimerStop
(
poll_timer
,
0
);
}
void
epic_status_led
(
bool
onoff
){
led_on
=
onoff
;
}
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