-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.c
129 lines (98 loc) · 2.58 KB
/
app.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
126
127
128
/**
******************************************************************************
* @file : app.c
* @brief : Application layer file
******************************************************************************
*/
#include "app.h"
#include "button.h"
#include "led.h"
#include "packet_handler.h"
//-----------------------------------------------------
// Global variables
//-----------------------------------------------------
SERIAL_PACKET_t g_serial_packet;
uint8_t g_result = 1;
bool x;
//-----------------------------------------------------
// Function Definitions
//-----------------------------------------------------
/**
* @attention : Definetions of private functions of the app.c module
*/
void on_button_pressed(BUTTON_ID_t button_id, BUTTON_ACTION_t action);
uint8_t process_packet(SERIAL_PACKET_t* pack, uint8_t* result);
uint8_t calculate_position(uint8_t x, uint8_t y);
//-----------------------------------------------------
// Public functions
//-----------------------------------------------------
/**
* @brief: This function initiate button and led drivers and handlle button callback events
*/
void app_init(void)
{
btn_init();
btn_subscribe(on_button_pressed);
led_init();
}
void app_run(void)
{
/*Handle packets */
//x = is_packet_complete();
//if(x == true)
//{
// x = false;
// get_packet(&g_serial_packet);
// process_packet(&g_serial_packet, &g_result);
packet_transmit(&g_result);
//}
}
//-----------------------------------------------------
// Private functions
//-----------------------------------------------------
/**
* @brief: Private function in the button driver which handlle the button events
*/
void on_button_pressed(BUTTON_ID_t button_id, BUTTON_ACTION_t action)
{
led_set_pattern(LED_PTRN_BLINK,3);
}
/**
* @brief: Private function process the packets
*/
uint8_t process_packet(SERIAL_PACKET_t* pack, uint8_t* result)
{
switch((*pack).sig )
{
case SIGA:
/**Do the led stuf*/
if((*pack).data[0] == 0x01){
led_set_pattern(LED_PTRN_ON,0);
}
else{
led_set_pattern(LED_PTRN_OFF,0);
}
break;
case SIGB:
/**Do the circle stuff*/
*result = calculate_position((*pack).data[0] , (*pack).data[1] );
break;
default:
break;
}
return *result;
}
uint8_t calculate_position(uint8_t x, uint8_t y)
{
uint8_t res;
int dist = sqrt(pow(abs(CX - x),2)+ pow(abs(CY - y),2));
if(dist < RADIUS)
{
res = 1;
}
else
{
res = 0;
}
return res;
}