Repository navigation
Expand file tree
/
Copy pathThread_Keypad.c
More file actions
198 lines (172 loc) · 4.94 KB
/
Copy pathThread_Keypad.c
File metadata and controls
198 lines (172 loc) · 4.94 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "cmsis_os.h" // ARM::CMSIS:RTOS:Keil RTX
#include "stm32f4xx_hal.h"
#include "my_headers.h"
void Thread_Keypad (void const *argument); // thread function
//osThreadId tid_Thread_Keypad; // thread id
osThreadDef(Thread_Keypad, osPriorityNormal, 1, 0);
//Variables for LED display function
int update_counter = 0;
int first_decimal, second_decimal = 0;
int digit_flag = 0;
int display_value, first_digit, second_digit, third_digit = 0;
int scale = 1;
//float rotations[3];
float pitchORroll_value = 0;
float inter_value = 0.0;
/*----------------------------------------------------------------------------
* Create the thread within RTOS context
*---------------------------------------------------------------------------*/
int start_Thread_Keypad (void)
{
tid_Thread_Keypad = osThreadCreate(osThread(Thread_Keypad ), NULL); // Start LED_Thread
if (!tid_Thread_Keypad) return(-1);
return(0);
}
/*----------------------------------------------------------------------------
* Thread keypad
monitors the keypad for input and sets the 7-segment display
*---------------------------------------------------------------------------*/
void Thread_Keypad (void const *argument)
{
while(1)
{
//
// printf("x = %f", accel_array[0]);
// printf("y = %f", accel_array[1]);
// printf("z = %f", accel_array[2]);
//
read_keypad(); //returnd 1 if a key is pressed
osSignalWait(0x00, osWaitForever);
update_counter = update_counter+1;
digit_flag = (digit_flag+1)%3;
inter_value = temperature;
if (angle_mode_flag == 1)
{
pitchORroll_value = rotation_array[0];
}
if (angle_mode_flag == 2)
{
pitchORroll_value = rotation_array[1];
}
if(mode_flag == 0) // display temperature
{
if(update_counter>100)
{
//handling for the decimal placement and order of values
//if less than 10, 2 decimal places
if(inter_value>=0 && inter_value<10)
{
first_decimal = 1;
second_decimal = 0;
scale = 100;
}
//if more than 10, but less than 100, 1 decimal place
else if(inter_value>=10 && inter_value<100)
{
first_decimal = 0;
second_decimal = 1;
scale = 10;
}
//otherwise no decimal places
else if(inter_value >= 100)
{
first_decimal = 0;
second_decimal = 0;
scale = 1;
}
//extract the digits
//temperature = 6.34;
display_value = (int)(inter_value*scale);
first_digit = (display_value/100)%10;
second_digit = (display_value/10)%10;
third_digit = (display_value%10);
update_counter = 0;
}
if((update_counter > 50) && (alarm_flag == 1))
{
first_digit = 10; //10 is a case for settign all off
second_digit = 10;
third_digit = 10;
}
if(digit_flag == 0)
{
Set_Number(first_digit);
First_Digit_Set();
Set_Decimal(first_decimal);
}
else if(digit_flag == 1)
{
Set_Number(second_digit);
Second_Digit_Set();
Set_Decimal(second_decimal);
}
else if(digit_flag == 2)
{
Set_Number(third_digit);
Third_Digit_Set();
Set_Decimal(0);
}
}
if(mode_flag == 1) //display accelerometer data
{
//
if(update_counter > 100)
{
//handling for the decimal placement and order of values
//if less than 10, 2 decimal places
if(pitchORroll_value>=0 && pitchORroll_value<10)
{
first_decimal = 1;
second_decimal = 0;
scale = 100;
}
//if more than 10, but less than 100, 1 decimal place
else if(pitchORroll_value>=10 && pitchORroll_value<100)
{
first_decimal = 0;
second_decimal = 1;
scale = 10;
}
//otherwise no decimal places
else if(pitchORroll_value >= 100)
{
first_decimal = 0;
second_decimal = 0;
scale = 1;
}
//extract the digits
//temperature = 6.34;
display_value = (int)(pitchORroll_value*scale);//??
first_digit = (display_value/100)%10;
second_digit = (display_value/10)%10;
third_digit = (display_value%10);
update_counter = 0;
//
}
if((update_counter > 50) && (alarm_flag == 1))
{
first_digit = 10; //10 is a case for settign all off
second_digit = 10;
third_digit = 10;
}
if(digit_flag == 0)
{
Set_Number(first_digit);
First_Digit_Set();
Set_Decimal(first_decimal);
}
else if(digit_flag == 1)
{
Set_Number(second_digit);
Second_Digit_Set();
Set_Decimal(second_decimal);
}
else if(digit_flag == 2)
{
Set_Number(third_digit);
Third_Digit_Set();
Set_Decimal(0);
}
}
}
}