Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Buttons - with workaround working (#91)
Browse files Browse the repository at this point in the history
need this for other parts. 
 
Workaround should change later, but at the moment the problem with the c
and c++ elements persists.
  • Loading branch information
moritzholzer authored May 30, 2024
2 parents b7779f1 + cc46540 commit 2af0ba7
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 0 deletions.
1 change: 1 addition & 0 deletions node/code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DIR += test_folder

FEATURES_REQUIRED += cpp
FEATURES_REQUIRED += libstdcpp
FEATURES_REQUIRED += periph_gpio_irq

# Internal Modules
# Teamagotchi MODULES
Expand Down
5 changes: 5 additions & 0 deletions node/code/modules/io_handler/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifneq (,$(filter io_handler,$(USEMODULE))) # if module in USEMODULE
USEMODULE += periph_gpio_irq
endif


5 changes: 5 additions & 0 deletions node/code/modules/io_handler/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# # Use an immediate variable to evaluate `MAKEFILE_LIST` now
# USEMODULE_INCLUDES_io_handler := $(LAST_MAKEFILEDIR)/include
# USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_io_handler)

INCLUDES += -I$(LAST_MAKEFILEDIR)/include
151 changes: 151 additions & 0 deletions node/code/modules/io_handler/init_buttons.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright (C) 2024 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
* @brief Vibration Module and Buttons Initialization
*
* @author Eduard Lomtadze <[email protected]>
* @}
*/

#include "init_buttons.h"

#include <stdio.h>

#include "board.h"
#include "periph/gpio.h"

#define ENABLE_DEBUG 1
#include "debug.h"

//TODO Workaround
kernel_pid_t dispatcher_pid;
uint16_t BUTTON_OK_PRESSED = 4;
uint16_t BUTTON_OK_RELEASED = 5;
uint16_t BUTTON_UP_PRESSED = 6;
uint16_t BUTTON_UP_RELEASED = 7;
uint16_t BUTTON_LEFT_PRESSED = 8;
uint16_t BUTTON_LEFT_RELEASED = 9;
uint16_t BUTTON_DOWN_PRESSED = 10;
uint16_t BUTTON_DOWN_RELEASED = 11;
uint16_t BUTTON_RIGHT_PRESSED = 12;
uint16_t BUTTON_RIGHT_RELEASED = 13;



//TODO: change the actual pin layout according to PCB Design
gpio_t button_ok = GPIO_PIN(0, 5); //PIN A1
gpio_t button_right = GPIO_PIN(0, 30); //PIN sA2
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

gpio_t vibr_gpio = GPIO_PIN(1, 9);
gpio_mode_t vibr_gpio_mode = GPIO_OUT;

int init_buttons(void)
{
puts("Buttons initialization...");

gpio_init_int(button_up, GPIO_IN, GPIO_BOTH, button_up_callback, NULL);
gpio_init_int(button_left, GPIO_IN, GPIO_BOTH, button_left_callback, NULL);
gpio_init_int(button_down, GPIO_IN, GPIO_BOTH, button_down_callback, NULL);
gpio_init_int(button_right, GPIO_IN, GPIO_BOTH, button_right_callback, NULL);
gpio_init_int(button_ok, GPIO_IN, GPIO_BOTH, button_ok_callback, NULL);

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

gpio_init(vibr_gpio, vibr_gpio_mode);
gpio_clear(vibr_gpio);
return 0;
}

void button_up_callback (void *arg)
{
(void) arg; /* the argument is not used */
msg_t message;
if (!gpio_read(button_up)) {
DEBUG("Button up pressed!\n");
message.type = BUTTON_UP_PRESSED;
msg_try_send(&message, dispatcher_pid);
}
else {
DEBUG("Button up released!\n");
message.type = BUTTON_UP_RELEASED;
msg_try_send(&message, dispatcher_pid);
}
}

void button_left_callback (void *arg)
{
(void) arg; /* the argument is not used */
msg_t message;
if (!gpio_read(button_left)) {
DEBUG("Button left pressed!\n");
message.type = BUTTON_LEFT_PRESSED;
msg_try_send(&message, dispatcher_pid);
}
else {
DEBUG("Button left released!\n");
message.type = BUTTON_LEFT_RELEASED;
msg_try_send(&message, dispatcher_pid);
}
}

void button_down_callback (void *arg)
{
(void) arg; /* the argument is not used */
msg_t message;
if (!gpio_read(button_down)) {
DEBUG("Button down pressed!\n");
message.type = BUTTON_DOWN_PRESSED;
msg_try_send(&message, dispatcher_pid);
}
else {
DEBUG("Button down released!\n");
message.type = BUTTON_DOWN_RELEASED;
msg_try_send(&message, dispatcher_pid);
}
}

void button_right_callback (void *arg)
{
(void) arg; /* the argument is not used */
msg_t message;
if (!gpio_read(button_right)) {
DEBUG("Button right pressed!\n");
message.type = BUTTON_RIGHT_PRESSED;
msg_try_send(&message, dispatcher_pid);
}
else {
DEBUG("Button right released!\n");
message.type = BUTTON_RIGHT_RELEASED;
msg_try_send(&message, dispatcher_pid);
}
}

void button_ok_callback (void *arg)
{
(void) arg; /* the argument is not used */
msg_t message;
if (!gpio_read(button_ok)) {
DEBUG("Button ok pressed!\n");
message.type = BUTTON_OK_PRESSED;
msg_try_send(&message, dispatcher_pid);
}
else {
DEBUG("Button ok released!\n");
message.type = BUTTON_OK_RELEASED;
msg_try_send(&message, dispatcher_pid);
}
}


42 changes: 42 additions & 0 deletions node/code/modules/io_handler/io_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @{
*
* @file
* @brief IO Handler: Vibration module and buttons initialization
*
* @author Eduard Lomtadze <[email protected]>
* @}
*/

#define ENABLE_DEBUG 0
#include "debug.h"

#include "init_buttons.h"
#include "io_handler.hpp"

IoHandler::IoHandler(){
}

void IoHandler::init(){
dispatcher_pid = DISPATCHER_PID;
init_buttons();
}

void IoHandler::handleEvent(msg_t *event){
DEBUG("[IoHandler:handleEvent]\n");
(void) event;
// switch(event->type){
// case EVENTS::VIBRATE :
// DEBUG("[IoHandler:handleEvent]: vibrate\n");
// vibrate();
// break;
// }s
}

0 comments on commit 2af0ba7

Please sign in to comment.