Commit 9c473c65 authored by fleur's avatar fleur
Browse files

epicardium.h still missing but getting there

parent 76a51b64
......@@ -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;
}
......@@ -21,5 +21,6 @@ module_sources = files(
'trng.c',
'vibra.c',
'watchdog.c',
'usb.c'
'usb.c',
'status.c'
)
#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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment