denko 0.13.6 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (376) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{build_avr.yml → build_atmega_avr.yml} +18 -18
  3. data/.github/workflows/{build_megaavr.yml → build_atmega_megaavr.yml} +18 -18
  4. data/.github/workflows/{build_sam3x.yml → build_atsam3x.yml} +17 -17
  5. data/.github/workflows/{build_samd.yml → build_atsamd21.yml} +18 -18
  6. data/.github/workflows/build_esp32.yml +17 -18
  7. data/.github/workflows/build_esp32c3.yml +57 -0
  8. data/.github/workflows/build_esp32c6.yml +57 -0
  9. data/.github/workflows/build_esp32h2.yml +56 -0
  10. data/.github/workflows/build_esp32s2.yml +57 -0
  11. data/.github/workflows/build_esp32s3.yml +57 -0
  12. data/.github/workflows/build_esp8266.yml +15 -15
  13. data/.github/workflows/build_ra4m1.yml +16 -16
  14. data/.github/workflows/build_rp2040.yml +17 -16
  15. data/.github/workflows/ruby.yml +20 -20
  16. data/CHANGELOG.md +195 -11
  17. data/DEPS_CLI.md +9 -9
  18. data/DEPS_IDE.md +17 -18
  19. data/HARDWARE.md +50 -51
  20. data/README.md +61 -53
  21. data/Rakefile +1 -1
  22. data/benchmarks/analog_listen.rb +49 -0
  23. data/benchmarks/digital_write.rb +28 -0
  24. data/benchmarks/i2c_ssd1306_refresh.rb +13 -6
  25. data/build +1 -1
  26. data/denko.gemspec +5 -2
  27. data/examples/advanced/{m5_env.rb → m5_env3.rb} +12 -14
  28. data/examples/advanced/rotary_encoder_mac_volume.rb +18 -13
  29. data/examples/advanced/ssd1306_time_temp_rh.rb +8 -13
  30. data/examples/analog_io/ads1100.rb +48 -0
  31. data/examples/analog_io/ads1115.rb +2 -2
  32. data/examples/analog_io/ads1118.rb +3 -11
  33. data/examples/analog_io/input.rb +17 -16
  34. data/examples/analog_io/input_smoothing.rb +27 -0
  35. data/examples/analog_io/potentiometer.rb +31 -0
  36. data/examples/connection/binary_echo.rb +34 -0
  37. data/examples/connection/tcp.rb +12 -27
  38. data/examples/digital_io/button.rb +7 -3
  39. data/examples/digital_io/relay.rb +17 -0
  40. data/examples/digital_io/rotary_encoder.rb +21 -11
  41. data/examples/display/hd44780.rb +13 -5
  42. data/examples/display/ssd1306.rb +20 -17
  43. data/examples/display/ssd1306_s2_pico.rb +2 -2
  44. data/examples/i2c/search.rb +10 -26
  45. data/examples/led/apa102_bounce.rb +3 -4
  46. data/examples/led/apa102_fade.rb +44 -0
  47. data/examples/led/builtin_blink.rb +3 -1
  48. data/examples/led/builtin_fade.rb +19 -0
  49. data/examples/led/rgb_led.rb +31 -0
  50. data/examples/led/seven_segment_char_echo.rb +4 -2
  51. data/examples/led/ws2812_bounce.rb +5 -7
  52. data/examples/led/ws2812_builtin_blink.rb +3 -2
  53. data/examples/led/ws2812_fade.rb +43 -0
  54. data/examples/motor/l298.rb +10 -8
  55. data/examples/motor/servo.rb +4 -3
  56. data/examples/motor/stepper.rb +13 -13
  57. data/examples/one_wire/search.rb +32 -0
  58. data/examples/pulse_io/buzzer.rb +8 -3
  59. data/examples/pulse_io/ir_output.rb +51 -0
  60. data/examples/pulse_io/pwm_output.rb +30 -0
  61. data/examples/rtc/ds3231.rb +18 -35
  62. data/examples/sensor/aht10.rb +4 -6
  63. data/examples/sensor/aht20.rb +4 -6
  64. data/examples/sensor/bme280.rb +4 -4
  65. data/examples/sensor/bmp180.rb +9 -5
  66. data/examples/sensor/dht.rb +20 -15
  67. data/examples/sensor/ds18b20.rb +20 -21
  68. data/examples/sensor/generic_pir.rb +4 -2
  69. data/examples/sensor/hcsr04.rb +5 -2
  70. data/examples/sensor/htu21d.rb +9 -20
  71. data/examples/sensor/htu31d.rb +7 -9
  72. data/examples/sensor/neat_tph_readings.rb +15 -9
  73. data/examples/sensor/qmp6988.rb +5 -7
  74. data/examples/sensor/rcwl9620.rb +3 -3
  75. data/examples/sensor/sht3x.rb +4 -6
  76. data/examples/spi/bitbang_loopback.rb +46 -0
  77. data/examples/spi/input_register.rb +9 -19
  78. data/examples/spi/output_register.rb +9 -17
  79. data/examples/spi/ssd_through_registers.rb +28 -0
  80. data/examples/spi/two_registers.rb +18 -24
  81. data/examples/uart/bit_bang_demo.rb +25 -0
  82. data/examples/uart/board_passthrough.rb +19 -13
  83. data/examples/uart/hardware_loopback.rb +1 -1
  84. data/lib/denko/analog_io/ads1100.rb +127 -0
  85. data/lib/denko/analog_io/ads1115.rb +8 -25
  86. data/lib/denko/analog_io/ads1118.rb +10 -25
  87. data/lib/denko/analog_io/ads111x.rb +25 -11
  88. data/lib/denko/analog_io/input.rb +29 -55
  89. data/lib/denko/analog_io/input_helper.rb +42 -0
  90. data/lib/denko/analog_io/output.rb +5 -5
  91. data/lib/denko/analog_io/potentiometer.rb +6 -8
  92. data/lib/denko/analog_io.rb +2 -1
  93. data/lib/denko/behaviors/board_proxy.rb +13 -1
  94. data/lib/denko/behaviors/bus_controller.rb +1 -0
  95. data/lib/denko/behaviors/bus_controller_addressed.rb +1 -0
  96. data/lib/denko/behaviors/bus_peripheral.rb +3 -4
  97. data/lib/denko/behaviors/bus_peripheral_addressed.rb +8 -6
  98. data/lib/denko/behaviors/callbacks.rb +9 -7
  99. data/lib/denko/behaviors/component.rb +16 -14
  100. data/lib/denko/behaviors/input_pin.rb +14 -15
  101. data/lib/denko/behaviors/lifecycle.rb +51 -0
  102. data/lib/denko/behaviors/multi_pin.rb +22 -18
  103. data/lib/denko/behaviors/output_pin.rb +9 -4
  104. data/lib/denko/behaviors/single_pin.rb +1 -0
  105. data/lib/denko/behaviors/state.rb +15 -9
  106. data/lib/denko/behaviors/subcomponents.rb +72 -12
  107. data/lib/denko/behaviors.rb +2 -1
  108. data/lib/denko/board/core.rb +36 -18
  109. data/lib/denko/board/i2c.rb +14 -14
  110. data/lib/denko/board/i2c_bit_bang.rb +49 -0
  111. data/lib/denko/board/infrared.rb +6 -6
  112. data/lib/denko/board/led_array.rb +6 -5
  113. data/lib/denko/board/spi.rb +15 -10
  114. data/lib/denko/board/spi_bit_bang.rb +9 -7
  115. data/lib/denko/board.rb +35 -33
  116. data/lib/denko/connection/binary_echo.rb +17 -0
  117. data/lib/denko/connection/flow_control.rb +11 -15
  118. data/lib/denko/connection/handshake.rb +2 -0
  119. data/lib/denko/digital_io/button.rb +4 -0
  120. data/lib/denko/digital_io/c_bit_bang.rb +15 -0
  121. data/lib/denko/digital_io/input.rb +4 -5
  122. data/lib/denko/digital_io/output.rb +7 -6
  123. data/lib/denko/digital_io/relay.rb +2 -0
  124. data/lib/denko/digital_io/rotary_encoder.rb +78 -60
  125. data/lib/denko/digital_io.rb +1 -0
  126. data/lib/denko/display/hd44780.rb +136 -93
  127. data/lib/denko/display/sh1106.rb +42 -0
  128. data/lib/denko/display/ssd1306.rb +105 -45
  129. data/lib/denko/display.rb +1 -0
  130. data/lib/denko/eeprom/built_in.rb +19 -16
  131. data/lib/denko/i2c/bit_bang.rb +31 -0
  132. data/lib/denko/i2c/bus.rb +8 -36
  133. data/lib/denko/i2c/bus_common.rb +45 -0
  134. data/lib/denko/i2c/peripheral.rb +28 -19
  135. data/lib/denko/i2c.rb +2 -0
  136. data/lib/denko/led/apa102.rb +43 -29
  137. data/lib/denko/led/base.rb +8 -2
  138. data/lib/denko/led/rgb.rb +5 -7
  139. data/lib/denko/led/seven_segment.rb +24 -9
  140. data/lib/denko/led/ws2812.rb +10 -7
  141. data/lib/denko/message.rb +5 -0
  142. data/lib/denko/motor/l298.rb +11 -10
  143. data/lib/denko/motor/servo.rb +22 -10
  144. data/lib/denko/motor/stepper.rb +11 -14
  145. data/lib/denko/mutex_stub.rb +7 -0
  146. data/lib/denko/one_wire/bus.rb +9 -5
  147. data/lib/denko/one_wire/peripheral.rb +0 -3
  148. data/lib/denko/pulse_io/buzzer.rb +9 -3
  149. data/lib/denko/pulse_io/{ir_transmitter.rb → ir_output.rb} +9 -4
  150. data/lib/denko/pulse_io/pwm_output.rb +69 -15
  151. data/lib/denko/pulse_io.rb +3 -3
  152. data/lib/denko/rtc/ds3231.rb +11 -13
  153. data/lib/denko/sensor/aht.rb +22 -21
  154. data/lib/denko/sensor/bme280.rb +60 -63
  155. data/lib/denko/sensor/bmp180.rb +41 -38
  156. data/lib/denko/sensor/dht.rb +22 -5
  157. data/lib/denko/sensor/ds18b20.rb +40 -34
  158. data/lib/denko/sensor/hcsr04.rb +7 -5
  159. data/lib/denko/sensor/helper.rb +37 -0
  160. data/lib/denko/sensor/htu21d.rb +44 -55
  161. data/lib/denko/sensor/htu31d.rb +32 -33
  162. data/lib/denko/sensor/qmp6988.rb +25 -23
  163. data/lib/denko/sensor/rcwl9620.rb +2 -5
  164. data/lib/denko/sensor/sht3x.rb +23 -21
  165. data/lib/denko/sensor.rb +1 -2
  166. data/lib/denko/spi/base_register.rb +22 -22
  167. data/lib/denko/spi/bit_bang.rb +17 -51
  168. data/lib/denko/spi/bus.rb +15 -29
  169. data/lib/denko/spi/bus_common.rb +36 -0
  170. data/lib/denko/spi/input_register.rb +36 -30
  171. data/lib/denko/spi/output_register.rb +25 -40
  172. data/lib/denko/spi/peripheral.rb +93 -24
  173. data/lib/denko/spi.rb +6 -1
  174. data/lib/denko/uart/bit_bang.rb +5 -3
  175. data/lib/denko/uart/hardware.rb +9 -8
  176. data/lib/denko/version.rb +1 -1
  177. data/lib/denko.rb +10 -0
  178. data/lib/denko_cli/generator.rb +2 -2
  179. data/lib/denko_cli/packages.rb +8 -10
  180. data/lib/denko_cli/targets.rb +8 -8
  181. data/lib/denko_cli/targets.txt +4 -4
  182. data/lib/denko_cli/usage.txt +1 -1
  183. data/src/denko_ethernet.ino +0 -14
  184. data/src/denko_serial.ino +0 -14
  185. data/src/denko_wifi.ino +6 -15
  186. data/src/lib/Denko.cpp +39 -3
  187. data/src/lib/Denko.h +42 -26
  188. data/src/lib/DenkoCoreIO.cpp +57 -102
  189. data/src/lib/DenkoDefines.h +36 -31
  190. data/src/lib/DenkoI2C.cpp +54 -45
  191. data/src/lib/DenkoI2CBB.cpp +238 -0
  192. data/src/lib/DenkoIROut.cpp +12 -7
  193. data/src/lib/DenkoLEDArray.cpp +36 -13
  194. data/src/lib/DenkoSPI.cpp +6 -5
  195. data/src/lib/DenkoSPIBB.cpp +7 -6
  196. data/target.yml +37 -2
  197. data/test/analog_io/potentiometer_test.rb +10 -10
  198. data/test/behaviors/board_proxy_test.rb +1 -1
  199. data/test/behaviors/callbacks_test.rb +11 -3
  200. data/test/behaviors/component_test.rb +17 -9
  201. data/test/behaviors/input_pin_test.rb +14 -9
  202. data/test/behaviors/multi_pin_test.rb +14 -4
  203. data/test/behaviors/output_pin_test.rb +11 -8
  204. data/test/behaviors/poller_test.rb +1 -0
  205. data/test/behaviors/reader_test.rb +3 -2
  206. data/test/behaviors/subcomponents_test.rb +22 -2
  207. data/test/board/core_test.rb +15 -11
  208. data/test/board/i2c_test.rb +39 -33
  209. data/test/board/infrared_test.rb +1 -1
  210. data/test/board/message_test.rb +17 -11
  211. data/test/board/spi_test.rb +21 -21
  212. data/test/digital_io/button_test.rb +15 -0
  213. data/test/digital_io/relay_test.rb +18 -0
  214. data/test/digital_io/rotary_encoder_test.rb +80 -60
  215. data/test/eeprom/built_in_test.rb +9 -9
  216. data/test/i2c/bus_test.rb +30 -14
  217. data/test/i2c/peripheral_test.rb +36 -17
  218. data/test/led/base_test.rb +2 -1
  219. data/test/led/rgb_test.rb +6 -6
  220. data/test/led/seven_segment_test.rb +7 -7
  221. data/test/motor/servo_test.rb +1 -1
  222. data/test/motor/stepper_test.rb +2 -2
  223. data/test/one_wire/bus_test.rb +1 -0
  224. data/test/pulse_io/buzzer_test.rb +7 -4
  225. data/test/pulse_io/{ir_transmitter_test.rb → ir_output_test.rb} +10 -10
  226. data/test/pulse_io/pwm_output_test.rb +74 -18
  227. data/test/rtc/ds3231_test.rb +11 -13
  228. data/test/sensor/dht_test.rb +1 -1
  229. data/test/sensor/ds18b20_test.rb +4 -8
  230. data/test/spi/bus_test.rb +7 -7
  231. data/test/spi/input_register_test.rb +15 -15
  232. data/test/spi/output_register_test.rb +10 -28
  233. data/test/spi/peripheral_multi_pin_test.rb +53 -0
  234. data/test/spi/peripheral_single_pin_test.rb +48 -0
  235. data/test/test_helper.rb +36 -33
  236. data/tutorial/02-button/button.rb +5 -4
  237. data/tutorial/03-potentiometer/potentiometer.rb +9 -5
  238. data/tutorial/04-pwm_led/pwm_led.rb +14 -16
  239. data/tutorial/05-rgb_led/rgb_led.rb +6 -6
  240. data/tutorial/05-rgb_led/rgb_mapping.rb +11 -11
  241. data/vendor/board-maps/BoardMap.h +416 -56
  242. data/vendor/board-maps/lib/header_parser.rb +12 -2
  243. data/vendor/board-maps/yaml/ADAFRUIT_CAMERA_ESP32S3.yml +2 -2
  244. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32C6.yml +15 -0
  245. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32_V2.yml +1 -1
  246. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_ADALOGGER.yml +44 -0
  247. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32C3.yml +1 -0
  248. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S2.yml +1 -0
  249. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_N4R2.yml +1 -0
  250. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_NOPSRAM.yml +1 -0
  251. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32_PICO.yml +1 -0
  252. data/vendor/board-maps/yaml/AMKEN_BB.yml +48 -0
  253. data/vendor/board-maps/yaml/AMKEN_ES.yml +48 -0
  254. data/vendor/board-maps/yaml/AMKEN_REVELOP.yml +48 -0
  255. data/vendor/board-maps/yaml/AMKEN_REVELOP_PLUS.yml +48 -0
  256. data/vendor/board-maps/yaml/ASL_CAN_X2.yml +41 -0
  257. data/vendor/board-maps/yaml/BLING.yml +25 -0
  258. data/vendor/board-maps/yaml/BPI_LEAF_S3.yml +1 -0
  259. data/vendor/board-maps/yaml/BRIDGETEK_IDM2040_7A.yml +48 -0
  260. data/vendor/board-maps/yaml/Bee_Motion_Mini.yml +13 -1
  261. data/vendor/board-maps/yaml/Breadstick_Raspberry.yml +31 -0
  262. data/vendor/board-maps/yaml/DFROBOT_BEETLE_ESP32C6.yml +8 -0
  263. data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32C6.yml +20 -0
  264. data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_ESP32.yml +46 -0
  265. data/vendor/board-maps/yaml/DPTECHNICS_WALTER.yml +39 -0
  266. data/vendor/board-maps/yaml/ELECROW_CROWPANEL_7.yml +8 -0
  267. data/vendor/board-maps/yaml/ESP32C2_DEV.yml +12 -0
  268. data/vendor/board-maps/yaml/ESP32C3_DEVKIT_LIPO.yml +14 -0
  269. data/vendor/board-maps/yaml/ESP32C6_DEV.yml +15 -0
  270. data/vendor/board-maps/yaml/ESP32C6_EVB.yml +15 -0
  271. data/vendor/board-maps/yaml/ESP32C6_QWIIC_POCKET.yml +15 -0
  272. data/vendor/board-maps/yaml/ESP32C6_THING_PLUS.yml +15 -0
  273. data/vendor/board-maps/yaml/ESP32H2_DEV.yml +13 -0
  274. data/vendor/board-maps/yaml/ESP32H2_DEVKIT_LIPO.yml +13 -0
  275. data/vendor/board-maps/yaml/ESP32S2_DEV.yml +1 -0
  276. data/vendor/board-maps/yaml/{RMP.yml → ESP32S2_DEVKIT_LIPO.yml} +2 -1
  277. data/vendor/board-maps/yaml/ESP32S2_DEVKIT_LIPO_USB.yml +44 -0
  278. data/vendor/board-maps/yaml/ESP32S3_DEVKIT_LIPO.yml +42 -0
  279. data/vendor/board-maps/yaml/ESP32S3_POWERFEATHER.yml +22 -0
  280. data/vendor/board-maps/yaml/ESP32_SBC_FABGL.yml +35 -0
  281. data/vendor/board-maps/yaml/EVN_ALPHA.yml +48 -0
  282. data/vendor/board-maps/yaml/FEATHERS3NEO.yml +32 -0
  283. data/vendor/board-maps/yaml/GEEKBLE_ESP32C3.yml +14 -0
  284. data/vendor/board-maps/yaml/HELTEC_CAPSULE_SENSOR_V3.yml +43 -0
  285. data/vendor/board-maps/yaml/HELTEC_WIFI_LORA_32_V3.yml +42 -0
  286. data/vendor/board-maps/yaml/HELTEC_WIRELESS_BRIDGE.yml +8 -0
  287. data/vendor/board-maps/yaml/HELTEC_WIRELESS_MINI_SHELL.yml +13 -0
  288. data/vendor/board-maps/yaml/HELTEC_WIRELESS_PAPER.yml +42 -0
  289. data/vendor/board-maps/yaml/HELTEC_WIRELESS_SHELL_V3.yml +42 -0
  290. data/vendor/board-maps/yaml/HELTEC_WIRELESS_STICK_LITE_V3.yml +30 -0
  291. data/vendor/board-maps/yaml/HELTEC_WIRELESS_TRACKER.yml +41 -0
  292. data/vendor/board-maps/yaml/HT_DE01.yml +42 -0
  293. data/vendor/board-maps/yaml/IMBRIOS_LOGSENS_V1P1.yml +1 -1
  294. data/vendor/board-maps/yaml/LILYGO_T3S3_LR1121.yml +9 -0
  295. data/vendor/board-maps/yaml/LILYGO_T3S3_SX1262.yml +9 -0
  296. data/vendor/board-maps/yaml/LILYGO_T3S3_SX1276.yml +9 -0
  297. data/vendor/board-maps/yaml/LILYGO_T3S3_SX1278.yml +9 -0
  298. data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280.yml +9 -0
  299. data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280PA.yml +8 -0
  300. data/vendor/board-maps/yaml/LILYGO_T_ETH_LITE.yml +21 -0
  301. data/vendor/board-maps/yaml/LOLIN_C3_PICO.yml +14 -0
  302. data/vendor/board-maps/yaml/LOLIN_S3.yml +1 -0
  303. data/vendor/board-maps/yaml/LOLIN_S3_MINI_PRO.yml +40 -0
  304. data/vendor/board-maps/yaml/Lion_Bit_Dev_Board.yml +0 -2
  305. data/vendor/board-maps/yaml/LoPy.yml +1 -0
  306. data/vendor/board-maps/yaml/LoPy4.yml +1 -0
  307. data/vendor/board-maps/yaml/M5STACK_CAPSULE.yml +8 -0
  308. data/vendor/board-maps/yaml/M5STACK_CARDPUTER.yml +8 -0
  309. data/vendor/board-maps/yaml/M5STACK_DIAL.yml +8 -0
  310. data/vendor/board-maps/yaml/M5STACK_FIRE.yml +0 -1
  311. data/vendor/board-maps/yaml/M5STACK_NANOC6.yml +17 -0
  312. data/vendor/board-maps/yaml/M5STACK_PAPER.yml +9 -0
  313. data/vendor/board-maps/yaml/M5STACK_POE_CAM.yml +5 -0
  314. data/vendor/board-maps/yaml/M5STACK_STAMP_C3.yml +13 -0
  315. data/vendor/board-maps/yaml/M5STACK_STAMP_S3.yml +4 -0
  316. data/vendor/board-maps/yaml/{M5Stick_C.yml → M5STACK_STICKC.yml} +0 -1
  317. data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS.yml +9 -0
  318. data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS2.yml +9 -0
  319. data/vendor/board-maps/yaml/M5STACK_TOUGH.yml +9 -0
  320. data/vendor/board-maps/yaml/M5STACK_UNIT_CAM.yml +10 -0
  321. data/vendor/board-maps/yaml/M5STACK_UNIT_CAMS3.yml +4 -0
  322. data/vendor/board-maps/yaml/M5Stack_ATOM.yml +0 -1
  323. data/vendor/board-maps/yaml/MAKERGO_C3_SUPERMINI.yml +14 -0
  324. data/vendor/board-maps/yaml/MARBLE_PICO.yml +48 -0
  325. data/vendor/board-maps/yaml/METEHOCA_AKANA_R1.yml +46 -0
  326. data/vendor/board-maps/yaml/NAMINO_BIANCO.yml +13 -0
  327. data/vendor/board-maps/yaml/NEBULAS3.yml +0 -1
  328. data/vendor/board-maps/yaml/NEWSAN_ARCHI.yml +48 -0
  329. data/vendor/board-maps/yaml/NOLOGO_ESP32C3_SUPER_MINI.yml +14 -0
  330. data/vendor/board-maps/yaml/NOLOGO_ESP32S3_PICO.yml +12 -0
  331. data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_16MB.yml +48 -0
  332. data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_2MB.yml +48 -0
  333. data/vendor/board-maps/yaml/OPTA_ANALOG.yml +7 -0
  334. data/vendor/board-maps/yaml/OPTA_DIGITAL.yml +5 -0
  335. data/vendor/board-maps/yaml/PINTRONIX_PINMAX.yml +42 -0
  336. data/vendor/board-maps/yaml/PYCOM_GPY.yml +1 -0
  337. data/vendor/board-maps/yaml/REDPILL_ESP32S3.yml +0 -1
  338. data/vendor/board-maps/yaml/SENSEBOX_MCU_ESP32S2.yml +12 -0
  339. data/vendor/board-maps/yaml/SPARKFUN_MICROMOD_RP2040.yml +48 -0
  340. data/vendor/board-maps/yaml/SPARKFUN_PRO_MICRO_ESP32C3.yml +24 -0
  341. data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER.yml +31 -0
  342. data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER_C6.yml +15 -0
  343. data/vendor/board-maps/yaml/TINYC6.yml +25 -0
  344. data/vendor/board-maps/yaml/UPESY_EDU_ESP32.yml +28 -0
  345. data/vendor/board-maps/yaml/UPESY_ESP32C3_BASIC.yml +13 -0
  346. data/vendor/board-maps/yaml/UPESY_ESP32C3_MINI.yml +12 -0
  347. data/vendor/board-maps/yaml/UPESY_ESP32S3_BASIC.yml +42 -0
  348. data/vendor/board-maps/yaml/VIRALINK_GATE32_01.yml +6 -0
  349. data/vendor/board-maps/yaml/VIRALINK_GATE32_11.yml +7 -0
  350. data/vendor/board-maps/yaml/WAVESHARE_ESP32S3_TOUCH_LCD_128.yml +8 -0
  351. data/vendor/board-maps/yaml/WAVESHARE_RP2040_MATRIX.yml +48 -0
  352. data/vendor/board-maps/yaml/WAVESHARE_RP2040_ONE.yml +1 -0
  353. data/vendor/board-maps/yaml/WAVESHARE_RP2040_PIZERO.yml +47 -0
  354. data/vendor/board-maps/yaml/WAVESHARE_RP2040_ZERO.yml +1 -0
  355. data/vendor/board-maps/yaml/WEACT_STUDIO_ESP32C3.yml +14 -0
  356. data/vendor/board-maps/yaml/WIPY3.yml +1 -0
  357. data/vendor/board-maps/yaml/WT32_SC01_PLUS.yml +7 -0
  358. data/vendor/board-maps/yaml/WiFiduinoV2.yml +1 -0
  359. data/vendor/board-maps/yaml/XIAO_ESP32C3.yml +0 -1
  360. data/vendor/board-maps/yaml/XIAO_ESP32C6.yml +22 -0
  361. data/vendor/board-maps/yaml/unphone9.yml +8 -0
  362. metadata +169 -30
  363. data/examples/led/apa102_breathe.rb +0 -45
  364. data/examples/pulse_io/ir_transmitter.rb +0 -55
  365. data/examples/spi/ssd_through_register.rb +0 -40
  366. data/examples/uart/bit_bang_read.rb +0 -16
  367. data/examples/uart/bit_bang_write.rb +0 -16
  368. data/lib/denko/analog_io/sensor.rb +0 -6
  369. data/lib/denko/sensor/virtual.rb +0 -42
  370. data/src/lib/DenkoIROutESP.cpp +0 -26
  371. data/vendor/board-maps/yaml/STAMP_S3.yml +0 -8
  372. /data/vendor/board-maps/yaml/{BRIDGETEK_IDM2040-7A.yml → BRIDGETEK_IDM2040_43A.yml} +0 -0
  373. /data/vendor/board-maps/yaml/{heltec_wifi_32_lora_V3.yml → HELTEC_WIRELESS_STICK_V3.yml} +0 -0
  374. /data/vendor/board-maps/yaml/{M5Stack_Core_ESP32.yml → M5STACK_CORE.yml} +0 -0
  375. /data/vendor/board-maps/yaml/{M5Stamp_Pico.yml → M5STACK_STAMP_PICO.yml} +0 -0
  376. /data/vendor/board-maps/yaml/{M5Stack-Timer-CAM.yml → M5STACK_TIMER_CAM.yml} +0 -0
data/lib/denko/led/rgb.rb CHANGED
@@ -21,17 +21,15 @@ module Denko
21
21
  off: [000, 000, 000]
22
22
  }
23
23
 
24
- def write(array)
25
- red.write array[0]
26
- green.write array[1]
27
- blue.write array[2]
24
+ def write(r, g, b)
25
+ red.write(r)
26
+ green.write(g)
27
+ blue.write(b)
28
28
  end
29
29
 
30
30
  def color=(color)
31
- return write(color) if color.class == Array
32
-
33
31
  color = color.to_sym
34
- write(COLORS[color]) if COLORS.include? color
32
+ write(*COLORS[color]) if COLORS.include? color
35
33
  end
36
34
  end
37
35
  end
@@ -2,7 +2,8 @@ module Denko
2
2
  module LED
3
3
  class SevenSegment
4
4
  include Behaviors::MultiPin
5
-
5
+ include Behaviors::Lifecycle
6
+
6
7
  ALL_OFF = [0,0,0,0,0,0,0]
7
8
  BLANK = " "
8
9
 
@@ -14,13 +15,15 @@ module Denko
14
15
  proxy_pin :cathode, DigitalIO::Output, optional: true
15
16
  proxy_pin :anode, DigitalIO::Output, optional: true
16
17
  end
17
-
18
- def after_initialize(options={})
19
- @segments = [a,b,c,d,e,f,g]
20
- clear; on
18
+
19
+ def segments
20
+ @segments ||= [a,b,c,d,e,f,g]
21
21
  end
22
22
 
23
- attr_reader :segments
23
+ after_initialize do
24
+ clear
25
+ on
26
+ end
24
27
 
25
28
  def clear
26
29
  write(BLANK)
@@ -46,7 +49,7 @@ module Denko
46
49
 
47
50
  def on?; @on; end
48
51
  def off?; !@on; end
49
-
52
+
50
53
  CHARACTERS = {
51
54
  '0' => [1,1,1,1,1,1,0],
52
55
  '1' => [0,1,1,0,0,0,0],
@@ -93,9 +96,21 @@ module Denko
93
96
 
94
97
  def write(char)
95
98
  bits = CHARACTERS[char] || ALL_OFF
99
+ bits = bits.map { |b| 1^b } if anode
100
+
96
101
  bits.each_with_index do |bit, index|
97
- bit = 1^bit if anode
98
- segments[index].write(bit) unless (segments[index].state == bit)
102
+ if board_is_register?
103
+ # On a register, use #bit_set except for the last bit. This changes state in memory.
104
+ # #digital_write on the last bit causes the register to write to its parallel out.
105
+ if (index == bits.length-1)
106
+ segments[index].digital_write(bit)
107
+ else
108
+ board.bit_set(segments[index].pin, bit)
109
+ end
110
+ else
111
+ # On a board, only set bits if changed.
112
+ segments[index].digital_write(bit) unless (segments[index].state == bit)
113
+ end
99
114
  end
100
115
  end
101
116
 
@@ -2,16 +2,19 @@ module Denko
2
2
  module LED
3
3
  class WS2812
4
4
  include Behaviors::SinglePin
5
+ include Behaviors::Lifecycle
5
6
 
6
- attr_reader :length, :bpp
7
+ def length
8
+ @length ||= params[:length] || 1
9
+ end
10
+
11
+ def bpp
12
+ @bpp ||= params[:bpp] || 3
13
+ end
7
14
 
8
- def after_initialize(options={})
9
- super(options)
10
- raise ArgumentError, "no length given for WS2812 array" unless options[:length]
11
- @length = options[:length]
15
+ attr_writer :length, :bpp
12
16
 
13
- # This is BYTES per pixel, not bits per pixel.
14
- @bpp = 3
17
+ after_initialize do
15
18
  off
16
19
  end
17
20
 
data/lib/denko/message.rb CHANGED
@@ -5,6 +5,11 @@ module Denko
5
5
  VAL_MAX = 9999
6
6
 
7
7
  def self.encode(command: nil, pin: nil, value: nil, aux_message: nil)
8
+ # Optimized single byte binary message for digital write on pins 0..63.
9
+ if (command == 1) && (pin < 64) && (value == 1 || value == 0)
10
+ return (pin | 0b10000000 | (value << 6)).chr
11
+ end
12
+
8
13
  # Start building message backwards with aux_message first.
9
14
  if aux_message
10
15
  # Convert it to String.
@@ -2,47 +2,48 @@ module Denko
2
2
  module Motor
3
3
  class L298
4
4
  include Behaviors::MultiPin
5
+ include Behaviors::Lifecycle
5
6
 
6
7
  attr_reader :speed
7
-
8
+
8
9
  def initialize_pins(options={})
9
10
  proxy_pin :direction1, DigitalIO::Output
10
11
  proxy_pin :direction2, DigitalIO::Output
11
- proxy_pin :enable, PulseIO::PWMOutput
12
+ proxy_pin :enable, PulseIO::PWMOutput
12
13
  end
13
-
14
- def after_initialize(options={})
14
+
15
+ after_initialize do
15
16
  off
16
17
  end
17
18
 
18
19
  def speed=(value)
19
- enable.write(value)
20
+ enable.duty = value
20
21
  @speed = value
21
22
  end
22
-
23
+
23
24
  def forward(value=nil)
24
25
  direction1.high
25
26
  direction2.low
26
27
  self.speed = value if value
27
28
  end
28
-
29
+
29
30
  def reverse(value=nil)
30
31
  direction1.low
31
32
  direction2.high
32
33
  self.speed = value if value
33
34
  end
34
-
35
+
35
36
  def idle
36
37
  direction1.low
37
38
  direction2.low
38
39
  self.speed = 0
39
40
  end
40
41
  alias :off :idle
41
-
42
+
42
43
  def brake
43
44
  direction1.high
44
45
  direction2.high
45
- self.speed = board.pwm_high
46
+ self.speed = 100
46
47
  end
47
48
  end
48
49
  end
@@ -3,16 +3,28 @@ module Denko
3
3
  class Servo
4
4
  include Behaviors::SinglePin
5
5
  include Behaviors::Threaded
6
+ include Behaviors::Lifecycle
6
7
 
7
- def after_initialize(options={})
8
- super(options)
9
- @min = options[:min] || 544
10
- @max = options[:max] || 2400
8
+ before_initialize do
9
+ params[:mode] = :output_pwm
10
+ end
11
+
12
+ after_initialize do
11
13
  attach
12
14
  end
13
15
 
16
+ def min
17
+ @min ||= params[:min] || 500
18
+ end
19
+
20
+ def max
21
+ @max ||= params[:max] || 2500
22
+ end
23
+
24
+ attr_writer :min, :max
25
+
14
26
  def attach
15
- board.servo_toggle(pin, :on, min: @min, max: @max)
27
+ board.servo_toggle(pin, :on, min: min, max: max)
16
28
  end
17
29
 
18
30
  def detach
@@ -22,19 +34,19 @@ module Denko
22
34
  def position=(value)
23
35
  value = value % 180 unless value == 180
24
36
 
25
- microseconds = ((value.to_f / 180) * (@max - @min)) + @min
37
+ microseconds = ((value.to_f / 180) * (max - min)) + min
26
38
  board.servo_write(pin, microseconds.round)
27
39
 
28
- @state = value
40
+ self.state = value
29
41
  end
30
42
 
31
43
  def speed=(value)
32
44
  raise 'invalid speed value' if value > 100 || value < -100
33
45
 
34
- microseconds = (((value.to_f + 100) / 200) * (@max - @min)) + @min
46
+ microseconds = (((value.to_f + 100) / 200) * (max - min)) + min
35
47
  board.servo_write(pin, microseconds.round)
36
48
 
37
- @state = value
49
+ self.state = value
38
50
  end
39
51
 
40
52
  alias :angle= :position=
@@ -43,7 +55,7 @@ module Denko
43
55
  alias :speed :state
44
56
 
45
57
  def write_microseconds(value)
46
- raise 'invalid microsecond value' if value > @max || value < @min
58
+ raise 'invalid microsecond value' if value > max || value < min
47
59
  board.servo_write(pin, value)
48
60
  end
49
61
  end
@@ -2,25 +2,24 @@ module Denko
2
2
  module Motor
3
3
  class Stepper
4
4
  include Behaviors::MultiPin
5
-
5
+ include Behaviors::Lifecycle
6
+
6
7
  def initialize_pins(options={})
7
8
  proxy_pin :step, DigitalIO::Output
8
9
  proxy_pin :direction, DigitalIO::Output
9
-
10
+
10
11
  proxy_pin :ms1, DigitalIO::Output, optional: true
11
12
  proxy_pin :ms2, DigitalIO::Output, optional: true
12
13
  proxy_pin :enable, DigitalIO::Output, optional: true
13
- proxy_pin :slp, DigitalIO::Output, optional: true
14
+ proxy_pin :slp, DigitalIO::Output, optional: true
14
15
  end
15
-
16
+
16
17
  attr_reader :microsteps
17
-
18
- def after_initialize(options={})
19
- wake; on;
20
-
21
- if (ms1 && ms2)
22
- self.microsteps = 8
23
- end
18
+
19
+ after_initialize do
20
+ wake
21
+ on
22
+ self.microsteps = 8 if (ms1 && ms2)
24
23
  end
25
24
 
26
25
  def sleep
@@ -53,7 +52,7 @@ module Denko
53
52
  @microsteps = steps
54
53
  end
55
54
 
56
- def step_cc
55
+ def step_ccw
57
56
  direction.high unless direction.high?
58
57
  step.high
59
58
  step.low
@@ -64,8 +63,6 @@ module Denko
64
63
  step.high
65
64
  step.low
66
65
  end
67
-
68
- alias :step_ccw :step_cc
69
66
  end
70
67
  end
71
68
  end
@@ -0,0 +1,7 @@
1
+ module Denko
2
+ class MutexStub
3
+ def synchronize(&block)
4
+ block.call
5
+ end
6
+ end
7
+ end
@@ -1,16 +1,15 @@
1
1
  module Denko
2
2
  module OneWire
3
- class Bus
4
- include Behaviors::SinglePin
3
+ class Bus < DigitalIO::CBitBang
5
4
  include Behaviors::BusControllerAddressed
6
5
  include Behaviors::Reader
6
+ include Behaviors::Lifecycle
7
7
  include BusEnumerator
8
8
  include Constants
9
9
 
10
10
  attr_reader :parasite_power
11
11
 
12
- def after_initialize(options = {})
13
- super(options)
12
+ after_initialize do
14
13
  read_power_supply
15
14
  end
16
15
 
@@ -53,7 +52,12 @@ module Denko
53
52
  end
54
53
 
55
54
  def pre_callback_filter(bytes)
56
- bytes = bytes.split(",").map(&:to_i)
55
+ # C extensions respond with Ruby array
56
+ # External Board responds with comma delimited String
57
+ unless bytes.class == Array
58
+ bytes = bytes.split(",").map(&:to_i)
59
+ end
60
+
57
61
  bytes.length > 1 ? bytes : bytes[0]
58
62
  end
59
63
  end
@@ -5,9 +5,6 @@ module Denko
5
5
  include Behaviors::Poller
6
6
  include Constants
7
7
 
8
- attr_reader :address
9
- alias :bus :board
10
-
11
8
  def read_scratch(num_bytes, &block)
12
9
  atomically do
13
10
  bus.add_callback(:read, &block) if block_given?
@@ -1,8 +1,14 @@
1
1
  module Denko
2
2
  module PulseIO
3
3
  class Buzzer < PWMOutput
4
- def after_initialize(options={})
5
- low
4
+ include Behaviors::Lifecycle
5
+
6
+ before_initialize do
7
+ params[:mode] ||= :output_pwm
8
+ end
9
+
10
+ after_initialize do
11
+ board.no_tone(pin)
6
12
  end
7
13
 
8
14
  # Duration is in mills
@@ -13,7 +19,7 @@ module Denko
13
19
  def no_tone
14
20
  board.no_tone(pin)
15
21
  end
16
-
22
+
17
23
  # Kill the thread if running, and send no_tone.
18
24
  def stop
19
25
  stop_thread
@@ -1,11 +1,16 @@
1
1
  module Denko
2
2
  module PulseIO
3
- class IRTransmitter
3
+ class IROutput
4
4
  include Behaviors::OutputPin
5
+ include Behaviors::Lifecycle
5
6
 
6
- def emit(pulses=[], frequency: 38)
7
- if pulses.length > 256 || pulses.length < 1
8
- raise ArgumentError, 'wrong number of IR pulses (expected 1 to 256)'
7
+ before_initialize do
8
+ params[:mode] = :output_pwm
9
+ end
10
+
11
+ def write(pulses=[], frequency: 38)
12
+ if pulses.length > 255 || pulses.length < 1
13
+ raise ArgumentError, 'wrong number of IR pulses (expected 1 to 255)'
9
14
  end
10
15
 
11
16
  pulses.each_with_index do |pulse, index|
@@ -1,34 +1,88 @@
1
1
  module Denko
2
2
  module PulseIO
3
3
  class PWMOutput < DigitalIO::Output
4
- interrupt_with :write
5
-
6
- def initialize_pins(options={})
7
- super(options)
8
- end
4
+ include Behaviors::Lifecycle
5
+
6
+ interrupt_with :write, :pwm_write, :digital_write, :duty=
9
7
 
10
- def write(value)
11
- if value == board.low
12
- digital_write(board.low)
13
- elsif value == board.pwm_high
14
- digital_write(board.high)
8
+ def duty=(percent)
9
+ if board_is_piboard
10
+ pwm_write(percent)
15
11
  else
16
- pwm_write(value)
12
+ pwm_write(((percent * pwm_high) / 100.0).round)
17
13
  end
18
14
  end
19
15
 
16
+ def digital_write(value)
17
+ pwm_disable if pwm_enabled
18
+ super(value)
19
+ end
20
+
20
21
  def pwm_write(value)
22
+ pwm_enable unless pwm_enabled
23
+ board.pwm_write(pin, value)
24
+ self.state = value
25
+ end
26
+ alias :write :pwm_write
27
+
28
+ def frequency
29
+ @frequency ||= params[:frequency] || 1000
30
+ end
31
+
32
+ def resolution
33
+ @resolution ||= params[:resolution] || board.analog_write_resolution
34
+ end
35
+
36
+ def pwm_high
37
+ @pwm_high ||= (2**resolution-1)
38
+ end
39
+
40
+ def frequency=(value)
41
+ @frequency = value
21
42
  pwm_enable
22
- board.pwm_write(pin, @state = value)
23
43
  end
24
44
 
25
- def pwm_enable
26
- self.mode = :output_pwm unless mode == :output_pwm
45
+ def resolution=(value)
46
+ @resolution = value
47
+ @pwm_high = (2**value-1)
48
+ pwm_enable
27
49
  end
28
-
50
+
51
+ def pwm_settings_hash
52
+ { frequency: frequency, resolution: resolution }
53
+ end
54
+
55
+ def pwm_enable(frequency: nil, resolution: nil)
56
+ @frequency = frequency if frequency
57
+ if resolution
58
+ @resolution = resolution
59
+ @pwm_high = (2**resolution-1)
60
+ end
61
+
62
+ board.set_pin_mode(pin, :output_pwm, pwm_settings_hash)
63
+ @mode = :output_pwm
64
+ end
65
+
29
66
  def pwm_disable
30
67
  self.mode = :output
31
68
  end
69
+
70
+ def pwm_enabled
71
+ mode == :output_pwm
72
+ end
73
+
74
+ def board_is_piboard
75
+ @board_is_piboard ||= piboard_check
76
+ end
77
+
78
+ def piboard_check
79
+ if Object.const_defined?("Denko::PiBoard")
80
+ if board.class.ancestors.include?(Denko::PiBoard)
81
+ return true
82
+ end
83
+ end
84
+ false
85
+ end
32
86
  end
33
87
  end
34
88
  end
@@ -1,7 +1,7 @@
1
1
  module Denko
2
2
  module PulseIO
3
- autoload :PWMOutput, "#{__dir__}/pulse_io/pwm_output"
4
- autoload :Buzzer, "#{__dir__}/pulse_io/buzzer"
5
- autoload :IRTransmitter, "#{__dir__}/pulse_io/ir_transmitter"
3
+ autoload :PWMOutput, "#{__dir__}/pulse_io/pwm_output"
4
+ autoload :Buzzer, "#{__dir__}/pulse_io/buzzer"
5
+ autoload :IROutput, "#{__dir__}/pulse_io/ir_output"
6
6
  end
7
7
  end
@@ -1,32 +1,30 @@
1
+ require 'bcd'
2
+
1
3
  module Denko
2
4
  module RTC
3
5
  class DS3231
4
6
  include I2C::Peripheral
5
- require 'bcd'
6
7
 
7
- def before_initialize(options={})
8
- @i2c_address = 0x68
9
- super(options)
10
- end
11
-
8
+ I2C_ADDRESS = 0x68
9
+
12
10
  # Write start register 0x00, then bytes to set time.
13
11
  def time=(time)
14
- i2c_write [0, time_to_bcd(time)]
12
+ i2c_write [0] + time_to_bcd(time)
15
13
  time
16
14
  end
17
-
15
+
18
16
  # Do a blocking read when #time is called.
19
17
  alias :time :read
20
-
18
+
21
19
  # Time data starts at register 0 and is 7 bytes long.
22
20
  def _read
23
- i2c_read(0, 7)
21
+ i2c_read(7, register: 0)
24
22
  end
25
-
23
+
26
24
  def pre_callback_filter(bytes)
27
25
  bcd_to_time(bytes)
28
26
  end
29
-
27
+
30
28
  # Convert Time object to 7 byte BCD sequence.
31
29
  def time_to_bcd(time)
32
30
  [ BCD.decode(time.sec),
@@ -37,7 +35,7 @@ module Denko
37
35
  BCD.decode(time.month),
38
36
  BCD.decode(time.year - 1970) ]
39
37
  end
40
-
38
+
41
39
  # Convert 7 byte BCD sequence to Time object.
42
40
  def bcd_to_time(bytes)
43
41
  t = bytes.map { |b| BCD.encode(b) }
@@ -3,9 +3,13 @@ module Denko
3
3
  class AHT10
4
4
  include I2C::Peripheral
5
5
  include Behaviors::Poller
6
+ include Behaviors::Lifecycle
7
+ include TemperatureHelper
8
+
9
+ I2C_ADDRESS = 0x38
6
10
 
7
11
  # Commands
8
- INIT_AND_CALIBRATE = [0xE1, 0x08, 0x00]
12
+ INIT_AND_CALIBRATE = [0xE1, 0x08, 0x00]
9
13
  READ_STATUS_REGISTER = [0x71]
10
14
  START_MEASUREMENT = [0xAC, 0x33, 0x00]
11
15
  SOFT_RESET = [0xBA]
@@ -28,24 +32,21 @@ module Denko
28
32
  # Number of bytes in each reading.
29
33
  DATA_LENGTH = 6
30
34
 
31
- def before_initialize(options={})
32
- @i2c_address = 0x38
33
- super(options)
34
- end
35
-
36
- def after_initialize(options={})
37
- super(options)
38
-
39
- # Avoid repeated memory allocation for callback data and state.
40
- @reading = { temperature: nil, humidity: nil }
41
- self.state = { temperature: nil, humidity: nil }
35
+ after_initialize do
42
36
  @status_register = 0x00
43
-
44
37
  sleep(self.class::POWER_ON_DELAY)
45
38
  reset
46
39
  calibrate
47
40
  end
48
41
 
42
+ def state
43
+ state_mutex.synchronize { @state = { temperature: nil, humidity: nil } }
44
+ end
45
+
46
+ def reading
47
+ @reading ||= { temperature: nil, humidity: nil }
48
+ end
49
+
49
50
  def reset
50
51
  i2c_write(SOFT_RESET)
51
52
  sleep(RESET_DELAY)
@@ -68,14 +69,14 @@ module Denko
68
69
  end
69
70
 
70
71
  def read_status_register
71
- read_using -> { i2c_read(READ_STATUS_REGISTER, 1) }
72
+ read_using -> { i2c_read(1, register: READ_STATUS_REGISTER) }
72
73
  sleep(COMMAND_DELAY)
73
74
  end
74
75
 
75
76
  def _read
76
77
  i2c_write(START_MEASUREMENT)
77
78
  sleep(MEASURE_DELAY)
78
- i2c_read(nil, self.class::DATA_LENGTH)
79
+ i2c_read(self.class::DATA_LENGTH)
79
80
  end
80
81
 
81
82
  def pre_callback_filter(bytes)
@@ -91,17 +92,17 @@ module Denko
91
92
 
92
93
  # Humidity uses the upper 4 bits of the shared byte as its lowest 4 bits.
93
94
  h_raw = ((bytes[1] << 16) | (bytes[2] << 8) | (bytes[3])) >> 4
94
- @reading[:humidity] = (h_raw.to_f / 2**20) * 100
95
+ reading[:humidity] = (h_raw.to_f / 2**20) * 100
95
96
 
96
97
  # Temperature uses the lower 4 bits of the shared byte as its highest 4 bits.
97
98
  t_raw = ((bytes[3] & 0x0F) << 16) | (bytes[4] << 8) | bytes[5]
98
- @reading[:temperature] = (t_raw.to_f / 2**20) * 200 - 50
99
+ reading[:temperature] = (t_raw.to_f / 2**20) * 200 - 50
99
100
 
100
- @reading
101
+ reading
101
102
  end
102
103
 
103
104
  def update_state(reading)
104
- @state_mutex.synchronize do
105
+ state_mutex.synchronize do
105
106
  @state[:temperature] = reading[:temperature]
106
107
  @state[:humidity] = reading[:humidity]
107
108
  end
@@ -119,7 +120,7 @@ module Denko
119
120
  # Changed constants compared to AHT10. Always access with self.class::CONSTANT_NAME
120
121
  # in shared methods coming from the superclass.
121
122
  #
122
- INIT_AND_CALIBRATE = [0xBE, 0x08, 0x00]
123
+ INIT_AND_CALIBRATE = [0xBE, 0x08, 0x00]
123
124
  POWER_ON_DELAY = 0.100
124
125
  DATA_LENGTH = 7
125
126
 
@@ -156,7 +157,7 @@ module Denko
156
157
  end
157
158
  end
158
159
  end
159
-
160
+
160
161
  # Limit CRC size to 8 bits.
161
162
  crc = crc & 0xFF
162
163
  end