diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-06-29 18:48:42 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-06-29 18:48:42 +0200 |
commit | 67f2b3a2979cd01a66b36c1abfea1f2aef47315d (patch) | |
tree | 802121773997ed4b8d61f9fa30148f912467e457 | |
parent | 40993ba522ccd09d40910489b9f805a15077e524 (diff) |
hardcode bus_id = 0. It's highly unlikely to change.main
-rw-r--r-- | scd4x.lua | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -1,41 +1,39 @@ local scd4x = {} -local device_address = 0x62 - -scd4x.bus_id = 0 +local addr = 0x62 function scd4x.start() - i2c.start(scd4x.bus_id) - if not i2c.address(scd4x.bus_id, device_address, i2c.TRANSMITTER) then + i2c.start(0) + if not i2c.address(0, addr, i2c.TRANSMITTER) then return false end - i2c.write(scd4x.bus_id, {0x21, 0xb1}) - i2c.stop(scd4x.bus_id) + i2c.write(0, {0x21, 0xb1}) + i2c.stop(0) return true end function scd4x.stop() - i2c.start(scd4x.bus_id) - if not i2c.address(scd4x.bus_id, device_address, i2c.TRANSMITTER) then + i2c.start(0) + if not i2c.address(0, addr, i2c.TRANSMITTER) then return false end - i2c.write(scd4x.bus_id, {0x3f, 0x86}) - i2c.stop(scd4x.bus_id) + i2c.write(0, {0x3f, 0x86}) + i2c.stop(0) return true end function scd4x.read() - i2c.start(scd4x.bus_id) - if not i2c.address(scd4x.bus_id, device_address, i2c.TRANSMITTER) then + i2c.start(0) + if not i2c.address(0, addr, i2c.TRANSMITTER) then return nil end - i2c.write(scd4x.bus_id, {0xec, 0x05}) - i2c.stop(scd4x.bus_id) - i2c.start(scd4x.bus_id) - if not i2c.address(scd4x.bus_id, device_address, i2c.RECEIVER) then + i2c.write(0, {0xec, 0x05}) + i2c.stop(0) + i2c.start(0) + if not i2c.address(0, addr, i2c.RECEIVER) then return nil end - local data = i2c.read(scd4x.bus_id, 9) - i2c.stop(scd4x.bus_id) + local data = i2c.read(0, 9) + i2c.stop(0) if not scd4x.crc_valid(data, 9) then return nil end |