-
Notifications
You must be signed in to change notification settings - Fork 6
/
buttons.c
84 lines (73 loc) · 1.21 KB
/
buttons.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
80
81
82
83
84
/*****************************************/
/* Developed by j0lama */
/* Visit www.jolama.es for more details */
/*****************************************/
#include <stdio.h>
#include <stdlib.h>
#include "buttons.h"
/*Buttons*/
#define SQUARE 0
#define CROSS 1
#define CIRCLE 2
#define TRIANGLE 3
#define L1 4
#define R1 5
#define SHARE 8
#define OPTIONS 9
#define L3 10
#define R3 11
#define PSN 12
#define UP 21
#define DOWN 22
#define LEFT 23
#define RIGHT 24
#define L2 30
#define R2 31
/*Common button status*/
#define PRESSED 1
#define NO_PRESSED 0
#define OK 0
#define ERROR -1
struct _button
{
int status;
int value;
};
button * ini_button(int value)
{
button * b = NULL;
if(value < 0)
return NULL;
b = (button *)malloc(sizeof(button));
if(b == NULL)
return NULL;
b->status = NO_PRESSED;
b->value = value;
return b;
}
int free_button(button * b)
{
if(b == NULL)
return ERROR;
free(b);
return OK;
}
int button_set_status(button * b, int status)
{
if(b == NULL)
return ERROR;
b->status = status;
return OK;
}
int button_get_status(button * b)
{
if(b == NULL)
return ERROR;
return b->status;
}
int button_get_value(button * b)
{
if(b == NULL)
return ERROR;
return b->value;
}