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

Add vibration function #128

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions node/code/modules/io_handler/include/init_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
extern "C" {
#endif

#include <stdio.h>
#include "thread.h"
#include "board.h"
#include "periph/gpio.h"
#include "events.h"


//TODO Workaround
extern kernel_pid_t dispatcher_pid;

//Buttons initialization functions prototypes:
int init_buttons(void);

void button_up_callback (void *arg);
Expand All @@ -20,6 +27,9 @@ void button_down_callback (void *arg);
void button_right_callback (void *arg);
void button_ok_callback (void *arg);

//Vibration functions prototypes:
void vibrate(uint16_t msec);

#ifdef __cplusplus
}
#endif
Expand Down
22 changes: 13 additions & 9 deletions node/code/modules/io_handler/init_buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,25 @@

#include "init_buttons.h"

#include <stdio.h>

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

#define ENABLE_DEBUG 1
#include "debug.h"

//Define the physical GPIO Pins used for buttons:
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

//Define the vibration module GPIO:
gpio_t vibr_gpio = GPIO_PIN(1, 9);
gpio_mode_t vibr_gpio_mode = GPIO_OUT;
gpio_mode_t vibr_gpio_mode = GPIO_OUT; //Define the vibr. GPIO as Output GPIO

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

//Initialize button interrupts and define callback funcs:
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);
Expand All @@ -48,11 +45,20 @@ int init_buttons(void)

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

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

//Vibrate for msec milliseconds:
void vibrate(uint16_t msec) {

gpio_set(vibr_gpio);
ztimer_sleep(ZTIMER_MSEC, msec);
gpio_clear(vibr_gpio);
}

void button_up_callback (void *arg)
{
(void) arg; /* the argument is not used */
Expand Down Expand Up @@ -117,5 +123,3 @@ void button_ok_callback (void *arg)
trigger_event(BUTTON_OK_RELEASED);
}
}


5 changes: 4 additions & 1 deletion node/code/modules/io_handler/io_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "init_buttons.h"
#include "io_handler.h"

//Define the vibration time (milliseconds) here:
#define VIBRATE_FOR_MSEC 500

void io_init(void){
init_buttons();
}
Expand All @@ -31,7 +34,7 @@ handler_result_t ioHandler_handleEvent(EVENT_T event){
switch(event){
case VIBRATE:
DEBUG("[IoHandler:handleEvent]: vibrate\n");
// vibrate();
vibrate(VIBRATE_FOR_MSEC);
break;
default:
break;
Expand Down