mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
update peripheral manager
This commit is contained in:
parent
c4d88309b5
commit
de1036cfcf
5 changed files with 100 additions and 17 deletions
|
|
@ -54,7 +54,8 @@ config button_map button_map
|
||||||
list buttonnames RESET
|
list buttonnames RESET
|
||||||
list buttonnames Wireless
|
list buttonnames Wireless
|
||||||
list buttonnames WPS
|
list buttonnames WPS
|
||||||
list buttonnames DECT
|
list buttonnames DECTS
|
||||||
|
list buttonnames DECTL
|
||||||
list buttonnames TOUCH_NEAR
|
list buttonnames TOUCH_NEAR
|
||||||
list buttonnames TOUCH_FAR
|
list buttonnames TOUCH_FAR
|
||||||
option minpress 100 # default minimum time a button nedes to be pressed.
|
option minpress 100 # default minimum time a button nedes to be pressed.
|
||||||
|
|
|
||||||
|
|
@ -71,12 +71,11 @@ struct function_action {
|
||||||
struct function_led {
|
struct function_led {
|
||||||
const char *name; /* If name is set this led function is in use by the board. */
|
const char *name; /* If name is set this led function is in use by the board. */
|
||||||
led_action_t state; /* state of the function led. contain what action is currently set */
|
led_action_t state; /* state of the function led. contain what action is currently set */
|
||||||
|
int brightness; /* Brightness of the led */
|
||||||
int press_indicator; /* record if this is part of press indictor */
|
int press_indicator; /* record if this is part of press indictor */
|
||||||
struct function_action actions[LED_ACTION_MAX];
|
struct function_action actions[LED_ACTION_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct function_led *leds; /* Array of functions, LED_FUNCTIONS + super_functions */
|
struct function_led *leds; /* Array of functions, LED_FUNCTIONS + super_functions */
|
||||||
static int total_functions; /* number of entries in leds array */
|
static int total_functions; /* number of entries in leds array */
|
||||||
|
|
||||||
|
|
@ -320,13 +319,37 @@ static int set_function_led(const char* fn_name, const char* action) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int brightness_function_led(const char* fn_name, int brightness) {
|
||||||
|
int led_idx = get_index_for_function(fn_name);
|
||||||
|
struct led *led;
|
||||||
|
|
||||||
|
if(led_idx == -1) {
|
||||||
|
syslog(LOG_WARNING, "called over ubus with non valid led name [%s]", fn_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
leds[led_idx].brightness = brightness;
|
||||||
|
|
||||||
|
list_for_each_entry(led, &leds[led_idx].actions[ leds[led_idx].state ].led_list, list) {
|
||||||
|
if (led->drv){
|
||||||
|
if (led->drv->func->set_brightness){
|
||||||
|
led->drv->func->set_brightness(led->drv, brightness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
LED_STATE,
|
LED_STATE,
|
||||||
|
LED_BRIGHTNESS,
|
||||||
__LED_MAX
|
__LED_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct blobmsg_policy led_policy[] = {
|
static const struct blobmsg_policy led_policy[] = {
|
||||||
[LED_STATE] = { .name = "state", .type = BLOBMSG_TYPE_STRING },
|
[LED_STATE] = { .name = "state", .type = BLOBMSG_TYPE_STRING },
|
||||||
|
[LED_BRIGHTNESS] = { .name = "brightness", .type = BLOBMSG_TYPE_INT32 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int led_set_method(struct ubus_context *ubus_ctx, struct ubus_object *obj,
|
static int led_set_method(struct ubus_context *ubus_ctx, struct ubus_object *obj,
|
||||||
|
|
@ -335,20 +358,26 @@ static int led_set_method(struct ubus_context *ubus_ctx, struct ubus_object *obj
|
||||||
{
|
{
|
||||||
struct blob_attr *tb[__LED_MAX];
|
struct blob_attr *tb[__LED_MAX];
|
||||||
char* state;
|
char* state;
|
||||||
|
int *number;
|
||||||
|
char *fn_name = strchr(obj->name, '.') + 1;
|
||||||
|
|
||||||
blobmsg_parse(led_policy, ARRAY_SIZE(led_policy), tb, blob_data(msg), blob_len(msg));
|
blobmsg_parse(led_policy, ARRAY_SIZE(led_policy), tb, blob_data(msg), blob_len(msg));
|
||||||
if (tb[LED_STATE]) {
|
if (tb[LED_STATE]) {
|
||||||
char *fn_name = strchr(obj->name, '.') + 1;
|
|
||||||
state = blobmsg_data(tb[LED_STATE]);
|
state = blobmsg_data(tb[LED_STATE]);
|
||||||
DBG(1,"set led [%s]->[%s]", fn_name, state);
|
DBG(1,"set led [%s]->[%s]", fn_name, state);
|
||||||
// syslog(LOG_INFO, "Led %s method: %s state %s", fn_name, method, state);
|
|
||||||
if (set_function_led(fn_name, state) ){
|
if (set_function_led(fn_name, state) ){
|
||||||
return UBUS_STATUS_NO_DATA;
|
return UBUS_STATUS_NO_DATA;
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
DBG(1,"(%s) not implemented",method);
|
|
||||||
return UBUS_STATUS_NO_DATA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tb[LED_BRIGHTNESS]) {
|
||||||
|
number = blobmsg_data(tb[LED_BRIGHTNESS]);
|
||||||
|
DBG(1,"set brightness [%s]->[%d]", fn_name, *number);
|
||||||
|
if (brightness_function_led(fn_name, *number) ){
|
||||||
|
return UBUS_STATUS_NO_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -362,6 +391,7 @@ static int led_status_method(struct ubus_context *ubus_ctx, struct ubus_object *
|
||||||
|
|
||||||
blob_buf_init (&bblob, 0);
|
blob_buf_init (&bblob, 0);
|
||||||
blobmsg_add_string(&bblob, "state",fn_actions[leds[led_idx].state]);
|
blobmsg_add_string(&bblob, "state",fn_actions[leds[led_idx].state]);
|
||||||
|
blobmsg_add_u32(&bblob, "brightness",leds[led_idx].brightness);
|
||||||
ubus_send_reply(ubus_ctx, req, bblob.head);
|
ubus_send_reply(ubus_ctx, req, bblob.head);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -682,6 +712,7 @@ void led_init( struct server_ctx *s_ctx)
|
||||||
|
|
||||||
/* Found led with action, init structs */
|
/* Found led with action, init structs */
|
||||||
leds[i].state = LED_OFF;
|
leds[i].state = LED_OFF;
|
||||||
|
leds[i].brightness = 100;
|
||||||
|
|
||||||
leds[i].actions[j].name = fn_actions[j];
|
leds[i].actions[j].name = fn_actions[j];
|
||||||
|
|
||||||
|
|
@ -744,7 +775,7 @@ void led_init( struct server_ctx *s_ctx)
|
||||||
DBG(1,"A:%s %s is a super function ",led_fn_name,super_action);
|
DBG(1,"A:%s %s is a super function ",led_fn_name,super_action);
|
||||||
|
|
||||||
list_for_each_entry(node, &super_action_list, list) {
|
list_for_each_entry(node, &super_action_list, list) {
|
||||||
char *s;
|
const char *s;
|
||||||
struct function_led *function;
|
struct function_led *function;
|
||||||
int action_ix;
|
int action_ix;
|
||||||
struct super_list *sl = malloc(sizeof(struct super_list));
|
struct super_list *sl = malloc(sizeof(struct super_list));
|
||||||
|
|
@ -755,7 +786,7 @@ void led_init( struct server_ctx *s_ctx)
|
||||||
DBG(1,"add to super list %s",node->val);
|
DBG(1,"add to super list %s",node->val);
|
||||||
|
|
||||||
s = node->val;
|
s = node->val;
|
||||||
while (s = get_function_action(s, &function, &action_ix)){
|
while ((s = get_function_action(s, &function, &action_ix))){
|
||||||
if (function) {
|
if (function) {
|
||||||
struct super_functions *sf = malloc(sizeof(struct super_functions));
|
struct super_functions *sf = malloc(sizeof(struct super_functions));
|
||||||
memset(sf, 0, sizeof(struct super_functions));
|
memset(sf, 0, sizeof(struct super_functions));
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ struct led_drv_func{
|
||||||
led_state_t (*get_state)(struct led_drv *); /* Get led state, on,off,flash ... */
|
led_state_t (*get_state)(struct led_drv *); /* Get led state, on,off,flash ... */
|
||||||
int (*set_color)(struct led_drv *, led_color_t); /* Set led color */
|
int (*set_color)(struct led_drv *, led_color_t); /* Set led color */
|
||||||
led_color_t (*get_color)(struct led_drv *); /* Get led color */
|
led_color_t (*get_color)(struct led_drv *); /* Get led color */
|
||||||
|
int (*set_brightness)(struct led_drv *, int ); /* Set led brightness */
|
||||||
|
int (*get_brightness)(struct led_drv *); /* Get led brightness */
|
||||||
int (*support) (struct led_drv *, led_state_t); /* do driver has hardware support for state */
|
int (*support) (struct led_drv *, led_state_t); /* do driver has hardware support for state */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@
|
||||||
#define SPI_SLAVE_SELECT 1
|
#define SPI_SLAVE_SELECT 1
|
||||||
|
|
||||||
struct vox_data {
|
struct vox_data {
|
||||||
int addr;
|
int addr;
|
||||||
led_state_t state;
|
led_state_t state;
|
||||||
|
int brightness;
|
||||||
struct led_drv led;
|
struct led_drv led;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -30,6 +31,8 @@ static int vox_set_state(struct led_drv *drv, led_state_t state)
|
||||||
if (p->state == state)
|
if (p->state == state)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
|
memset(spi_data, 0, 6);
|
||||||
|
|
||||||
spi_data[0] = p->addr;
|
spi_data[0] = p->addr;
|
||||||
|
|
||||||
if (state == ON) {
|
if (state == ON) {
|
||||||
|
|
@ -49,7 +52,7 @@ static int vox_set_state(struct led_drv *drv, led_state_t state)
|
||||||
spi_data[3] = 0x20;
|
spi_data[3] = 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG(1,"vox_set_state %x %x %x %x",spi_data[0],spi_data[1],spi_data[2],spi_data[3]);
|
DBG(2,"vox_set_state %x %x %x %x",spi_data[0],spi_data[1],spi_data[2],spi_data[3]);
|
||||||
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, spi_data, 6, 0);
|
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, spi_data, 6, 0);
|
||||||
|
|
||||||
p->state = state;
|
p->state = state;
|
||||||
|
|
@ -62,6 +65,47 @@ static led_state_t vox_get_state(struct led_drv *drv)
|
||||||
return p->state;
|
return p->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* input brightness is in %. 0-100 */
|
||||||
|
/* internal brightness is 5 steps. 0-4 */
|
||||||
|
/*
|
||||||
|
step, level percent mapping.
|
||||||
|
0 0 -> 20
|
||||||
|
1 21 -> 40
|
||||||
|
2 41 -> 60
|
||||||
|
3 61 -> 80
|
||||||
|
4 81 -> 100
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int vox_set_brightness(struct led_drv *drv, int level)
|
||||||
|
{
|
||||||
|
struct vox_data *p = (struct vox_data *)drv->priv;
|
||||||
|
int new = (level * 5)/101; /* really level/(101/5) */
|
||||||
|
char spi_data[6] = {0,0,0,0,0,0};
|
||||||
|
|
||||||
|
if (new == p->brightness)
|
||||||
|
return level;
|
||||||
|
|
||||||
|
p->brightness = new;
|
||||||
|
|
||||||
|
memset(spi_data, 0, 6);
|
||||||
|
|
||||||
|
spi_data[0] = p->addr;
|
||||||
|
spi_data[1] = 6;
|
||||||
|
spi_data[2] = p->brightness;
|
||||||
|
|
||||||
|
DBG(2,"vox_set_state %x %x %x %x",spi_data[0],spi_data[1],spi_data[2],spi_data[3]);
|
||||||
|
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, spi_data, 6, 0);
|
||||||
|
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vox_get_brightness(struct led_drv *drv)
|
||||||
|
{
|
||||||
|
struct vox_data *p = (struct vox_data *)drv->priv;
|
||||||
|
return p->brightness * (100/5);
|
||||||
|
}
|
||||||
|
|
||||||
static int vox_support(struct led_drv *drv, led_state_t state)
|
static int vox_support(struct led_drv *drv, led_state_t state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
@ -81,9 +125,11 @@ static int vox_support(struct led_drv *drv, led_state_t state)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct led_drv_func func = {
|
static struct led_drv_func func = {
|
||||||
.set_state = vox_set_state,
|
.set_state = vox_set_state,
|
||||||
.get_state = vox_get_state,
|
.get_state = vox_get_state,
|
||||||
.support = vox_support,
|
.set_brightness = vox_set_brightness,
|
||||||
|
.get_brightness = vox_get_brightness,
|
||||||
|
.support = vox_support,
|
||||||
};
|
};
|
||||||
|
|
||||||
void vox_init(struct server_ctx *s_ctx) {
|
void vox_init(struct server_ctx *s_ctx) {
|
||||||
|
|
@ -115,6 +161,7 @@ void vox_init(struct server_ctx *s_ctx) {
|
||||||
data->led.func = &func;
|
data->led.func = &func;
|
||||||
data->led.priv = data;
|
data->led.priv = data;
|
||||||
data->state = NEED_INIT;
|
data->state = NEED_INIT;
|
||||||
|
data->brightness = 4;
|
||||||
led_add(&data->led);
|
led_add(&data->led);
|
||||||
register_spi = 1;
|
register_spi = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,11 +163,13 @@ int main(int argc, char *argv[])
|
||||||
/* up */
|
/* up */
|
||||||
if (ch == 4283163) {
|
if (ch == 4283163) {
|
||||||
inc();
|
inc();
|
||||||
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, (char*)spi_data, 6, 0);
|
|
||||||
}
|
}
|
||||||
/* down */
|
/* down */
|
||||||
if (ch == 4348699) {
|
if (ch == 4348699) {
|
||||||
dec();
|
dec();
|
||||||
|
}
|
||||||
|
/* enter */
|
||||||
|
if (ch == '\r') {
|
||||||
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, (char*)spi_data, 6, 0);
|
board_ioctl(BOARD_IOCTL_SPI_WRITE, SPI_SLAVE_SELECT, 0, (char*)spi_data, 6, 0);
|
||||||
}
|
}
|
||||||
display();
|
display();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue