This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
funkey_gpio_management.c
executable file
·79 lines (64 loc) · 2.27 KB
/
funkey_gpio_management.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h> // Defines signal-handling functions (i.e. trap Ctrl-C)
#include <sys/select.h>
#include "gpio-utils.h"
#include <assert.h>
#include "uinput.h"
#include "gpio_mapping.h"
#include "read_conf_file.h"
/****************************************************************
* Defines
****************************************************************/
/****************************************************************
* Global variables
****************************************************************/
int keepgoing = 1; // Set to 0 when ctrl-c is pressed
/****************************************************************
* signal_handler
****************************************************************/
void signal_handler(int sig);
// Callback called when SIGINT is sent to the process (Ctrl-C)
void signal_handler(int sig)
{
printf( "Ctrl-C pressed, cleaning up and exiting..\n" );
keepgoing = 0;
}
/****************************************************************
* Local functions
****************************************************************/
/****************************************************************
* Main
****************************************************************/
int main(int argc, char **argv, char **envp)
{
// Variables
STRUCT_MAPPED_GPIO * chained_list_mapping = NULL;
int nb_valid_gpios = 0;
int * gpio_pins_idx_declared = NULL;
bool * gpios_pins_active_high = NULL;
// Set the signal callback for Ctrl-C
signal(SIGINT, signal_handler);
// Init uinput device
init_uinput();
// Read Conf File: Get GPIO pins to declare and all valid pin mappings
get_mapping_from_conf_file(&chained_list_mapping, &nb_valid_gpios, &gpio_pins_idx_declared, &gpios_pins_active_high);
// Init GPIOs
init_mapping_gpios(gpio_pins_idx_declared, gpios_pins_active_high, nb_valid_gpios, chained_list_mapping);
// Main Loop
while (keepgoing) {
listen_gpios_interrupts();
}
// De-Init GPIOs
deinit_mapping_gpios();
/*
* Give userspace some time to read the events before we destroy the
* device with UI_DEV_DESTOY.
*/
close_uinput();
return 0;
}