git.haldean.org d / 9e347c1
reading distances! haldean 4 years ago
1 changed file(s) with 36 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
2828
2929 #include "lidar-lite.h"
3030
31 static const int addr = 0x63;
31 static const int addr = 0x62;
3232
3333 int t_lo = 800;
3434 int t_hi = 2600;
3636 int p_hi = 2600;
3737 int period = 60000;
3838
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
3957 int main(int argc, char *argv[])
4058 {
41 int i2c;
42 uint8_t buf[4];
59 int res;
4360 int phi = p_lo;
4461 int theta = t_lo;
4562 bool inc = true;
5572 rc_enable_servo_power_rail();
5673 rc_set_state(RUNNING);
5774
58 if (!rc_i2c_init(1, addr))
75 if ((res = rc_i2c_init(1, addr)) != 0)
5976 {
60 fprintf(stderr, "ERROR: failed to initialize I2C\n");
77 fprintf(stderr, "ERROR: failed to initialize I2C: %d\n", res);
6178 return -1;
6279 }
6380
86103 }
87104 */
88105
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);
92120
93121 if (rc_get_state() == RUNNING)
94122 {