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; ...@@ -19,8 +19,8 @@ static uint8_t last = 0;
static uint8_t memory = 0; static uint8_t memory = 0;
static uint8_t display_wake_mask = 0xF; static uint8_t display_wake_mask = 0xF;
static uint8_t memory_mask = 0xF; static uint8_t memory_mask = 0xF;
static TimerHandle_t poll_timer; static TimerHandle_t button_timer;
static StaticTimer_t poll_timer_buffer; static StaticTimer_t button_timer_buffer;
uint8_t epic_buttons_read(uint8_t mask) uint8_t epic_buttons_read(uint8_t mask)
{ {
...@@ -64,15 +64,16 @@ static void CALLBACK_buttons(){ ...@@ -64,15 +64,16 @@ static void CALLBACK_buttons(){
} }
void epic_buttons_start(){ void epic_buttons_start(){
if(!poll_timer) { if(!button_timer) {
poll_timer = xTimerCreateStatic( button_timer = xTimerCreateStatic(
"buttons", "buttons",
FREQ, FREQ,
pdTRUE, pdTRUE,
NULL, NULL,
CALLBACK_buttons, 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){ ...@@ -81,15 +82,15 @@ void epic_buttons_set_display_wake_mask(uint8_t mask){
} }
uint8_t epic_buttons_get(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 -ENODATA;
} }
return last & mask; return last & mask;
} }
void epic_buttons_stop(){ void epic_buttons_stop(){
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; } if (!button_timer || xTimerIsTimerActive(button_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0); xTimerStop(button_timer, 0);
} }
void epic_buttons_reset_memory(){ void epic_buttons_reset_memory(){
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#define FREQ 100 #define FREQ 100
static TaskHandle_t lock = NULL; static TaskHandle_t lock = NULL;
static TimerHandle_t poll_timer; static TimerHandle_t display_timer;
static StaticTimer_t poll_timer_buffer; static StaticTimer_t display_timer_buffer;
static bool display_on; static bool display_on;
static bool wake_event; static bool wake_event;
...@@ -91,20 +91,21 @@ static void CALLBACK_power_mgmt(){ //u gotta loop dis ...@@ -91,20 +91,21 @@ static void CALLBACK_power_mgmt(){ //u gotta loop dis
void epic_disp_backlight_auto_stop() void epic_disp_backlight_auto_stop()
{ {
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; } if (!display_timer || xTimerIsTimerActive(display_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0); xTimerStop(display_timer, 0);
} }
void epic_disp_backlight_auto_start(){ void epic_disp_backlight_auto_start(){
if(!poll_timer) { if(!display_timer) {
poll_timer = xTimerCreateStatic( display_timer = xTimerCreateStatic(
"auto_backlight", "auto_backlight",
FREQ, FREQ,
pdTRUE, pdTRUE,
NULL, NULL,
CALLBACK_power_mgmt, CALLBACK_power_mgmt,
&poll_timer_buffer &display_timer_buffer
); );
xTimerStart(display_timer, 0);
} }
} }
......
...@@ -7,21 +7,22 @@ ...@@ -7,21 +7,22 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "timers.h" #include "timers.h"
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#define POWERLED 10 #define POWERLED 10
#define FREQ 100 #define FREQ 100
#define PULSEWIDTH 2 #define PULSEWIDTH 2
#define PULSELENGTH 10 #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_volt = 0;
static float bat_cur = 0; static float bat_cur = 0;
static float char_volt = 0; static float char_volt = 0;
static float char_cur = 0; static float char_cur = 0;
static bool power_led_on = true; static bool power_led_on = true;
static TimerHandle_t poll_timer; static TimerHandle_t status_timer;
static StaticTimer_t poll_timer_buffer; static StaticTimer_t status_timer_buffer;
static void get_power_status(){ static void get_power_status(){
epic_read_battery_voltage(&bat_volt); epic_read_battery_voltage(&bat_volt);
...@@ -33,7 +34,11 @@ static void get_power_status(){ ...@@ -33,7 +34,11 @@ static void get_power_status(){
if(char_cur > 0.1){ if(char_cur > 0.1){
power_status = 254; power_status = 254;
} else { } else {
if(bat_volt>4.1){
power_status = 255; power_status = 255;
} else {
power_status = 128;
}
} }
} else if(bat_volt>3.8){ } else if(bat_volt>3.8){
power_status = 0; power_status = 0;
...@@ -46,6 +51,10 @@ static void get_power_status(){ ...@@ -46,6 +51,10 @@ static void get_power_status(){
static void update_power_led(){ static void update_power_led(){
static uint8_t counter = 0; 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){ switch(power_status){
case 0: case 0:
case 1: case 1:
...@@ -66,6 +75,7 @@ static void update_power_led(){ ...@@ -66,6 +75,7 @@ static void update_power_led(){
counter++; counter++;
counter = counter % PULSELENGTH; counter = counter % PULSELENGTH;
} }
old_power_status = power_status;
} }
static void CALLBACK_led(){ static void CALLBACK_led(){
...@@ -76,28 +86,29 @@ static void CALLBACK_led(){ ...@@ -76,28 +86,29 @@ static void CALLBACK_led(){
} }
void epic_status_start(){ void epic_status_start(){
if(!poll_timer) { if(!status_timer) {
poll_timer = xTimerCreateStatic( status_timer = xTimerCreateStatic(
"status_led", "status_led",
FREQ, FREQ,
pdTRUE, pdTRUE,
NULL, NULL,
CALLBACK_led, CALLBACK_led,
&poll_timer_buffer &status_timer_buffer
); );
xTimerStart(status_timer, 0);
} }
} }
uint8_t epic_status_get_power_status(){ uint8_t epic_status_get_power_status(){
if (!poll_timer || !xTimerIsTimerActive(poll_timer)) { if (!status_timer || !xTimerIsTimerActive(status_timer)) {
return -ENODATA; return -ENODATA;
} }
return power_status; return power_status;
} }
void epic_status_stop(){ void epic_status_stop(){
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; } if (!status_timer || xTimerIsTimerActive(status_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0); xTimerStop(status_timer, 0);
} }
void epic_status_power_led(bool onoff){ void epic_status_power_led(bool onoff){
......
...@@ -16,7 +16,8 @@ modsrc = files( ...@@ -16,7 +16,8 @@ modsrc = files(
'modules/sys_display.c', 'modules/sys_display.c',
'modules/utime.c', 'modules/utime.c',
'modules/vibra.c', 'modules/vibra.c',
'modules/bme680.c' 'modules/bme680.c',
'modules/status.c'
) )
################################# #################################
......
...@@ -167,3 +167,11 @@ Q(COMMUNICATION) ...@@ -167,3 +167,11 @@ Q(COMMUNICATION)
Q(CAMP) Q(CAMP)
Q(MAX30001_ECG) 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); ...@@ -54,6 +54,7 @@ int mp_hal_trng_read_int(void);
#define MODULE_LEDS_ENABLED (1) #define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1) #define MODULE_LIGHT_SENSOR_ENABLED (1)
#define MODULE_MAX30001_ENABLED (1) #define MODULE_MAX30001_ENABLED (1)
#define MODULE_STATUS_ENABLED (1)
#define MODULE_OS_ENABLED (1) #define MODULE_OS_ENABLED (1)
#define MODULE_PERSONAL_STATE_ENABLED (1) #define MODULE_PERSONAL_STATE_ENABLED (1)
#define MODULE_POWER_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