52 #define PRINTF(...) printf(__VA_ARGS__)
57 #if PLATFORM_HAS_BUTTON
58 #include "dev/button-sensor.h"
60 PROCESS(ipso_button_process,
"ipso-button");
63 static int input_state = 0;
64 static int polarity = 0;
65 static int32_t counter = 0;
66 static int32_t edge_selection = 3;
67 static int32_t debounce_time = 10;
70 read_state(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
74 value = input_state ? 1 : 0;
76 value = input_state ? 0 : 1;
78 PRINTF(
"Read button state (polarity=%d, state=%d): %d\n",
79 polarity, input_state, value);
80 return ctx->writer->write_boolean(ctx, outbuf, outsize, value);
84 reset_counter(lwm2m_context_t *ctx,
const uint8_t *arg,
size_t len,
85 uint8_t *outbuf,
size_t outlen)
91 LWM2M_RESOURCES(button_resources,
92 LWM2M_RESOURCE_CALLBACK(5500, { read_state,
NULL, NULL }),
93 LWM2M_RESOURCE_INTEGER_VAR(5501, &counter),
94 LWM2M_RESOURCE_BOOLEAN_VAR(5502, &polarity),
95 LWM2M_RESOURCE_INTEGER_VAR(5503, &debounce_time),
96 LWM2M_RESOURCE_INTEGER_VAR(5504, &edge_selection),
97 LWM2M_RESOURCE_CALLBACK(5505, {
NULL,
NULL, reset_counter }),
98 LWM2M_RESOURCE_STRING(5751,
"Button")
100 LWM2M_INSTANCES(button_instances,
101 LWM2M_INSTANCE(0, button_resources));
102 LWM2M_OBJECT(button, 3200, button_instances);
105 ipso_button_init(
void)
109 lwm2m_engine_register_object(&button);
111 #if PLATFORM_HAS_BUTTON
116 #if PLATFORM_HAS_BUTTON
124 SENSORS_ACTIVATE(button_sensor);
129 if(ev == sensors_event && data == &button_sensor) {
133 if((edge_selection & 2) != 0) {
134 lwm2m_object_notify_observers(&button,
"/0/5500");
136 lwm2m_object_notify_observers(&button,
"/0/5501");
144 }
else if(ev == PROCESS_EVENT_TIMER && data == &
timer) {
147 }
else if(button_sensor.value(0) != 0) {
152 if((edge_selection & 1) != 0) {
153 lwm2m_object_notify_observers(&button,
"/0/5500");
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
Header file for the Contiki OMA LWM2M object API
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Header file for the Contiki OMA LWM2M engine
#define NULL
The null pointer.
#define CLOCK_SECOND
A second, measured in system clock time.
void process_start(struct process *p, process_data_t data)
Start a process.
CoAP implementation for the REST Engine.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
#define PROCESS_BEGIN()
Define the beginning of a process.