permngr: Add longpress indicator.

If the board has press indicator configured and a longpress option
the press indicator leds will stop flashing once the longpress time is
reached.

refs #7959
This commit is contained in:
Kenneth Johansson 2015-12-09 11:35:19 +01:00
parent 4940ba3428
commit 207c769970
3 changed files with 32 additions and 16 deletions

View file

@ -285,7 +285,7 @@ static void button_handler(struct uloop_timeout *timeout)
#endif
/* clean out indicator status, set by any valid press again if we find it */
led_pressindicator_clear();
led_pressindicator_set(PRESS_NONE);
list_for_each(i, &buttons) {
struct list_head *j;
@ -294,6 +294,7 @@ static void button_handler(struct uloop_timeout *timeout)
list_for_each(j, &node->drv_list) {
struct button_drv_list *drv_node = list_entry(j, struct button_drv_list, list);
if (drv_node->drv) {
button_press_type_t time_type;
button_state_t st = drv_node->drv->func->get_state(drv_node->drv);
if (st == BUTTON_PRESSED ) {
@ -302,8 +303,12 @@ static void button_handler(struct uloop_timeout *timeout)
DBG(1, " %s pressed", drv_node->drv->name);
// button_ubus_interface_event(global_ubus_ctx, node->name, BUTTON_PRESSED);
}
if(timer_valid(drv_node, node->minpress, 0))
led_pressindicator_set();
time_type = timer_valid(drv_node, node->minpress, node->longpress);
if( time_type == BUTTON_PRESS_LONG )
led_pressindicator_set(PRESS_LONG);
if( time_type == BUTTON_PRESS_SHORT )
led_pressindicator_set(PRESS_SHORT);
}
if (st == BUTTON_RELEASED ) {
@ -313,6 +318,7 @@ static void button_handler(struct uloop_timeout *timeout)
button_ubus_interface_event(global_ubus_ctx, node->name, BUTTON_RELEASED);
if(node->dimming)
led_dimming();
DBG(1, " %s released timer_valid=%d", drv_node->drv->name,r);
button_hotplug_cmd(node->name, r==BUTTON_PRESS_LONG);
}
}

View file

@ -81,8 +81,8 @@ struct function_led {
struct function_led *leds; /* Array of functions, LED_FUNCTIONS + super_functions */
static int total_functions; /* number of entries in leds array */
static leds_state_t global_state; /* global state for the leds,overrids individual states */
static leds_state_t press_state; /* global state for the press indicator */
static leds_state_t global_state; /* global state for the leds,overrids individual states */
static press_t press_state; /* global state for the press indicator */
static led_action_t dimming_level; /* The min level where dimming should not happen on led */
static int dimming_timeout; /* The time to turn on leds when we have dimming on */
@ -294,7 +294,7 @@ static void super_update(void)
}
if (status){
leds[i].state = j;
DBG(1,"\tSet super function [%s] to action [%s]",leds[i].name, fn_actions[j]);
DBG(3,"\tSet super function [%s] to action [%s]",leds[i].name, fn_actions[j]);
}
}
}
@ -537,11 +537,15 @@ static void flash_handler(struct uloop_timeout *timeout)
global_state == LEDS_INFO ) {
for (i = 0; i < total_functions ; i++) {
struct led *led;
if (leds[i].press_indicator & press_state) {
if (leds[i].press_indicator && (press_state != PRESS_NONE) ) {
// DBG(1,"INDICATE_PRESS on %s",leds[i].name);
list_for_each_entry(led, &leds[i].actions[leds[i].state].led_list, list) {
if (led->drv)
led->drv->func->set_state(led->drv, fast);
if (led->drv){
if (press_state == PRESS_LONG)
led->drv->func->set_state(led->drv, ON);
else
led->drv->func->set_state(led->drv, fast);
}
}
/* normal operation, flash else reset state */
@ -609,12 +613,13 @@ static void flash_handler(struct uloop_timeout *timeout)
uloop_timeout_set(&flash_inform_timer, FLASH_TIMEOUT);
}
void led_pressindicator_set(void){
press_state = 1;
}
void led_pressindicator_set(press_t type){
void led_pressindicator_clear(void){
press_state = 0;
/* press long has prio over short so if it's already set to long do not change */
if (type == PRESS_SHORT && press_state == PRESS_LONG)
return;
press_state = type;
}
void led_dimming(void){

View file

@ -24,6 +24,12 @@ typedef enum {
WHITE,
} led_color_t;
typedef enum {
PRESS_NONE,
PRESS_SHORT,
PRESS_LONG,
} press_t;
struct led_drv;
struct led_drv_func{
@ -46,7 +52,6 @@ void led_add( struct led_drv *);
void led_init(struct server_ctx *);
void led_dimming(void);
void led_pressindicator_set(void);
void led_pressindicator_clear(void);
void led_pressindicator_set(press_t type);
#endif /* LED_H */