Skip to content
Snippets Groups Projects
Commit dc2c4452 authored by fleur's avatar fleur
Browse files

everything seems to be working kinda

parent 0a1b82c3
Branches ch3/leds-api
No related tags found
No related merge requests found
Pipeline #3608 failed
...@@ -58,8 +58,10 @@ typedef _Bool bool; ...@@ -58,8 +58,10 @@ typedef _Bool bool;
#define API_DISP_BACKLIGHT_AUTO_START 0x2c #define API_DISP_BACKLIGHT_AUTO_START 0x2c
#define API_DISP_BACKLIGHT_AUTO_STOP 0x2d #define API_DISP_BACKLIGHT_AUTO_STOP 0x2d
#define API_DISP_WAKE 0x2e #define API_DISP_WAKE 0x2e
#define API_DISP_SET_TIMEOUT_CYCLES 0x2f #define API_DISP_TUCK_IN 0x2f
#define API_DISP_SET_BRIGHTNESS_TABLE 0x130
#define API_DISP_SET_TIMEOUT_CYCLES 0x130
#define API_DISP_SET_BRIGHTNESS_TABLE 0x131
/* API_BATTERY_VOLTAGE 0x30 */ /* API_BATTERY_VOLTAGE 0x30 */
#define API_BATTERY_CURRENT 0x31 #define API_BATTERY_CURRENT 0x31
...@@ -1423,6 +1425,7 @@ API(API_DISP_BACKLIGHT, int epic_disp_backlight(uint16_t brightness)); ...@@ -1423,6 +1425,7 @@ API(API_DISP_BACKLIGHT, int epic_disp_backlight(uint16_t brightness));
API(API_DISP_BACKLIGHT_AUTO_START, void epic_disp_backlight_auto_start(void)); API(API_DISP_BACKLIGHT_AUTO_START, void epic_disp_backlight_auto_start(void));
API(API_DISP_BACKLIGHT_AUTO_STOP, void epic_disp_backlight_auto_stop(void)); API(API_DISP_BACKLIGHT_AUTO_STOP, void epic_disp_backlight_auto_stop(void));
API(API_DISP_WAKE, void epic_disp_wake(void)); API(API_DISP_WAKE, void epic_disp_wake(void));
API(API_DISP_TUCK_IN, void epic_disp_tuck_in(void));
API(API_DISP_SET_TIMEOUT_CYCLES, void epic_disp_set_timeout_cycles(int cycles)); API(API_DISP_SET_TIMEOUT_CYCLES, void epic_disp_set_timeout_cycles(int cycles));
API(API_DISP_SET_BRIGHTNESS_TABLE, void epic_disp_set_brightness_table(uint8_t *table)); API(API_DISP_SET_BRIGHTNESS_TABLE, void epic_disp_set_brightness_table(uint8_t *table));
......
...@@ -18,10 +18,10 @@ static TaskHandle_t lock = NULL; ...@@ -18,10 +18,10 @@ static TaskHandle_t lock = NULL;
static TimerHandle_t display_timer; static TimerHandle_t display_timer;
static StaticTimer_t display_timer_buffer; static StaticTimer_t display_timer_buffer;
static bool display_on; static bool display_on = true;
static bool wake_event; static bool wake_event;
static uint16_t timeout_cycles = 1000; static uint16_t timeout_cycles = 0;
static uint8_t lpf_speed = 10; //ca. 1Hz f_g static uint8_t lpf_speed = 10; //10 = ca. 1Hz f_g
static uint8_t brightness_table[MAX_BRIGHTNESS]; static uint8_t brightness_table[MAX_BRIGHTNESS];
static int check_lock() static int check_lock()
...@@ -43,12 +43,12 @@ void epic_disp_set_brightness_table(uint8_t table[MAX_BRIGHTNESS]) ...@@ -43,12 +43,12 @@ void epic_disp_set_brightness_table(uint8_t table[MAX_BRIGHTNESS])
static uint16_t limit(uint16_t input, uint16_t max, uint16_t min){ static uint16_t limit(uint16_t input, uint16_t max, uint16_t min){
uint16_t output = input > max ? max : input; uint16_t output = input > max ? max : input;
return output < 0 ? 0 : output; return output < min ? min : output;
} }
static uint16_t lpf(uint16_t input, uint8_t speed){ static uint16_t lpf(uint16_t input, uint8_t speed){
static uint16_t output; static uint16_t output;
output = speed*input+(~speed)*output; output = speed*input+((uint8_t)~speed)*output;
output = output >> 8; output = output >> 8;
return output; return output;
} }
...@@ -73,16 +73,20 @@ void epic_disp_wake(){ ...@@ -73,16 +73,20 @@ void epic_disp_wake(){
wake_event = true; wake_event = true;
} }
void epic_disp_tuck_in(){
display_on = false;
}
static void CALLBACK_power_mgmt(){ //u gotta loop dis static void CALLBACK_power_mgmt(){ //u gotta loop dis
uint16_t buttonTimeout = 0; static uint16_t timeout = 0;
if(!timeout_cycles){ if(!timeout_cycles){
display_on = true; display_on = true;
} else if(wake_event){ } else if(wake_event){
buttonTimeout = timeout_cycles; timeout = timeout_cycles;
display_on = true; display_on = true;
wake_event = false; wake_event = false;
} else if(buttonTimeout){ } else if(timeout){
buttonTimeout--; timeout--;
} else { } else {
display_on = false; display_on = false;
} }
......
...@@ -19,7 +19,7 @@ static float bat_volt = 0; ...@@ -19,7 +19,7 @@ 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 uint8_t power_led_on = true;
static TimerHandle_t status_timer; static TimerHandle_t status_timer;
static StaticTimer_t status_timer_buffer; static StaticTimer_t status_timer_buffer;
...@@ -79,9 +79,14 @@ static void update_power_led(){ ...@@ -79,9 +79,14 @@ static void update_power_led(){
} }
static void CALLBACK_led(){ static void CALLBACK_led(){
static bool prev_power_led_on;
get_power_status(); get_power_status();
if(power_led_on){ if(power_led_on){
update_power_led(); update_power_led();
prev_power_led_on = true;
} else if (prev_power_led_on) {
epic_leds_set(POWERLED,0,0,0);
prev_power_led_on = false;
} }
} }
......
...@@ -13,9 +13,60 @@ static mp_obj_t mp_buttons_read(mp_obj_t mask_in) ...@@ -13,9 +13,60 @@ static mp_obj_t mp_buttons_read(mp_obj_t mask_in)
} }
static MP_DEFINE_CONST_FUN_OBJ_1(buttons_read_obj, mp_buttons_read); static MP_DEFINE_CONST_FUN_OBJ_1(buttons_read_obj, mp_buttons_read);
static mp_obj_t mp_buttons_start()
{
epic_buttons_start();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(buttons_start_obj, mp_buttons_start);
static mp_obj_t mp_buttons_stop()
{
epic_buttons_stop();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(buttons_stop_obj, mp_buttons_stop);
static mp_obj_t mp_buttons_get(mp_obj_t mask_in)
{
uint8_t mask = mp_obj_get_int(mask_in);
uint8_t button_states = epic_buttons_get(mask);
return MP_OBJ_NEW_SMALL_INT(button_states);
}
static MP_DEFINE_CONST_FUN_OBJ_1(buttons_get_obj, mp_buttons_get);
static mp_obj_t mp_buttons_get_memory(mp_obj_t mask_in)
{
uint8_t mask = mp_obj_get_int(mask_in);
uint8_t button_states = epic_buttons_get_memory(mask);
return MP_OBJ_NEW_SMALL_INT(button_states);
}
static MP_DEFINE_CONST_FUN_OBJ_1(buttons_get_memory_obj, mp_buttons_get_memory);
static mp_obj_t mp_buttons_reset_memory()
{
epic_buttons_reset_memory();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(buttons_reset_memory_obj, mp_buttons_reset_memory);
static mp_obj_t mp_buttons_set_display_wake_mask(mp_obj_t mask_in)
{
uint8_t mask = mp_obj_get_int(mask_in);
epic_buttons_set_display_wake_mask(mask);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(buttons_set_display_wake_mask_obj, mp_buttons_set_display_wake_mask);
static const mp_rom_map_elem_t buttons_module_globals_table[] = { static const mp_rom_map_elem_t buttons_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buttons) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buttons) },
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&buttons_read_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&buttons_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&buttons_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&buttons_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&buttons_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_memory), MP_ROM_PTR(&buttons_get_memory_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_memory), MP_ROM_PTR(&buttons_reset_memory_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_display_wake_mask), MP_ROM_PTR(&buttons_set_display_wake_mask_obj) },
{ MP_ROM_QSTR(MP_QSTR_BOTTOM_LEFT), { MP_ROM_QSTR(MP_QSTR_BOTTOM_LEFT),
MP_OBJ_NEW_SMALL_INT(BUTTON_LEFT_BOTTOM) }, MP_OBJ_NEW_SMALL_INT(BUTTON_LEFT_BOTTOM) },
{ MP_ROM_QSTR(MP_QSTR_BOTTOM_RIGHT), { MP_ROM_QSTR(MP_QSTR_BOTTOM_RIGHT),
......
...@@ -181,6 +181,25 @@ class Display: ...@@ -181,6 +181,25 @@ class Display:
sys_display.circ(x, y, rad, col, filled, size) sys_display.circ(x, y, rad, col, filled, size)
return self return self
def backlight_auto_start(self):
sys_display.backlight_auto_start()
def backlight_auto_stop(self):
sys_display.backlight_auto_stop()
def wake(self):
sys_display.wake()
def tuck_in(self):
sys_display.tuck_in()
def set_timeout_cycles(self, timeout = 1000):
sys_display.set_timeout_cycles(timeout)
def set_brightness_table(self):
table = [min(100,(max(i-12,0)*10)) for i in range(300)]
sys_display.set_brightness_table(table)
open = Display.open open = Display.open
close = Display.close close = Display.close
...@@ -27,6 +27,12 @@ Q(TOP_RIGHT) ...@@ -27,6 +27,12 @@ Q(TOP_RIGHT)
/* buttons */ /* buttons */
Q(buttons) Q(buttons)
Q(read) Q(read)
Q(start)
Q(stop)
Q(get)
Q(get_memory)
Q(reset_memory)
Q(set_display_wake_mask)
Q(BOTTOM_LEFT) Q(BOTTOM_LEFT)
Q(TOP_LEFT) Q(TOP_LEFT)
Q(BOTTOM_RIGHT) Q(BOTTOM_RIGHT)
...@@ -92,6 +98,12 @@ Q(line) ...@@ -92,6 +98,12 @@ Q(line)
Q(rect) Q(rect)
Q(circ) Q(circ)
Q(clear) Q(clear)
Q(backlight_auto_start)
Q(backlight_auto_stop)
Q(wake)
Q(tuck_in)
Q(set_timeout_cycles)
Q(set_brightness_table)
/* ambient */ /* ambient */
Q(light_sensor) Q(light_sensor)
......
...@@ -252,6 +252,56 @@ static mp_obj_t mp_display_close() ...@@ -252,6 +252,56 @@ static mp_obj_t mp_display_close()
} }
static MP_DEFINE_CONST_FUN_OBJ_0(display_close_obj, mp_display_close); static MP_DEFINE_CONST_FUN_OBJ_0(display_close_obj, mp_display_close);
static mp_obj_t mp_display_backlight_auto_start()
{
epic_disp_backlight_auto_start();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(display_backlight_auto_start_obj, mp_display_backlight_auto_start);
static mp_obj_t mp_display_backlight_auto_stop()
{
epic_disp_backlight_auto_stop();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(display_backlight_auto_stop_obj, mp_display_backlight_auto_stop);
static mp_obj_t mp_display_wake()
{
epic_disp_wake();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(display_wake_obj, mp_display_wake);
static mp_obj_t mp_display_tuck_in()
{
epic_disp_tuck_in();
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(display_tuck_in_obj, mp_display_tuck_in);
static mp_obj_t mp_display_set_timeout_cycles(mp_obj_t cycles_in)
{
int cycles = mp_obj_get_int(cycles_in);
epic_disp_set_timeout_cycles(cycles);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(display_set_timeout_cycles_obj, mp_display_set_timeout_cycles);
static mp_obj_t mp_display_set_brightness_table(mp_obj_t table_in)
{
if(mp_obj_get_int(mp_obj_len(table_in)) != 300) {
mp_raise_ValueError("table must have 300 elements");
}
uint8_t table[300];
for (int i = 0; i< 256; i++) {
table[i] = mp_obj_get_int(mp_obj_subscr(table_in, mp_obj_new_int(i), MP_OBJ_SENTINEL));
}
epic_disp_set_brightness_table(table);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(display_set_brightness_table_obj, mp_display_set_brightness_table);
/* The globals table for this module */ /* The globals table for this module */
static const mp_rom_map_elem_t display_module_globals_table[] = { static const mp_rom_map_elem_t display_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_display) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_display) },
...@@ -266,6 +316,12 @@ static const mp_rom_map_elem_t display_module_globals_table[] = { ...@@ -266,6 +316,12 @@ static const mp_rom_map_elem_t display_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_circ), MP_ROM_PTR(&display_circ_obj) }, { MP_ROM_QSTR(MP_QSTR_circ), MP_ROM_PTR(&display_circ_obj) },
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&display_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&display_clear_obj) },
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&display_update_obj) }, { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&display_update_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight_auto_start), MP_ROM_PTR(&display_backlight_auto_start_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight_auto_stop), MP_ROM_PTR(&display_backlight_auto_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_wake), MP_ROM_PTR(&display_wake_obj) },
{ MP_ROM_QSTR(MP_QSTR_tuck_in), MP_ROM_PTR(&display_tuck_in_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_timeout_cycles), MP_ROM_PTR(&display_set_timeout_cycles_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_brightness_table), MP_ROM_PTR(&display_set_brightness_table_obj) },
}; };
static MP_DEFINE_CONST_DICT( static MP_DEFINE_CONST_DICT(
display_module_globals, display_module_globals_table display_module_globals, display_module_globals_table
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment