From 72dbf509844ae775ea3cdefff987ac0b545f096b Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 16 May 2022 23:04:04 +0800 Subject: [PATCH] gy-801-dump: read L3G4200D --- tools/gy-801-dump/main.ha | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/gy-801-dump/main.ha b/tools/gy-801-dump/main.ha index ac436ee..d1e2de1 100644 --- a/tools/gy-801-dump/main.ha +++ b/tools/gy-801-dump/main.ha @@ -3,6 +3,7 @@ use fs; use os; use rt; use sensors::ADXL345; +use sensors::L3G4200D; use strconv; export fn main() void = { @@ -26,9 +27,22 @@ export fn main() void = { }; defer ADXL345::destroy(ADXL345); + const L3G4200D = match (L3G4200D::new(bus)) { + case let L3G4200D: L3G4200D::L3G4200D => + yield L3G4200D; + case let err: fs::error => + fmt::fatalf("Cannot open i2c device: {}", fs::strerror(err)); + case let err: rt::errno => + fmt::fatalf("Cannot ioctl i2c device: {}", rt::strerror(err)); + }; + defer L3G4200D::destroy(L3G4200D); + ADXL345::init(ADXL345)!; + L3G4200D::init(L3G4200D)!; const acc_readings = ADXL345::read(ADXL345)!; + const gyro_readings = L3G4200D::read(L3G4200D)!; fmt::printfln("Accelerometer: {} {} {} g", acc_readings.0, acc_readings.1, acc_readings.2)!; + fmt::printfln("Gyroscope: {} {} {} dps", gyro_readings.0, gyro_readings.1, gyro_readings.2)!; }; -- 2.45.2