-
Notifications
You must be signed in to change notification settings - Fork 4
/
info_disp.c
125 lines (113 loc) · 2.83 KB
/
info_disp.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "menu_objs.h"
#include <sys/file.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "plcm_ioctl.h"
int main(int argc, char *argv[])
{
unsigned char Keypad_Value = 0;
unsigned char detect_dir;
unsigned char detect_press;
unsigned char Pre_Value = 0;
char Keypad_Message[19] = "";
int btn1_state = 0;
int btn2_state = 0;
int btn3_state = 0;
int btn4_state = 0;
unsigned char Cur_Display = 0x08; // Current Display On/Off Ctrl
unsigned char Ctrl = 0;
if(argc == 2)
{
if(strcmp("-stop", argv[1]) == 0)
{
printf("plcm_drv thread has been stopped.\n");
printf("sled_drv : PLCM_IOCTL_STOP_THREAD\n");
goto out;
}
}
// creates all the menus and items in the menu_objs c file
initialize_menus_and_items();
current_menu = main_menu;
devfd = open("/dev/plcm_drv", O_RDWR);
if(devfd == -1)
{
printf("Can't open /dev/plcm_drv\n");
return -1;
}
// stops cursor from blinking
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 0);
ioctl(devfd, PLCM_IOCTL_DISPLAY_C, 0);
//clear previous keypad status
ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
// shows the titles of each of the menu items
show_menu(current_menu);
Pre_Value = ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
// this do while loop checks for button preses and then executes the functions on each menu item
do{
ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
Keypad_Value = ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
if(Pre_Value != Keypad_Value)
{
detect_press=(Keypad_Value & 0x40);
detect_dir=(Keypad_Value & 0x28);
if(detect_press == 0x40){
switch(detect_dir){
case 0x20: // left
btn2_state = 0;
btn3_state = 0;
btn4_state = 0;
if(btn1_state == 1){
show_menu(current_menu);
btn1_state = 0;
}else{
on_btn_press(current_menu.item1);
btn1_state = 1;
}
break;
case 0x00: // up
btn1_state = 0;
btn3_state = 0;
btn4_state = 0;
if(btn2_state == 1){
show_menu(current_menu);
btn2_state = 0;
}else{
on_btn_press(current_menu.item2);
btn2_state = 1;
}
break;
case 0x08: // down
btn1_state = 0;
btn2_state = 0;
btn4_state = 0;
if(btn3_state == 1){
show_menu(current_menu);
btn3_state = 0;
}else{
on_btn_press(current_menu.item3);
btn3_state = 1;
}
break;
case 0x28: // right
btn1_state = 0;
btn2_state = 0;
btn3_state = 0;
if(btn4_state == 1){
show_menu(current_menu);
btn4_state = 0;
}else{
on_btn_press(current_menu.item4);
btn4_state = 1;
}
break;
}
}
Pre_Value = Keypad_Value;
}
usleep(10000);
}while(1);
out:
close(devfd);
return 0;
}