reading distances!
haldean
4 years ago
28 | 28 | |
29 | 29 | #include "lidar-lite.h" |
30 | 30 | |
31 | static const int addr = 0x63; | |
31 | static const int addr = 0x62; | |
32 | 32 | |
33 | 33 | int t_lo = 800; |
34 | 34 | int t_hi = 2600; |
36 | 36 | int p_hi = 2600; |
37 | 37 | int period = 60000; |
38 | 38 | |
39 | static bool | |
40 | wait_while_busy() | |
41 | { | |
42 | int res; | |
43 | uint8_t status = 0xFF; | |
44 | do | |
45 | { | |
46 | if ((res = rc_i2c_read_byte(1, STATUS, &status)) != 1) | |
47 | { | |
48 | printf("failed to read status from I2C: %d\n", res); | |
49 | return false; | |
50 | } | |
51 | } | |
52 | while (status & STATUS_BUSY); | |
53 | ||
54 | return true; | |
55 | } | |
56 | ||
39 | 57 | int main(int argc, char *argv[]) |
40 | 58 | { |
41 | int i2c; | |
42 | uint8_t buf[4]; | |
59 | int res; | |
43 | 60 | int phi = p_lo; |
44 | 61 | int theta = t_lo; |
45 | 62 | bool inc = true; |
55 | 72 | rc_enable_servo_power_rail(); |
56 | 73 | rc_set_state(RUNNING); |
57 | 74 | |
58 | if (!rc_i2c_init(1, addr)) | |
75 | if ((res = rc_i2c_init(1, addr)) != 0) | |
59 | 76 | { |
60 | fprintf(stderr, "ERROR: failed to initialize I2C\n"); | |
77 | fprintf(stderr, "ERROR: failed to initialize I2C: %d\n", res); | |
61 | 78 | return -1; |
62 | 79 | } |
63 | 80 | |
86 | 103 | } |
87 | 104 | */ |
88 | 105 | |
89 | uint8_t status = 0xFF; | |
90 | rc_i2c_read_byte(1, STATUS, &status); | |
91 | printf("status: %02x\n"); | |
106 | wait_while_busy(); | |
107 | if ((res = rc_i2c_write_byte(1, CMD, CMD_CAPTURE)) != 0) | |
108 | { | |
109 | printf("failed to write command to I2C: %d\n", res); | |
110 | return false; | |
111 | } | |
112 | wait_while_busy(); | |
113 | uint16_t reading; | |
114 | if ((res = rc_i2c_read_word(1, 0x8F, &reading)) != 0) | |
115 | { | |
116 | printf("failed to read measurement from I2C: %d\n", res); | |
117 | return false; | |
118 | } | |
119 | printf("measured: %u\n", reading); | |
92 | 120 | |
93 | 121 | if (rc_get_state() == RUNNING) |
94 | 122 | { |