-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
69 lines (57 loc) · 1.29 KB
/
main.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
#include "Drivers/Motor.h"
#include "Drivers/TriggerSensor.h"
#include "Drivers/LightSensor.h"
#ifndef TESTING
#include "HAL/HAL_UART.h"
#include "HAL/HAL_GPIO.h"
#include "HAL/HAL_ADC.h"
#endif //TESTING
#include <iostream>
#include <stdint.h>
#define SPEED 100
void update();
void onTrigger(TriggerHandle *handle, uint8_t status);
#ifndef TESTING
MotorHandle motor_handle;
TriggerHandle trigger_handle;
LightHandle light_handle;
void onError(char* error)
{
std::cout << error << std::endl;
}
void init()
{
motor_handle = Motor(move, stop, onError);
trigger_handle = Trigger(onTrigger, onError);
light_handle = Light(getADCValue, onError);
}
int main()
{
init();
while(1)
{
update();
}
}
#else //TESTING
extern MotorHandle motor_handle;
extern TriggerHandle trigger_handle;
extern LightHandle light_handle;
#endif //TESTING
void onTrigger(TriggerHandle *handle, uint8_t status)
{
if(status)
Motor_stop(&motor_handle);
}
void update()
{
float lightValue = Light_getValue(&light_handle);
if(lightValue > 1000 && Trigger_getStatus(&trigger_handle) == 1)
{
Motor_move(&motor_handle, FORWARDS, SPEED);
}
if(lightValue < 100 && Trigger_getStatus(&trigger_handle) == 2)
{
Motor_move(&motor_handle, BACKWARDS, SPEED);
}
}