Updated IPSO button to use the button HAL pressed/released events.
Removed support for the optional polarity resource to simplify the code.
This commit is contained in:
parent
c87aadc390
commit
9b37e4b7fb
@ -56,7 +56,6 @@
|
|||||||
|
|
||||||
#define IPSO_INPUT_STATE 5500
|
#define IPSO_INPUT_STATE 5500
|
||||||
#define IPSO_INPUT_COUNTER 5501
|
#define IPSO_INPUT_COUNTER 5501
|
||||||
#define IPSO_INPUT_POLARITY 5502
|
|
||||||
#define IPSO_INPUT_DEBOUNCE 5503
|
#define IPSO_INPUT_DEBOUNCE 5503
|
||||||
#define IPSO_INPUT_EDGE_SEL 5504
|
#define IPSO_INPUT_EDGE_SEL 5504
|
||||||
#define IPSO_INPUT_CTR_RESET 5505
|
#define IPSO_INPUT_CTR_RESET 5505
|
||||||
@ -79,13 +78,12 @@ static lwm2m_status_t lwm2m_callback(lwm2m_object_instance_t *object,
|
|||||||
lwm2m_context_t *ctx);
|
lwm2m_context_t *ctx);
|
||||||
|
|
||||||
static int input_state = 0;
|
static int input_state = 0;
|
||||||
static int polarity = 0;
|
|
||||||
static int32_t counter = 0;
|
static int32_t counter = 0;
|
||||||
static int32_t edge_selection = 3; /* both */
|
static int32_t edge_selection = 3; /* both */
|
||||||
static int32_t debounce_time = 10;
|
static int32_t debounce_time = 10;
|
||||||
|
|
||||||
static const lwm2m_resource_id_t resources[] = {
|
static const lwm2m_resource_id_t resources[] = {
|
||||||
RO(IPSO_INPUT_STATE), RO(IPSO_INPUT_COUNTER), RW(IPSO_INPUT_POLARITY),
|
RO(IPSO_INPUT_STATE), RO(IPSO_INPUT_COUNTER),
|
||||||
RW(IPSO_INPUT_DEBOUNCE), RW(IPSO_INPUT_EDGE_SEL), EX(IPSO_INPUT_CTR_RESET),
|
RW(IPSO_INPUT_DEBOUNCE), RW(IPSO_INPUT_EDGE_SEL), EX(IPSO_INPUT_CTR_RESET),
|
||||||
RO(IPSO_INPUT_SENSOR_TYPE)
|
RO(IPSO_INPUT_SENSOR_TYPE)
|
||||||
};
|
};
|
||||||
@ -103,15 +101,8 @@ static lwm2m_object_instance_t reg_object = {
|
|||||||
static int
|
static int
|
||||||
read_state(void)
|
read_state(void)
|
||||||
{
|
{
|
||||||
int value;
|
PRINTF("Read button state: %d\n", input_state);
|
||||||
if(polarity == 0) {
|
return input_state;
|
||||||
value = input_state ? 1 : 0;
|
|
||||||
} else {
|
|
||||||
value = input_state ? 0 : 1;
|
|
||||||
}
|
|
||||||
PRINTF("Read button state (polarity=%d, state=%d): %d\n",
|
|
||||||
polarity, input_state, value);
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
@ -127,9 +118,6 @@ lwm2m_callback(lwm2m_object_instance_t *object,
|
|||||||
case IPSO_INPUT_COUNTER:
|
case IPSO_INPUT_COUNTER:
|
||||||
lwm2m_object_write_int(ctx, counter);
|
lwm2m_object_write_int(ctx, counter);
|
||||||
break;
|
break;
|
||||||
case IPSO_INPUT_POLARITY:
|
|
||||||
lwm2m_object_write_int(ctx, polarity);
|
|
||||||
break;
|
|
||||||
case IPSO_INPUT_DEBOUNCE:
|
case IPSO_INPUT_DEBOUNCE:
|
||||||
lwm2m_object_write_int(ctx, debounce_time);
|
lwm2m_object_write_int(ctx, debounce_time);
|
||||||
break;
|
break;
|
||||||
@ -177,13 +165,20 @@ PROCESS_THREAD(ipso_button_process, ev, data)
|
|||||||
PROCESS_WAIT_EVENT();
|
PROCESS_WAIT_EVENT();
|
||||||
|
|
||||||
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
/* ToDo */
|
if(ev == button_hal_press_event) {
|
||||||
if(ev == button_hal_release_event) {
|
input_state = 1;
|
||||||
lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE);
|
counter++;
|
||||||
} else if(ev == button_hal_periodic_event) {
|
if((edge_selection & 2) != 0) {
|
||||||
|
lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE);
|
||||||
|
}
|
||||||
lwm2m_notify_object_observers(®_object, IPSO_INPUT_COUNTER);
|
lwm2m_notify_object_observers(®_object, IPSO_INPUT_COUNTER);
|
||||||
|
} else if(ev == button_hal_release_event) {
|
||||||
|
input_state = 0;
|
||||||
|
if((edge_selection & 1) != 0) {
|
||||||
|
lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else /* PLATFORM_SUPPORTS_BUTTON_HAL */
|
||||||
if(ev == sensors_event && data == &IPSO_BUTTON_SENSOR) {
|
if(ev == sensors_event && data == &IPSO_BUTTON_SENSOR) {
|
||||||
if(!input_state) {
|
if(!input_state) {
|
||||||
int32_t time;
|
int32_t time;
|
||||||
@ -213,7 +208,7 @@ PROCESS_THREAD(ipso_button_process, ev, data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* PLATFORM_SUPPORTS_BUTTON_HAL */
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
|
Loading…
Reference in New Issue
Block a user