forked from leoz/rpic-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpic-lib.c
111 lines (83 loc) · 2 KB
/
rpic-lib.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
#include <stdio.h>
#include <unistd.h>
#include "rpic-lib.h"
#if defined(linux)
#if defined(__ia64__) || defined(__i386__) || defined(__x86_64__)
#define SERVO_0 1
#define SERVO_1 2
#define SERVO_2 3
#define SERVO_3 4
#define AVRSLAVE_ADDR 0
#define rj_setservo(a,b)
#define rj_open(a,b) 0
#define rj_getversion() "VOID"
#elif defined(__arm__)
#include "juice-dev.h"
#include "../raspy-juice-read-only/firmware/juice.h"
#else
#error Architecture is not supported
#endif
#else
#error OS is not supported
#endif
void rpi_car_forward()
{
printf("### RPi Car Forward ###\n");
rj_setservo(SERVO_0, RPI_CAR_VAL_FORWARD);
rj_setservo(SERVO_1, RPI_CAR_VAL_BACKWARD);
rj_setservo(SERVO_2, RPI_CAR_VAL_FORWARD);
rj_setservo(SERVO_3, RPI_CAR_VAL_BACKWARD);
}
void rpi_car_backward()
{
printf("### RPi Car Backward ###\n");
rj_setservo(SERVO_0, RPI_CAR_VAL_BACKWARD);
rj_setservo(SERVO_1, RPI_CAR_VAL_FORWARD);
rj_setservo(SERVO_2, RPI_CAR_VAL_BACKWARD);
rj_setservo(SERVO_3, RPI_CAR_VAL_FORWARD);
}
void rpi_car_stop()
{
printf("### RPi Car Stop ###\n");
rj_setservo(SERVO_0, RPI_CAR_VAL_STOP);
rj_setservo(SERVO_1, RPI_CAR_VAL_STOP);
rj_setservo(SERVO_2, RPI_CAR_VAL_STOP);
rj_setservo(SERVO_3, RPI_CAR_VAL_STOP);
}
void rpi_car_left()
{
printf("### RPi Car Left Turn ###\n");
rj_setservo(SERVO_0, RPI_CAR_VAL_FORWARD);
rj_setservo(SERVO_1, RPI_CAR_VAL_STOP);
rj_setservo(SERVO_2, RPI_CAR_VAL_STOP);
rj_setservo(SERVO_3, RPI_CAR_VAL_FORWARD);
}
void rpi_car_right()
{
printf("### RPi Car Right Turn ###\n");
}
void rpi_car_deccelerate()
{
printf("### RPi Car Deccelerate ###\n");
}
void rpi_car_accelerate()
{
printf("### RPi Car Accelerate ###\n");
}
#define RPI_CAR_DEV_NAME "/dev/i2c-0"
int rpi_car_dev_open()
{
int dev = -1;
dev = rj_open(RPI_CAR_DEV_NAME, AVRSLAVE_ADDR);
return dev;
}
void rpi_car_dev_close(int dev)
{
close (dev);
}
char* rpi_car_dev_version()
{
char* ver = NULL;
ver = rj_getversion();
return ver;
}