Commit 76a51b64 authored by fleur's avatar fleur
Browse files

just a quick save, tons of stuff missing

parent 37da10f9
...@@ -4,14 +4,22 @@ ...@@ -4,14 +4,22 @@
#include "portexpander.h" #include "portexpander.h"
#include "MAX77650-Arduino-Library.h" #include "MAX77650-Arduino-Library.h"
#include "FreeRTOS.h"
#include "timers.h"
#include <stdint.h> #include <stdint.h>
#define FREQ 100
static const uint8_t pin_mask[] = { static const uint8_t pin_mask[] = {
[BUTTON_LEFT_BOTTOM] = 1 << 5, [BUTTON_LEFT_BOTTOM] = 1 << 5,
[BUTTON_RIGHT_BOTTOM] = 1 << 3, [BUTTON_RIGHT_BOTTOM] = 1 << 3,
[BUTTON_RIGHT_TOP] = 1 << 6, [BUTTON_RIGHT_TOP] = 1 << 6,
}; };
static uint8_t last;
static uint8_t display_wake_mask = 0xF;
static Timer_Handle_t poll_timer;
static StaticTimer_t poll_timer_buffer;
uint8_t epic_buttons_read(uint8_t mask) uint8_t epic_buttons_read(uint8_t mask)
{ {
...@@ -43,3 +51,36 @@ uint8_t epic_buttons_read(uint8_t mask) ...@@ -43,3 +51,36 @@ uint8_t epic_buttons_read(uint8_t mask)
return ret; return ret;
} }
static void CALLBACK_buttons(){
last = epic_buttons_read(0xF);
if(last & display_wake_mask){
epic_disp_wake();
}
}
void epic_buttons_start(){
if(!poll_timer) {
poll_timer = xTimerCreateStatic(
"buttons",
FREQ,
pdTRUE,
NULL,
CALLBACK_buttons,
&poll_timer_buffer
);
}
}
void epic_buttons_set_display_wake_mask(uint8_t mask){
display_wake_mask = mask;
}
uint8_t epic_buttons_get(){
return last;
}
void epic_buttons_stop(){
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0);
}
...@@ -8,8 +8,21 @@ ...@@ -8,8 +8,21 @@
#include "task.h" #include "task.h"
#include "tmr.h" #include "tmr.h"
#include "tmr_utils.h" #include "tmr_utils.h"
#include "FreeRTOS.h"
#include "timers.h"
#define MAX_BRIGHTNESS 300
#define FREQ 100
static TaskHandle_t lock = NULL; static TaskHandle_t lock = NULL;
static TimerHandle_t poll_timer;
static StaticTimer_t poll_timer_buffer;
static bool display_on;
static bool wake_event;
static uint16_t timeout_cycles = 1000;
static uint8_t lpf_speed = 10; //ca. 1Hz f_g
static uint8_t brightness_table[MAX_BRIGHTNESS];
static int check_lock() static int check_lock()
{ {
...@@ -21,6 +34,76 @@ static int check_lock() ...@@ -21,6 +34,76 @@ static int check_lock()
} }
} }
void epic_disp_set_brightness_table(uint8_t table[MAX_BRIGHTNESS])
{
for (int i = 0; i < MAX_BRIGHTNESS; i++){
brightness_table[i]=table[i];
}
}
static uint16_t limit(uint16_t input, uint16_t max, uint16_t min){
uint16_t output = input > max ? max : input;
return output < 0 ? 0 : output;
}
static uint16_t lpf(uint16_t input, uint8_t speed){
static uint16_t output;
output = speed*input+(~speed)*output;
output = output >> 8;
return output;
}
static void auto_backlight(){
uint16_t light = 0;
if(display_on){
epic_light_sensor_get(&light);
light = brightness_table[limit(light,MAX_BRIGHTNESS-1,0)];
}
uint16_t lpf_light = lpf(light, lpf_speed);
lpf_light = limit(lpf_light,100,display_on);
epic_disp_backlight(lpf_light);
}
void epic_disp_wake(){
wake_event = true;
}
static void CALLBACK_power_mgmt(){ //u gotta loop dis
uint16_t buttonTimeout = 0;
if(!timeout_cycles){
display_on = true;
} else if(wake_event){
buttonTimeout = timeout_cycles;
display_on = true;
wake_event = false;
} else if(buttonTimeout){
buttonTimeout--;
} else {
display_on = false;
}
auto_backlight();
}
void epic_disp_backlight_auto_stop()
{
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { return; }
xTimerStop(poll_timer, 0);
}
void epic_disp_backlight_auto(){
if(!poll_timer) {
poll_timer = xTimerCreateStatic(
"auto_backlight",
FREQ,
pdTRUE,
NULL,
CALLBACK_power_mgmt,
&poll_timer_buffer
);
}
}
int epic_disp_print( int epic_disp_print(
uint16_t posx, uint16_t posx,
uint16_t posy, uint16_t posy,
......
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