Skip to content

Commit

Permalink
display on/off and registration (#145)
Browse files Browse the repository at this point in the history
Able to turn on/off display by long pressing the OK Button
  • Loading branch information
moritzholzer authored Jun 24, 2024
2 parents e7cdb46 + 152e562 commit 6dfc782
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
4 changes: 2 additions & 2 deletions node/code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE='(3*1024)'
# Uncomment to enable Wakaama debug log
#CFLAGS += -DCONFIG_LWM2M_WITH_LOGS=1
# Specific the server URI address (NOTE: Domain names not supported yet)
LWM2M_SERVER_URI ?= '"coap://[2001:db8:1::1]:5683"'
# LWM2M_SERVER_URI ?= '"coap://[fd00:dead:beef::1]:5683"'
# LWM2M_SERVER_URI ?= '"coap://[2001:db8:1::1]:5683"'
LWM2M_SERVER_URI ?= '"coap://[fd00:dead:beef::1]:5683"'
# Configure via CFLAGS only if not done via Kconfig
ifndef CONFIG_LWM2M_SERVER_URI
CFLAGS += -DCONFIG_LWM2M_SERVER_URI=$(LWM2M_SERVER_URI)
Expand Down
4 changes: 2 additions & 2 deletions node/code/modules/display_handler/display_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ handler_result_t displayHandler_handleEvent(EVENT_T event){
right_released();
break;
case REGISTER_CODE:
//init_not_registered_code(get_register_code());
init_not_registered_code("Hallo Tom");
init_not_registered_code(get_register_code());
//init_not_registered_code("Hallo Tom");
break;
case REGISTERED:
init_registered_no_pet();
Expand Down
8 changes: 7 additions & 1 deletion node/code/modules/fsm/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ handler_result_t on_handler(EVENT_T event) {
void on_entry(void) {
DEBUG("[FSM:on_entry_handler]: called\n");
ioHandler_handleEvent(VIBRATE);
ioHandler_handleEvent(SCREEN_ON);
traverse_state(&On_Level[0]); //wie gehe ich in den Child State
}

Expand Down Expand Up @@ -226,6 +227,8 @@ void off_entry(void) {
display_init();
startDisplayThread();
}
ioHandler_handleEvent(SCREEN_OFF);
ioHandler_handleEvent(VIBRATE);
}

void off_exit(void) {
Expand All @@ -234,8 +237,11 @@ void off_exit(void) {

handler_result_t unregistered_handler(EVENT_T event) {
switch (event) {
case REGISTERED:
case REGISTER_CODE:
displayHandler_handleEvent(REGISTERED);
displayHandler_handleEvent(REGISTER_CODE);
return HANDLED;
case REGISTERED:
traverse_state(&On_Level[1]);
return HANDLED;
default:
Expand Down
2 changes: 2 additions & 0 deletions node/code/modules/fsm/include/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ typedef enum {
PET_BORED,
PET_DIRTY,
VIBRATE,
SCREEN_OFF,
SCREEN_ON,
INIT,
REGISTER,
REGISTERED,
Expand Down
3 changes: 3 additions & 0 deletions node/code/modules/io_handler/include/init_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void button_down_callback (void *arg);
void button_right_callback (void *arg);
void button_ok_callback (void *arg);

//Screen functions:
void screen_off(void);
void screen_on(void);
void timer_long_pressed_cb(void *arg);

//Vibration functions prototypes:
Expand Down
16 changes: 16 additions & 0 deletions node/code/modules/io_handler/init_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ gpio_t button_up = GPIO_PIN(0, 28); //PIN A3
gpio_t button_down = GPIO_PIN(0, 2); //PIN A4
gpio_t button_left = GPIO_PIN(0, 3); //PIN A5

//For turning screen on and off:
gpio_t screen_gpio = GPIO_PIN(0, 7); //PIN 6
gpio_mode_t screen_gpio_mode = GPIO_OUT; //Define the screen GPIO as Output GPIO

//Define the vibration module GPIO:
gpio_t vibr_gpio = GPIO_PIN(1, 9);
gpio_mode_t vibr_gpio_mode = GPIO_OUT; //Define the vibr. GPIO as Output GPIO
Expand All @@ -50,12 +54,24 @@ int init_buttons(void)

puts("Vibration Module initialization...");

//Initialize screen gpio
gpio_init(screen_gpio, screen_gpio_mode);
gpio_set(screen_gpio);

//Initialize vibration module
gpio_init(vibr_gpio, vibr_gpio_mode);
gpio_clear(vibr_gpio);
return 0;
}

void screen_off(void) {
gpio_clear(screen_gpio);
}

void screen_on(void) {
gpio_set(screen_gpio);
}

void timer_long_pressed_cb(void *arg) {
(void) arg;
long_pressed = true;
Expand Down
8 changes: 8 additions & 0 deletions node/code/modules/io_handler/io_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ handler_result_t ioHandler_handleEvent(EVENT_T event){
DEBUG("[IoHandler:handleEvent]: vibrate\n");
vibrate(VIBRATE_FOR_MSEC);
break;
case SCREEN_OFF:
DEBUG("[IoHandler:handleEvent]: screen_off\n");
screen_off();
break;
case SCREEN_ON:
DEBUG("[IoHandler:handleEvent]: screen_on\n");
screen_on();
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion node/code/modules/lwm2m_handler/include/device_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "lwm2m_client.h"

#ifndef CONFIG_LWM2M_STRING_MAX_SIZE
#define CONFIG_LWM2M_STRING_MAX_SIZE 8
#define CONFIG_LWM2M_STRING_MAX_SIZE 20
#endif

#define LWM2M_DEVICE_STATUS_ID 0
Expand Down

0 comments on commit 6dfc782

Please sign in to comment.