Skip to content

Commit

Permalink
event instrumented
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Oct 2, 2017
1 parent 723b374 commit a057c77
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions burba/apps/hello-mqtt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#define LED_YELLOW_BIT 1
#define LED_GREEN_BIT 2


// message types used in this demo
#define RETRY_TO_CONNECT 9000
#define BUTTON_PRESSED 9001

struct timer_msg {
xtimer_t timer;
Expand Down Expand Up @@ -78,20 +79,42 @@ uint32_t handle_command(uint8_t type, Command *command) {
return sts;
}

bocia_channel_t *app_init(void) {
bocia_channel_t *channel = bocia_init(0);

void app_init(void) {
if (!bocia_init(0)) {
if (!channel) {
DEBUG("connection failed, scheduling retry ...\n");
xtimer_set_msg(&retry.timer, retry.interval, &retry.msg,
thread_getpid());
thread_getpid());
}
return channel;
}

int main(void) {
static xtimer_ticks64_t previous_event_time = {0};

static kernel_pid_t main_pid;

void button_sw3_pressed(void *arg) {
msg_t msg;
xtimer_ticks64_t curr_time = xtimer_now64();

// 200 millisecond debounce period
if ((curr_time.ticks64 - previous_event_time.ticks64) > 16000000) {
msg.type = BUTTON_PRESSED;
msg_send(&msg, main_pid);
}
previous_event_time = curr_time;
}

int main(void) {
bocia_channel_t *channel = 0;
msg_t msg;
msg_t msg_queue[SBAPI_MSG_QUEUE_SIZE];

main_pid = thread_getpid();

gpio_init_int(PUSH1, GPIO_IN, GPIO_FALLING, button_sw3_pressed, NULL);

/* initialize message queue */
msg_init_queue(msg_queue, SBAPI_MSG_QUEUE_SIZE);

Expand All @@ -111,15 +134,23 @@ int main(void) {
printf("IP up, starting tcp client ...\n");

// run the client
app_init();
channel = app_init();

break;
case BOCIA_SOCK_CLOSED:
case RETRY_TO_CONNECT:
// connection failed or socket closed by peer: try to reconnect
app_init();
channel = app_init();
break;

case BUTTON_PRESSED: {
proto_msg_t ev_type = {EVENT_TYPE};
Event event = EVENT__INIT;
event.id = BUTTON_PRESSED;
if (channel) {
channel->send(channel, ev_type, &event);
}
break;
}
default:
DEBUG("unexpected message %d\n", msg.type);
}
Expand Down

0 comments on commit a057c77

Please sign in to comment.