Commit 0a1b82c3 authored by fleur's avatar fleur
Browse files

pycardium, first tests, some fixes

parent fe7d1182
......@@ -19,8 +19,8 @@ static uint8_t last = 0;
static uint8_t memory = 0;
static uint8_t display_wake_mask = 0xF;
static uint8_t memory_mask = 0xF;
static TimerHandle_t poll_timer;
static StaticTimer_t poll_timer_buffer;
static TimerHandle_t button_timer;
static StaticTimer_t button_timer_buffer;
uint8_t epic_buttons_read(uint8_t mask)
{
......@@ -64,15 +64,16 @@ static void CALLBACK_buttons(){
}
void epic_buttons_start(){
if(!poll_timer) {
poll_timer = xTimerCreateStatic(
if(!button_timer) {
button_timer = xTimerCreateStatic(
"buttons",
FREQ,
pdTRUE,
NULL,
CALLBACK_buttons,
&poll_timer_buffer
&button_timer_buffer
);
xTimerStart(button_timer,0);
}
}
......@@ -81,15 +82,15 @@ void epic_buttons_set_display_wake_mask(uint8_t mask){
}
uint8_t epic_buttons_get(uint8_t mask){
if (!poll_timer || !xTimerIsTimerActive(poll_timer)) {
if (!button_timer || !xTimerIsTimerActive(button_timer)) {
return -ENODATA;
}
return last & mask;
}
void epic_buttons_stop(){
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0);
if (!button_timer || xTimerIsTimerActive(button_timer) == pdFALSE) { return; }
xTimerStop(button_timer, 0);
}
void epic_buttons_reset_memory(){
......
......@@ -15,8 +15,8 @@
#define FREQ 100
static TaskHandle_t lock = NULL;
static TimerHandle_t poll_timer;
static StaticTimer_t poll_timer_buffer;
static TimerHandle_t display_timer;
static StaticTimer_t display_timer_buffer;
static bool display_on;
static bool wake_event;
......@@ -91,20 +91,21 @@ static void CALLBACK_power_mgmt(){ //u gotta loop dis
void epic_disp_backlight_auto_stop()
{
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0);
if (!display_timer || xTimerIsTimerActive(display_timer) == pdFALSE) { return; }
xTimerStop(display_timer, 0);
}
void epic_disp_backlight_auto_start(){
if(!poll_timer) {
poll_timer = xTimerCreateStatic(
if(!display_timer) {
display_timer = xTimerCreateStatic(
"auto_backlight",
FREQ,
pdTRUE,
NULL,
CALLBACK_power_mgmt,
&poll_timer_buffer
&display_timer_buffer
);
xTimerStart(display_timer, 0);
}
}
......
......@@ -7,21 +7,22 @@
#include "FreeRTOS.h"
#include "timers.h"
#include <stdio.h>
#include <stdint.h>
#define POWERLED 10
#define FREQ 100
#define PULSEWIDTH 2
#define PULSELENGTH 10
static uint8_t power_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 uint8_t power_status = 0; // 0: discharging, 1: below 3.8V, 2: below 3.6V, 254: charging, 255: full and connected to charger, 128: charge error, 127: undefined
static float bat_volt = 0;
static float bat_cur = 0;
static float char_volt = 0;
static float char_cur = 0;
static bool power_led_on = true;
static TimerHandle_t poll_timer;
static StaticTimer_t poll_timer_buffer;
static TimerHandle_t status_timer;
static StaticTimer_t status_timer_buffer;
static void get_power_status(){
epic_read_battery_voltage(&bat_volt);
......@@ -33,7 +34,11 @@ static void get_power_status(){
if(char_cur > 0.1){
power_status = 254;
} else {
power_status = 255;
if(bat_volt>4.1){
power_status = 255;
} else {
power_status = 128;
}
}
} else if(bat_volt>3.8){
power_status = 0;
......@@ -46,6 +51,10 @@ static void get_power_status(){
static void update_power_led(){
static uint8_t counter = 0;
static uint8_t old_power_status = 127;
if(old_power_status == power_status && power_status != 2){
return;
}
switch(power_status){
case 0:
case 1:
......@@ -66,6 +75,7 @@ static void update_power_led(){
counter++;
counter = counter % PULSELENGTH;
}
old_power_status = power_status;
}
static void CALLBACK_led(){
......@@ -76,28 +86,29 @@ static void CALLBACK_led(){
}
void epic_status_start(){
if(!poll_timer) {
poll_timer = xTimerCreateStatic(
if(!status_timer) {
status_timer = xTimerCreateStatic(
"status_led",
FREQ,
pdTRUE,
NULL,
CALLBACK_led,
&poll_timer_buffer
&status_timer_buffer
);
xTimerStart(status_timer, 0);
}
}
uint8_t epic_status_get_power_status(){
if (!poll_timer || !xTimerIsTimerActive(poll_timer)) {
if (!status_timer || !xTimerIsTimerActive(status_timer)) {
return -ENODATA;
}
return power_status;
}
void epic_status_stop(){
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0);
if (!status_timer || xTimerIsTimerActive(status_timer) == pdFALSE) { return; }
xTimerStop(status_timer, 0);
}
void epic_status_power_led(bool onoff){
......
......@@ -16,7 +16,8 @@ modsrc = files(
'modules/sys_display.c',
'modules/utime.c',
'modules/vibra.c',
'modules/bme680.c'
'modules/bme680.c',
'modules/status.c'
)
#################################
......
......@@ -167,3 +167,11 @@ Q(COMMUNICATION)
Q(CAMP)
Q(MAX30001_ECG)
/* status */
Q(status)
Q(start)
Q(stop)
Q(get_power_status)
Q(power_led)
#include "epicardium.h"
#include "py/builtin.h"
#include "py/obj.h"
#include "py/runtime.h"
static mp_obj_t mp_status_start()
{
epic_status_start();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(
status_start_obj, mp_status_start
);
static mp_obj_t mp_status_stop()
{
epic_status_stop();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(
status_stop_obj, mp_status_stop
);
static mp_obj_t mp_status_get_power_status()
{
int status = epic_status_get_power_status();
return mp_obj_new_int(status);
}
static MP_DEFINE_CONST_FUN_OBJ_0(
status_get_power_status_obj, mp_status_get_power_status
);
static mp_obj_t mp_status_power_led(mp_obj_t on_in)
{
int on = mp_obj_get_int(on_in);
epic_status_power_led(on);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(
status_power_led_obj, mp_status_power_led
);
static const mp_rom_map_elem_t status_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_status) },
{ MP_ROM_QSTR(MP_QSTR_start),
MP_ROM_PTR(&status_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop),
MP_ROM_PTR(&status_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_power_status),
MP_ROM_PTR(&status_get_power_status_obj) },
{ MP_ROM_QSTR(MP_QSTR_power_led),
MP_ROM_PTR(&status_power_led_obj) },
};
static MP_DEFINE_CONST_DICT(status_module_globals, status_module_globals_table);
const mp_obj_module_t status_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&status_module_globals,
};
/* clang-format off */
MP_REGISTER_MODULE(MP_QSTR_status, status_module, MODULE_STATUS_ENABLED);
......@@ -54,6 +54,7 @@ int mp_hal_trng_read_int(void);
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_MAX30001_ENABLED (1)
#define MODULE_STATUS_ENABLED (1)
#define MODULE_OS_ENABLED (1)
#define MODULE_PERSONAL_STATE_ENABLED (1)
#define MODULE_POWER_ENABLED (1)
......
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