denko 0.13.6 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{build_avr.yml → build_atmega_avr.yml} +18 -18
- data/.github/workflows/{build_megaavr.yml → build_atmega_megaavr.yml} +18 -18
- data/.github/workflows/{build_sam3x.yml → build_atsam3x.yml} +17 -17
- data/.github/workflows/{build_samd.yml → build_atsamd21.yml} +18 -18
- data/.github/workflows/build_esp32.yml +17 -18
- data/.github/workflows/build_esp32c3.yml +57 -0
- data/.github/workflows/build_esp32c6.yml +57 -0
- data/.github/workflows/build_esp32h2.yml +56 -0
- data/.github/workflows/build_esp32s2.yml +57 -0
- data/.github/workflows/build_esp32s3.yml +57 -0
- data/.github/workflows/build_esp8266.yml +15 -15
- data/.github/workflows/build_ra4m1.yml +16 -16
- data/.github/workflows/build_rp2040.yml +17 -16
- data/.github/workflows/ruby.yml +20 -20
- data/CHANGELOG.md +195 -11
- data/DEPS_CLI.md +9 -9
- data/DEPS_IDE.md +17 -18
- data/HARDWARE.md +50 -51
- data/README.md +61 -53
- data/Rakefile +1 -1
- data/benchmarks/analog_listen.rb +49 -0
- data/benchmarks/digital_write.rb +28 -0
- data/benchmarks/i2c_ssd1306_refresh.rb +13 -6
- data/build +1 -1
- data/denko.gemspec +5 -2
- data/examples/advanced/{m5_env.rb → m5_env3.rb} +12 -14
- data/examples/advanced/rotary_encoder_mac_volume.rb +18 -13
- data/examples/advanced/ssd1306_time_temp_rh.rb +8 -13
- data/examples/analog_io/ads1100.rb +48 -0
- data/examples/analog_io/ads1115.rb +2 -2
- data/examples/analog_io/ads1118.rb +3 -11
- data/examples/analog_io/input.rb +17 -16
- data/examples/analog_io/input_smoothing.rb +27 -0
- data/examples/analog_io/potentiometer.rb +31 -0
- data/examples/connection/binary_echo.rb +34 -0
- data/examples/connection/tcp.rb +12 -27
- data/examples/digital_io/button.rb +7 -3
- data/examples/digital_io/relay.rb +17 -0
- data/examples/digital_io/rotary_encoder.rb +21 -11
- data/examples/display/hd44780.rb +13 -5
- data/examples/display/ssd1306.rb +20 -17
- data/examples/display/ssd1306_s2_pico.rb +2 -2
- data/examples/i2c/search.rb +10 -26
- data/examples/led/apa102_bounce.rb +3 -4
- data/examples/led/apa102_fade.rb +44 -0
- data/examples/led/builtin_blink.rb +3 -1
- data/examples/led/builtin_fade.rb +19 -0
- data/examples/led/rgb_led.rb +31 -0
- data/examples/led/seven_segment_char_echo.rb +4 -2
- data/examples/led/ws2812_bounce.rb +5 -7
- data/examples/led/ws2812_builtin_blink.rb +3 -2
- data/examples/led/ws2812_fade.rb +43 -0
- data/examples/motor/l298.rb +10 -8
- data/examples/motor/servo.rb +4 -3
- data/examples/motor/stepper.rb +13 -13
- data/examples/one_wire/search.rb +32 -0
- data/examples/pulse_io/buzzer.rb +8 -3
- data/examples/pulse_io/ir_output.rb +51 -0
- data/examples/pulse_io/pwm_output.rb +30 -0
- data/examples/rtc/ds3231.rb +18 -35
- data/examples/sensor/aht10.rb +4 -6
- data/examples/sensor/aht20.rb +4 -6
- data/examples/sensor/bme280.rb +4 -4
- data/examples/sensor/bmp180.rb +9 -5
- data/examples/sensor/dht.rb +20 -15
- data/examples/sensor/ds18b20.rb +20 -21
- data/examples/sensor/generic_pir.rb +4 -2
- data/examples/sensor/hcsr04.rb +5 -2
- data/examples/sensor/htu21d.rb +9 -20
- data/examples/sensor/htu31d.rb +7 -9
- data/examples/sensor/neat_tph_readings.rb +15 -9
- data/examples/sensor/qmp6988.rb +5 -7
- data/examples/sensor/rcwl9620.rb +3 -3
- data/examples/sensor/sht3x.rb +4 -6
- data/examples/spi/bitbang_loopback.rb +46 -0
- data/examples/spi/input_register.rb +9 -19
- data/examples/spi/output_register.rb +9 -17
- data/examples/spi/ssd_through_registers.rb +28 -0
- data/examples/spi/two_registers.rb +18 -24
- data/examples/uart/bit_bang_demo.rb +25 -0
- data/examples/uart/board_passthrough.rb +19 -13
- data/examples/uart/hardware_loopback.rb +1 -1
- data/lib/denko/analog_io/ads1100.rb +127 -0
- data/lib/denko/analog_io/ads1115.rb +8 -25
- data/lib/denko/analog_io/ads1118.rb +10 -25
- data/lib/denko/analog_io/ads111x.rb +25 -11
- data/lib/denko/analog_io/input.rb +29 -55
- data/lib/denko/analog_io/input_helper.rb +42 -0
- data/lib/denko/analog_io/output.rb +5 -5
- data/lib/denko/analog_io/potentiometer.rb +6 -8
- data/lib/denko/analog_io.rb +2 -1
- data/lib/denko/behaviors/board_proxy.rb +13 -1
- data/lib/denko/behaviors/bus_controller.rb +1 -0
- data/lib/denko/behaviors/bus_controller_addressed.rb +1 -0
- data/lib/denko/behaviors/bus_peripheral.rb +3 -4
- data/lib/denko/behaviors/bus_peripheral_addressed.rb +8 -6
- data/lib/denko/behaviors/callbacks.rb +9 -7
- data/lib/denko/behaviors/component.rb +16 -14
- data/lib/denko/behaviors/input_pin.rb +14 -15
- data/lib/denko/behaviors/lifecycle.rb +51 -0
- data/lib/denko/behaviors/multi_pin.rb +22 -18
- data/lib/denko/behaviors/output_pin.rb +9 -4
- data/lib/denko/behaviors/single_pin.rb +1 -0
- data/lib/denko/behaviors/state.rb +15 -9
- data/lib/denko/behaviors/subcomponents.rb +72 -12
- data/lib/denko/behaviors.rb +2 -1
- data/lib/denko/board/core.rb +36 -18
- data/lib/denko/board/i2c.rb +14 -14
- data/lib/denko/board/i2c_bit_bang.rb +49 -0
- data/lib/denko/board/infrared.rb +6 -6
- data/lib/denko/board/led_array.rb +6 -5
- data/lib/denko/board/spi.rb +15 -10
- data/lib/denko/board/spi_bit_bang.rb +9 -7
- data/lib/denko/board.rb +35 -33
- data/lib/denko/connection/binary_echo.rb +17 -0
- data/lib/denko/connection/flow_control.rb +11 -15
- data/lib/denko/connection/handshake.rb +2 -0
- data/lib/denko/digital_io/button.rb +4 -0
- data/lib/denko/digital_io/c_bit_bang.rb +15 -0
- data/lib/denko/digital_io/input.rb +4 -5
- data/lib/denko/digital_io/output.rb +7 -6
- data/lib/denko/digital_io/relay.rb +2 -0
- data/lib/denko/digital_io/rotary_encoder.rb +78 -60
- data/lib/denko/digital_io.rb +1 -0
- data/lib/denko/display/hd44780.rb +136 -93
- data/lib/denko/display/sh1106.rb +42 -0
- data/lib/denko/display/ssd1306.rb +105 -45
- data/lib/denko/display.rb +1 -0
- data/lib/denko/eeprom/built_in.rb +19 -16
- data/lib/denko/i2c/bit_bang.rb +31 -0
- data/lib/denko/i2c/bus.rb +8 -36
- data/lib/denko/i2c/bus_common.rb +45 -0
- data/lib/denko/i2c/peripheral.rb +28 -19
- data/lib/denko/i2c.rb +2 -0
- data/lib/denko/led/apa102.rb +43 -29
- data/lib/denko/led/base.rb +8 -2
- data/lib/denko/led/rgb.rb +5 -7
- data/lib/denko/led/seven_segment.rb +24 -9
- data/lib/denko/led/ws2812.rb +10 -7
- data/lib/denko/message.rb +5 -0
- data/lib/denko/motor/l298.rb +11 -10
- data/lib/denko/motor/servo.rb +22 -10
- data/lib/denko/motor/stepper.rb +11 -14
- data/lib/denko/mutex_stub.rb +7 -0
- data/lib/denko/one_wire/bus.rb +9 -5
- data/lib/denko/one_wire/peripheral.rb +0 -3
- data/lib/denko/pulse_io/buzzer.rb +9 -3
- data/lib/denko/pulse_io/{ir_transmitter.rb → ir_output.rb} +9 -4
- data/lib/denko/pulse_io/pwm_output.rb +69 -15
- data/lib/denko/pulse_io.rb +3 -3
- data/lib/denko/rtc/ds3231.rb +11 -13
- data/lib/denko/sensor/aht.rb +22 -21
- data/lib/denko/sensor/bme280.rb +60 -63
- data/lib/denko/sensor/bmp180.rb +41 -38
- data/lib/denko/sensor/dht.rb +22 -5
- data/lib/denko/sensor/ds18b20.rb +40 -34
- data/lib/denko/sensor/hcsr04.rb +7 -5
- data/lib/denko/sensor/helper.rb +37 -0
- data/lib/denko/sensor/htu21d.rb +44 -55
- data/lib/denko/sensor/htu31d.rb +32 -33
- data/lib/denko/sensor/qmp6988.rb +25 -23
- data/lib/denko/sensor/rcwl9620.rb +2 -5
- data/lib/denko/sensor/sht3x.rb +23 -21
- data/lib/denko/sensor.rb +1 -2
- data/lib/denko/spi/base_register.rb +22 -22
- data/lib/denko/spi/bit_bang.rb +17 -51
- data/lib/denko/spi/bus.rb +15 -29
- data/lib/denko/spi/bus_common.rb +36 -0
- data/lib/denko/spi/input_register.rb +36 -30
- data/lib/denko/spi/output_register.rb +25 -40
- data/lib/denko/spi/peripheral.rb +93 -24
- data/lib/denko/spi.rb +6 -1
- data/lib/denko/uart/bit_bang.rb +5 -3
- data/lib/denko/uart/hardware.rb +9 -8
- data/lib/denko/version.rb +1 -1
- data/lib/denko.rb +10 -0
- data/lib/denko_cli/generator.rb +2 -2
- data/lib/denko_cli/packages.rb +8 -10
- data/lib/denko_cli/targets.rb +8 -8
- data/lib/denko_cli/targets.txt +4 -4
- data/lib/denko_cli/usage.txt +1 -1
- data/src/denko_ethernet.ino +0 -14
- data/src/denko_serial.ino +0 -14
- data/src/denko_wifi.ino +6 -15
- data/src/lib/Denko.cpp +39 -3
- data/src/lib/Denko.h +42 -26
- data/src/lib/DenkoCoreIO.cpp +57 -102
- data/src/lib/DenkoDefines.h +36 -31
- data/src/lib/DenkoI2C.cpp +54 -45
- data/src/lib/DenkoI2CBB.cpp +238 -0
- data/src/lib/DenkoIROut.cpp +12 -7
- data/src/lib/DenkoLEDArray.cpp +36 -13
- data/src/lib/DenkoSPI.cpp +6 -5
- data/src/lib/DenkoSPIBB.cpp +7 -6
- data/target.yml +37 -2
- data/test/analog_io/potentiometer_test.rb +10 -10
- data/test/behaviors/board_proxy_test.rb +1 -1
- data/test/behaviors/callbacks_test.rb +11 -3
- data/test/behaviors/component_test.rb +17 -9
- data/test/behaviors/input_pin_test.rb +14 -9
- data/test/behaviors/multi_pin_test.rb +14 -4
- data/test/behaviors/output_pin_test.rb +11 -8
- data/test/behaviors/poller_test.rb +1 -0
- data/test/behaviors/reader_test.rb +3 -2
- data/test/behaviors/subcomponents_test.rb +22 -2
- data/test/board/core_test.rb +15 -11
- data/test/board/i2c_test.rb +39 -33
- data/test/board/infrared_test.rb +1 -1
- data/test/board/message_test.rb +17 -11
- data/test/board/spi_test.rb +21 -21
- data/test/digital_io/button_test.rb +15 -0
- data/test/digital_io/relay_test.rb +18 -0
- data/test/digital_io/rotary_encoder_test.rb +80 -60
- data/test/eeprom/built_in_test.rb +9 -9
- data/test/i2c/bus_test.rb +30 -14
- data/test/i2c/peripheral_test.rb +36 -17
- data/test/led/base_test.rb +2 -1
- data/test/led/rgb_test.rb +6 -6
- data/test/led/seven_segment_test.rb +7 -7
- data/test/motor/servo_test.rb +1 -1
- data/test/motor/stepper_test.rb +2 -2
- data/test/one_wire/bus_test.rb +1 -0
- data/test/pulse_io/buzzer_test.rb +7 -4
- data/test/pulse_io/{ir_transmitter_test.rb → ir_output_test.rb} +10 -10
- data/test/pulse_io/pwm_output_test.rb +74 -18
- data/test/rtc/ds3231_test.rb +11 -13
- data/test/sensor/dht_test.rb +1 -1
- data/test/sensor/ds18b20_test.rb +4 -8
- data/test/spi/bus_test.rb +7 -7
- data/test/spi/input_register_test.rb +15 -15
- data/test/spi/output_register_test.rb +10 -28
- data/test/spi/peripheral_multi_pin_test.rb +53 -0
- data/test/spi/peripheral_single_pin_test.rb +48 -0
- data/test/test_helper.rb +36 -33
- data/tutorial/02-button/button.rb +5 -4
- data/tutorial/03-potentiometer/potentiometer.rb +9 -5
- data/tutorial/04-pwm_led/pwm_led.rb +14 -16
- data/tutorial/05-rgb_led/rgb_led.rb +6 -6
- data/tutorial/05-rgb_led/rgb_mapping.rb +11 -11
- data/vendor/board-maps/BoardMap.h +416 -56
- data/vendor/board-maps/lib/header_parser.rb +12 -2
- data/vendor/board-maps/yaml/ADAFRUIT_CAMERA_ESP32S3.yml +2 -2
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32C6.yml +15 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32_V2.yml +1 -1
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_ADALOGGER.yml +44 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32C3.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S2.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_N4R2.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_NOPSRAM.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32_PICO.yml +1 -0
- data/vendor/board-maps/yaml/AMKEN_BB.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_ES.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_REVELOP.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_REVELOP_PLUS.yml +48 -0
- data/vendor/board-maps/yaml/ASL_CAN_X2.yml +41 -0
- data/vendor/board-maps/yaml/BLING.yml +25 -0
- data/vendor/board-maps/yaml/BPI_LEAF_S3.yml +1 -0
- data/vendor/board-maps/yaml/BRIDGETEK_IDM2040_7A.yml +48 -0
- data/vendor/board-maps/yaml/Bee_Motion_Mini.yml +13 -1
- data/vendor/board-maps/yaml/Breadstick_Raspberry.yml +31 -0
- data/vendor/board-maps/yaml/DFROBOT_BEETLE_ESP32C6.yml +8 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32C6.yml +20 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_ESP32.yml +46 -0
- data/vendor/board-maps/yaml/DPTECHNICS_WALTER.yml +39 -0
- data/vendor/board-maps/yaml/ELECROW_CROWPANEL_7.yml +8 -0
- data/vendor/board-maps/yaml/ESP32C2_DEV.yml +12 -0
- data/vendor/board-maps/yaml/ESP32C3_DEVKIT_LIPO.yml +14 -0
- data/vendor/board-maps/yaml/ESP32C6_DEV.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_EVB.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_QWIIC_POCKET.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_THING_PLUS.yml +15 -0
- data/vendor/board-maps/yaml/ESP32H2_DEV.yml +13 -0
- data/vendor/board-maps/yaml/ESP32H2_DEVKIT_LIPO.yml +13 -0
- data/vendor/board-maps/yaml/ESP32S2_DEV.yml +1 -0
- data/vendor/board-maps/yaml/{RMP.yml → ESP32S2_DEVKIT_LIPO.yml} +2 -1
- data/vendor/board-maps/yaml/ESP32S2_DEVKIT_LIPO_USB.yml +44 -0
- data/vendor/board-maps/yaml/ESP32S3_DEVKIT_LIPO.yml +42 -0
- data/vendor/board-maps/yaml/ESP32S3_POWERFEATHER.yml +22 -0
- data/vendor/board-maps/yaml/ESP32_SBC_FABGL.yml +35 -0
- data/vendor/board-maps/yaml/EVN_ALPHA.yml +48 -0
- data/vendor/board-maps/yaml/FEATHERS3NEO.yml +32 -0
- data/vendor/board-maps/yaml/GEEKBLE_ESP32C3.yml +14 -0
- data/vendor/board-maps/yaml/HELTEC_CAPSULE_SENSOR_V3.yml +43 -0
- data/vendor/board-maps/yaml/HELTEC_WIFI_LORA_32_V3.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_BRIDGE.yml +8 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_MINI_SHELL.yml +13 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_PAPER.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_SHELL_V3.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_STICK_LITE_V3.yml +30 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_TRACKER.yml +41 -0
- data/vendor/board-maps/yaml/HT_DE01.yml +42 -0
- data/vendor/board-maps/yaml/IMBRIOS_LOGSENS_V1P1.yml +1 -1
- data/vendor/board-maps/yaml/LILYGO_T3S3_LR1121.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1262.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1276.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1278.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280PA.yml +8 -0
- data/vendor/board-maps/yaml/LILYGO_T_ETH_LITE.yml +21 -0
- data/vendor/board-maps/yaml/LOLIN_C3_PICO.yml +14 -0
- data/vendor/board-maps/yaml/LOLIN_S3.yml +1 -0
- data/vendor/board-maps/yaml/LOLIN_S3_MINI_PRO.yml +40 -0
- data/vendor/board-maps/yaml/Lion_Bit_Dev_Board.yml +0 -2
- data/vendor/board-maps/yaml/LoPy.yml +1 -0
- data/vendor/board-maps/yaml/LoPy4.yml +1 -0
- data/vendor/board-maps/yaml/M5STACK_CAPSULE.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_CARDPUTER.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_DIAL.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_FIRE.yml +0 -1
- data/vendor/board-maps/yaml/M5STACK_NANOC6.yml +17 -0
- data/vendor/board-maps/yaml/M5STACK_PAPER.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_POE_CAM.yml +5 -0
- data/vendor/board-maps/yaml/M5STACK_STAMP_C3.yml +13 -0
- data/vendor/board-maps/yaml/M5STACK_STAMP_S3.yml +4 -0
- data/vendor/board-maps/yaml/{M5Stick_C.yml → M5STACK_STICKC.yml} +0 -1
- data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS2.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_TOUGH.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_UNIT_CAM.yml +10 -0
- data/vendor/board-maps/yaml/M5STACK_UNIT_CAMS3.yml +4 -0
- data/vendor/board-maps/yaml/M5Stack_ATOM.yml +0 -1
- data/vendor/board-maps/yaml/MAKERGO_C3_SUPERMINI.yml +14 -0
- data/vendor/board-maps/yaml/MARBLE_PICO.yml +48 -0
- data/vendor/board-maps/yaml/METEHOCA_AKANA_R1.yml +46 -0
- data/vendor/board-maps/yaml/NAMINO_BIANCO.yml +13 -0
- data/vendor/board-maps/yaml/NEBULAS3.yml +0 -1
- data/vendor/board-maps/yaml/NEWSAN_ARCHI.yml +48 -0
- data/vendor/board-maps/yaml/NOLOGO_ESP32C3_SUPER_MINI.yml +14 -0
- data/vendor/board-maps/yaml/NOLOGO_ESP32S3_PICO.yml +12 -0
- data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_16MB.yml +48 -0
- data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_2MB.yml +48 -0
- data/vendor/board-maps/yaml/OPTA_ANALOG.yml +7 -0
- data/vendor/board-maps/yaml/OPTA_DIGITAL.yml +5 -0
- data/vendor/board-maps/yaml/PINTRONIX_PINMAX.yml +42 -0
- data/vendor/board-maps/yaml/PYCOM_GPY.yml +1 -0
- data/vendor/board-maps/yaml/REDPILL_ESP32S3.yml +0 -1
- data/vendor/board-maps/yaml/SENSEBOX_MCU_ESP32S2.yml +12 -0
- data/vendor/board-maps/yaml/SPARKFUN_MICROMOD_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/SPARKFUN_PRO_MICRO_ESP32C3.yml +24 -0
- data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER.yml +31 -0
- data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER_C6.yml +15 -0
- data/vendor/board-maps/yaml/TINYC6.yml +25 -0
- data/vendor/board-maps/yaml/UPESY_EDU_ESP32.yml +28 -0
- data/vendor/board-maps/yaml/UPESY_ESP32C3_BASIC.yml +13 -0
- data/vendor/board-maps/yaml/UPESY_ESP32C3_MINI.yml +12 -0
- data/vendor/board-maps/yaml/UPESY_ESP32S3_BASIC.yml +42 -0
- data/vendor/board-maps/yaml/VIRALINK_GATE32_01.yml +6 -0
- data/vendor/board-maps/yaml/VIRALINK_GATE32_11.yml +7 -0
- data/vendor/board-maps/yaml/WAVESHARE_ESP32S3_TOUCH_LCD_128.yml +8 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_MATRIX.yml +48 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ONE.yml +1 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_PIZERO.yml +47 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ZERO.yml +1 -0
- data/vendor/board-maps/yaml/WEACT_STUDIO_ESP32C3.yml +14 -0
- data/vendor/board-maps/yaml/WIPY3.yml +1 -0
- data/vendor/board-maps/yaml/WT32_SC01_PLUS.yml +7 -0
- data/vendor/board-maps/yaml/WiFiduinoV2.yml +1 -0
- data/vendor/board-maps/yaml/XIAO_ESP32C3.yml +0 -1
- data/vendor/board-maps/yaml/XIAO_ESP32C6.yml +22 -0
- data/vendor/board-maps/yaml/unphone9.yml +8 -0
- metadata +169 -30
- data/examples/led/apa102_breathe.rb +0 -45
- data/examples/pulse_io/ir_transmitter.rb +0 -55
- data/examples/spi/ssd_through_register.rb +0 -40
- data/examples/uart/bit_bang_read.rb +0 -16
- data/examples/uart/bit_bang_write.rb +0 -16
- data/lib/denko/analog_io/sensor.rb +0 -6
- data/lib/denko/sensor/virtual.rb +0 -42
- data/src/lib/DenkoIROutESP.cpp +0 -26
- data/vendor/board-maps/yaml/STAMP_S3.yml +0 -8
- /data/vendor/board-maps/yaml/{BRIDGETEK_IDM2040-7A.yml → BRIDGETEK_IDM2040_43A.yml} +0 -0
- /data/vendor/board-maps/yaml/{heltec_wifi_32_lora_V3.yml → HELTEC_WIRELESS_STICK_V3.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stack_Core_ESP32.yml → M5STACK_CORE.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stamp_Pico.yml → M5STACK_STAMP_PICO.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stack-Timer-CAM.yml → M5STACK_TIMER_CAM.yml} +0 -0
data/lib/denko/sensor/bme280.rb
CHANGED
@@ -3,7 +3,13 @@ module Denko
|
|
3
3
|
class BME280
|
4
4
|
include I2C::Peripheral
|
5
5
|
include Behaviors::Poller
|
6
|
-
|
6
|
+
include Behaviors::Lifecycle
|
7
|
+
include TemperatureHelper
|
8
|
+
include PressureHelper
|
9
|
+
include HumidityHelper
|
10
|
+
|
11
|
+
I2C_ADDRESS = 0x76
|
12
|
+
|
7
13
|
# Reading Mode Settings
|
8
14
|
SLEEP_MODE = 0b00
|
9
15
|
ONESHOT_MODE = 0b01 # 0b10 is also valid. Called "forced mode" in datasheet.
|
@@ -38,8 +44,8 @@ module Denko
|
|
38
44
|
8 => 0b100,
|
39
45
|
16 => 0b101, # 0b110 and 0b111 are also valid for 16x.
|
40
46
|
}
|
41
|
-
|
42
|
-
# IIR Filter Coefficients
|
47
|
+
|
48
|
+
# IIR Filter Coefficients
|
43
49
|
IIR_COEFFICIENTS = {
|
44
50
|
0 => 0b000,
|
45
51
|
2 => 0b001,
|
@@ -47,19 +53,8 @@ module Denko
|
|
47
53
|
8 => 0b011,
|
48
54
|
16 => 0b100, # 0b101, 0b110 and 0b111 are also valid for 16.
|
49
55
|
}
|
50
|
-
|
51
|
-
def before_initialize(options={})
|
52
|
-
@i2c_address = 0x76
|
53
|
-
super(options)
|
54
|
-
end
|
55
|
-
|
56
|
-
def after_initialize(options={})
|
57
|
-
super(options)
|
58
|
-
|
59
|
-
# Avoid repeated memory allocation for callback data and state.
|
60
|
-
@reading = { temperature: nil, humidity: nil, pressure: nil }
|
61
|
-
self.state = { temperature: nil, humidity: nil, pressure: nil }
|
62
56
|
|
57
|
+
after_initialize do
|
63
58
|
#
|
64
59
|
# Setup defaults for the config registers:
|
65
60
|
# Oneshot reading mode
|
@@ -72,7 +67,7 @@ module Denko
|
|
72
67
|
# Bits 2..4 control the pressure oversampling factor
|
73
68
|
# Bits 5..7 control the temperature oversampling factor.
|
74
69
|
f4: 0b00100110,
|
75
|
-
|
70
|
+
|
76
71
|
# Bits 0..1 should always be 0.
|
77
72
|
# Bits 2..4 control the IIR filter coefficient.
|
78
73
|
# Bits 5..7 control the standby time when in continuous reading mode.
|
@@ -81,10 +76,18 @@ module Denko
|
|
81
76
|
# Bits 0..2 control the humidity oversampling factor, on BME280 only.
|
82
77
|
# Bits 3+ are unused.
|
83
78
|
@registers.merge!(f2: 0b00000001) if humidity_available?
|
84
|
-
|
79
|
+
|
85
80
|
@calibration_data_loaded = false
|
86
81
|
end
|
87
82
|
|
83
|
+
def state
|
84
|
+
state_mutex.synchronize { @state = { temperature: nil, humidity: nil, pressure: nil } }
|
85
|
+
end
|
86
|
+
|
87
|
+
def reading
|
88
|
+
@reading ||= { temperature: nil, humidity: nil, pressure: nil }
|
89
|
+
end
|
90
|
+
|
88
91
|
#
|
89
92
|
# Configuration Methods
|
90
93
|
#
|
@@ -94,7 +97,7 @@ module Denko
|
|
94
97
|
end
|
95
98
|
|
96
99
|
attr_reader :measurement_time
|
97
|
-
|
100
|
+
|
98
101
|
def update_measurement_time
|
99
102
|
t_oversampling = 2 ** (((@registers[:f4] & 0b11100000) >> 5) - 1)
|
100
103
|
p_oversampling = 2 ** (((@registers[:f4] & 0b00011100) >> 2) - 1)
|
@@ -110,57 +113,57 @@ module Denko
|
|
110
113
|
# Milliseconds to seconds
|
111
114
|
@measurement_time = @measurement_time / 1000
|
112
115
|
end
|
113
|
-
|
116
|
+
|
114
117
|
def continuous_mode
|
115
118
|
@registers[:f4] = (@registers[:f4] & 0b11111100) | CONTINUOUS_MODE
|
116
|
-
write_settings
|
119
|
+
write_settings
|
117
120
|
end
|
118
|
-
|
121
|
+
|
119
122
|
def standby_time=(ms)
|
120
123
|
raise ArgumentError, "invalid standby time: #{ms}" unless self.class::STANDBY_TIMES.keys.include? ms
|
121
124
|
|
122
125
|
@registers[:f5] = (@registers[:f5] & 0b00011111) | (self.class::STANDBY_TIMES[ms] << 5)
|
123
126
|
write_settings
|
124
127
|
end
|
125
|
-
|
128
|
+
|
126
129
|
def temperature_samples=(factor)
|
127
130
|
raise ArgumentError, "invalid oversampling factor: #{factor}" unless OVERSAMPLE_FACTORS.keys.include? factor
|
128
131
|
raise ArgumentError, "temperature must be read. Invalid oversampling factor: #{factor}" if factor == 0
|
129
|
-
|
132
|
+
|
130
133
|
@registers[:f4] = (@registers[:f4] & 0b00011111) | (OVERSAMPLE_FACTORS[factor] << 5)
|
131
134
|
write_settings
|
132
135
|
end
|
133
|
-
|
136
|
+
|
134
137
|
def pressure_samples=(factor)
|
135
138
|
raise ArgumentError, "invalid oversampling factor: #{factor}" unless OVERSAMPLE_FACTORS.keys.include? factor
|
136
|
-
|
139
|
+
|
137
140
|
@registers[:f4] = (@registers[:f4] & 0b11100011) | (OVERSAMPLE_FACTORS[factor] << 2)
|
138
141
|
write_settings
|
139
142
|
end
|
140
|
-
|
143
|
+
|
141
144
|
def humidity_samples=(factor)
|
142
145
|
raise ArgumentError, "invalid oversampling factor: #{factor}" unless OVERSAMPLE_FACTORS.keys.include? factor
|
143
|
-
|
146
|
+
|
144
147
|
@registers[:f2] = (@registers[:f2] & 0b11111000) | OVERSAMPLE_FACTORS[factor]
|
145
148
|
write_settings
|
146
149
|
end
|
147
|
-
|
150
|
+
|
148
151
|
def iir_coefficient=(coeff)
|
149
152
|
raise ArgumentError, "invalid IIR coefficient: #{coeff}" unless IIR_COEFFICIENTS.keys.include? coeff
|
150
|
-
|
153
|
+
|
151
154
|
@registers[:f5] = (@registers[:f5] & 0b11100011) | (IIR_COEFFICIENTS[coeff] << 2)
|
152
155
|
write_settings
|
153
156
|
end
|
154
|
-
|
157
|
+
|
155
158
|
def write_settings
|
156
159
|
if humidity_available?
|
157
|
-
i2c_write [0xF2, @registers[:f2], 0xF4, @registers[:f4], 0xF5, @registers[:f5]]
|
160
|
+
i2c_write [0xF2, @registers[:f2], 0xF4, @registers[:f4], 0xF5, @registers[:f5]]
|
158
161
|
else
|
159
162
|
i2c_write [0xF4, @registers[:f4], 0xF5, @registers[:f5]]
|
160
163
|
end
|
161
164
|
update_measurement_time
|
162
165
|
end
|
163
|
-
|
166
|
+
|
164
167
|
def config_register_bits
|
165
168
|
str = ""
|
166
169
|
@registers.each_key do |key|
|
@@ -171,13 +174,13 @@ module Denko
|
|
171
174
|
|
172
175
|
#
|
173
176
|
# Reading Methods
|
174
|
-
#
|
177
|
+
#
|
175
178
|
def _read
|
176
179
|
get_calibration_data unless calibration_data_loaded
|
177
180
|
write_settings
|
178
|
-
i2c_read
|
181
|
+
i2c_read 8, register: 0xF7
|
179
182
|
end
|
180
|
-
|
183
|
+
|
181
184
|
def pre_callback_filter(data)
|
182
185
|
if data.length == 8
|
183
186
|
return decode_reading(data)
|
@@ -192,11 +195,11 @@ module Denko
|
|
192
195
|
return nil
|
193
196
|
end
|
194
197
|
end
|
195
|
-
|
198
|
+
|
196
199
|
def update_state(reading)
|
197
200
|
# Checking for Hash ignores calibration data and nil.
|
198
201
|
if reading.class == Hash
|
199
|
-
|
202
|
+
state_mutex.synchronize do
|
200
203
|
@state[:temperature] = reading[:temperature]
|
201
204
|
@state[:pressure] = reading[:pressure]
|
202
205
|
@state[:humidity] = reading[:humidity]
|
@@ -204,31 +207,25 @@ module Denko
|
|
204
207
|
end
|
205
208
|
end
|
206
209
|
|
207
|
-
def [](key)
|
208
|
-
@state_mutex.synchronize do
|
209
|
-
return @state[key]
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
210
|
#
|
214
211
|
# Decoding Methods
|
215
212
|
#
|
216
213
|
def decode_reading(bytes)
|
217
214
|
# Always read temperature since t_fine is needed to calibrate other values.
|
218
215
|
temperature, t_fine = decode_temperature(bytes)
|
219
|
-
|
220
|
-
|
216
|
+
reading[:temperature] = temperature
|
217
|
+
|
221
218
|
# Pressure and humidity are optional. Humidity is not available on the BMP280.
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
219
|
+
reading[:pressure] = decode_pressure(bytes, t_fine) if reading_pressure?
|
220
|
+
reading[:humidity] = decode_humidity(bytes, t_fine) if reading_humidity?
|
221
|
+
|
222
|
+
reading
|
226
223
|
end
|
227
|
-
|
224
|
+
|
228
225
|
def decode_temperature(bytes)
|
229
226
|
# Reformat raw temeprature bytes (20-bits in 24) to uint32.
|
230
227
|
adc_t = ((bytes[3] << 16) | (bytes[4] << 8) | (bytes[5])) >> 4
|
231
|
-
|
228
|
+
|
232
229
|
# Floating point temperature calculation from datasheet. Result in degrees Celsius.
|
233
230
|
var1 = (adc_t / 16384.0 - @calibration[:t1] / 1024.0) * @calibration[:t2]
|
234
231
|
var2 = (adc_t / 131072.0 - @calibration[:t1] / 8192.0) ** 2 * @calibration[:t3]
|
@@ -236,11 +233,11 @@ module Denko
|
|
236
233
|
temperature = (var1 + var2) / 5120.0
|
237
234
|
[temperature, t_fine]
|
238
235
|
end
|
239
|
-
|
236
|
+
|
240
237
|
def decode_pressure(bytes, t_fine)
|
241
238
|
# Reformat raw pressure bytes (20-bits in 24) to uint32.
|
242
239
|
adc_p = ((bytes[0] << 16) | (bytes[1] << 8) | (bytes[2])) >> 4
|
243
|
-
|
240
|
+
|
244
241
|
# Floating point pressure calculation from datasheet. Result in Pascals.
|
245
242
|
var1 = (t_fine / 2.0) - 64000.0
|
246
243
|
var2 = var1 * var1 * @calibration[:p6] / 32768.0
|
@@ -259,11 +256,11 @@ module Denko
|
|
259
256
|
end
|
260
257
|
pressure
|
261
258
|
end
|
262
|
-
|
259
|
+
|
263
260
|
def decode_humidity(bytes, t_fine)
|
264
261
|
# Raw data for humidity is big-endian uint16.
|
265
262
|
adc_h = (bytes[6] << 8) | bytes[7]
|
266
|
-
|
263
|
+
|
267
264
|
# Floating point humidity calculation from datasheet. Result in % RH.
|
268
265
|
humidity = t_fine - 76800.0
|
269
266
|
humidity = (adc_h - (@calibration[:h4] * 64.0 + @calibration[:h5] / 16384.0 * humidity)) *
|
@@ -278,30 +275,30 @@ module Denko
|
|
278
275
|
# Bits 2..4 of 0xF4 register must not be 0.
|
279
276
|
(@registers[:f4] >> 2 & 0b111) != OVERSAMPLE_FACTORS[0]
|
280
277
|
end
|
281
|
-
|
278
|
+
|
282
279
|
def reading_humidity?
|
283
280
|
return false unless humidity_available?
|
284
281
|
# Lowest 3 bits of 0xF2 register must not be 0.
|
285
282
|
(@registers[:f2] & 0b111) != OVERSAMPLE_FACTORS[0]
|
286
283
|
end
|
287
|
-
|
284
|
+
|
288
285
|
# No humidity on the BMP280.
|
289
286
|
def humidity_available?
|
290
287
|
!self.class.to_s.match(/bmp/i)
|
291
288
|
end
|
292
|
-
|
289
|
+
|
293
290
|
#
|
294
291
|
# Calibration Methods
|
295
292
|
#
|
296
293
|
attr_reader :calibration_data_loaded
|
297
|
-
|
298
|
-
def get_calibration_data
|
294
|
+
|
295
|
+
def get_calibration_data
|
299
296
|
# First group of calibration bytes, sent to #process_calibration_a.
|
300
|
-
read_using -> { i2c_read(
|
297
|
+
read_using -> { i2c_read(26, register: 0x88) }
|
301
298
|
|
302
299
|
# Second group of calibration bytes, only on BME280, sent to #process_calibration_b.
|
303
300
|
if humidity_available?
|
304
|
-
read_using -> { i2c_read 0xE1
|
301
|
+
read_using -> { i2c_read(7, register: 0xE1) }
|
305
302
|
end
|
306
303
|
|
307
304
|
if (@calibration[:cal_a] && @calibration[:cal_b]) || (@calibration[:cal_a] && !humidity_available?)
|
@@ -345,7 +342,7 @@ module Denko
|
|
345
342
|
end
|
346
343
|
end
|
347
344
|
end
|
348
|
-
|
345
|
+
|
349
346
|
#
|
350
347
|
# BMP280 is mostly compatible with BME280, except for a few changes.
|
351
348
|
#
|
data/lib/denko/sensor/bmp180.rb
CHANGED
@@ -3,7 +3,12 @@ module Denko
|
|
3
3
|
class BMP180
|
4
4
|
include I2C::Peripheral
|
5
5
|
include Behaviors::Poller
|
6
|
-
|
6
|
+
include Behaviors::Lifecycle
|
7
|
+
include TemperatureHelper
|
8
|
+
include PressureHelper
|
9
|
+
|
10
|
+
I2C_ADDRESS = 0x77
|
11
|
+
|
7
12
|
# Write this to register 0xE0 for soft reset
|
8
13
|
SOFT_RESET = 0xB6
|
9
14
|
|
@@ -20,18 +25,7 @@ module Denko
|
|
20
25
|
8 => 0b11,
|
21
26
|
}
|
22
27
|
|
23
|
-
|
24
|
-
@i2c_address = 0x77
|
25
|
-
super(options)
|
26
|
-
end
|
27
|
-
|
28
|
-
def after_initialize(options={})
|
29
|
-
super(options)
|
30
|
-
|
31
|
-
# Avoid repeated memory allocation for callback data and state.
|
32
|
-
@reading = { temperature: nil, pressure: nil }
|
33
|
-
self.state = { temperature: nil, pressure: nil }
|
34
|
-
|
28
|
+
after_initialize do
|
35
29
|
# Default to start conversion off, reading temperature, no pressure oversampling.
|
36
30
|
@register = 0b00001110
|
37
31
|
@calibration_data_loaded = false
|
@@ -43,6 +37,14 @@ module Denko
|
|
43
37
|
soft_reset
|
44
38
|
end
|
45
39
|
|
40
|
+
def state
|
41
|
+
state_mutex.synchronize { @state ||= { temperature: nil, pressure: nil } }
|
42
|
+
end
|
43
|
+
|
44
|
+
def reading
|
45
|
+
@reading ||= { temperature: nil, pressure: nil }
|
46
|
+
end
|
47
|
+
|
46
48
|
#
|
47
49
|
# Configuration Methods
|
48
50
|
#
|
@@ -51,7 +53,7 @@ module Denko
|
|
51
53
|
end
|
52
54
|
|
53
55
|
attr_reader :measurement_time
|
54
|
-
|
56
|
+
|
55
57
|
def update_measurement_time
|
56
58
|
# Get oversample bits from current register setting.
|
57
59
|
oversample_exponent = (@register & 0b11000000) >> 6
|
@@ -69,7 +71,7 @@ module Denko
|
|
69
71
|
raise ArgumentError, "invalid oversampling factor: #{factor}" unless OVERSAMPLE_FACTORS.keys.include? factor
|
70
72
|
@oss = OVERSAMPLE_FACTORS[factor]
|
71
73
|
end
|
72
|
-
|
74
|
+
|
73
75
|
def write_settings
|
74
76
|
update_measurement_time
|
75
77
|
i2c_write [0xF4, @register]
|
@@ -78,26 +80,33 @@ module Denko
|
|
78
80
|
#
|
79
81
|
# Reading Methods
|
80
82
|
#
|
81
|
-
def
|
83
|
+
def _read_temperature
|
82
84
|
@register = 0x2E
|
83
85
|
write_settings
|
86
|
+
sleep(@measurement_time)
|
87
|
+
i2c_read(2, register: 0xF6)
|
84
88
|
end
|
85
89
|
|
86
|
-
def
|
90
|
+
def _read_pressure
|
87
91
|
@register = 0x34 | (@oss << 6)
|
88
92
|
write_settings
|
93
|
+
sleep(@measurement_time)
|
94
|
+
i2c_read(3, register: 0xF6)
|
89
95
|
end
|
90
96
|
|
91
|
-
|
97
|
+
# Workaround for :read callbacks getting automatically removed on first reading.
|
98
|
+
def read(*args, **kwargs, &block)
|
92
99
|
get_calibration_data unless calibration_data_loaded
|
93
100
|
|
94
|
-
|
95
|
-
|
96
|
-
|
101
|
+
read_using(self.method(:_read_temperature), *args, **kwargs)
|
102
|
+
read_using(self.method(:_read_pressure), *args, **kwargs, &block)
|
103
|
+
end
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
105
|
+
def _read
|
106
|
+
get_calibration_data unless calibration_data_loaded
|
107
|
+
|
108
|
+
_read_temperature
|
109
|
+
_read_pressure
|
101
110
|
end
|
102
111
|
|
103
112
|
def pre_callback_filter(data)
|
@@ -123,27 +132,21 @@ module Denko
|
|
123
132
|
def update_state(reading)
|
124
133
|
# Checking for Hash ignores calibration data and nil.
|
125
134
|
if reading.class == Hash
|
126
|
-
|
135
|
+
state_mutex.synchronize do
|
127
136
|
@state[:temperature] = reading[:temperature]
|
128
137
|
@state[:pressure] = reading[:pressure]
|
129
138
|
end
|
130
139
|
end
|
131
140
|
end
|
132
141
|
|
133
|
-
def [](key)
|
134
|
-
@state_mutex.synchronize do
|
135
|
-
return @state[key]
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
142
|
#
|
140
143
|
# Decoding Methods
|
141
144
|
#
|
142
145
|
def decode_reading(bytes)
|
143
146
|
temperature, b5 = decode_temperature(bytes)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
+
reading[:temperature] = temperature
|
148
|
+
reading[:pressure] = decode_pressure(bytes, b5)
|
149
|
+
reading
|
147
150
|
end
|
148
151
|
|
149
152
|
def decode_temperature(bytes)
|
@@ -162,7 +165,7 @@ module Denko
|
|
162
165
|
# Return temperature and b5 for pressure calculation.
|
163
166
|
[temperature, b5]
|
164
167
|
end
|
165
|
-
|
168
|
+
|
166
169
|
def decode_pressure(bytes, b5)
|
167
170
|
# Pressure is bytes [2..3], MSB first.
|
168
171
|
up = ((bytes[2] << 16) | (bytes[3] << 8) | (bytes[4])) >> (8 - @oss)
|
@@ -194,10 +197,10 @@ module Denko
|
|
194
197
|
# Calibration Methods
|
195
198
|
#
|
196
199
|
attr_reader :calibration_data_loaded
|
197
|
-
|
198
|
-
def get_calibration_data
|
200
|
+
|
201
|
+
def get_calibration_data
|
199
202
|
# Calibration data is 22 bytes starting at address 0xAA.
|
200
|
-
read_using -> { i2c_read(
|
203
|
+
read_using -> { i2c_read(22, register: 0xAA) }
|
201
204
|
end
|
202
205
|
|
203
206
|
def process_calibration(bytes)
|
data/lib/denko/sensor/dht.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
module Denko
|
2
2
|
module Sensor
|
3
3
|
class DHT
|
4
|
-
include Behaviors::
|
4
|
+
include Behaviors::InputPin
|
5
5
|
include Behaviors::Poller
|
6
|
+
include Behaviors::Lifecycle
|
7
|
+
include TemperatureHelper
|
8
|
+
include HumidityHelper
|
9
|
+
|
10
|
+
def state
|
11
|
+
state_mutex.synchronize { @state ||= { temperature: nil, humidity: nil } }
|
12
|
+
end
|
13
|
+
|
14
|
+
def reading
|
15
|
+
@reading ||= { temperature: nil, humidity: nil }
|
16
|
+
end
|
6
17
|
|
7
18
|
def _read
|
8
19
|
board.pulse_read(pin, reset: board.low, reset_time: 20000, pulse_limit: 84, timeout: 100)
|
@@ -28,11 +39,17 @@ module Denko
|
|
28
39
|
end
|
29
40
|
return { error: 'CRC failure' } unless crc(bytes)
|
30
41
|
|
31
|
-
|
32
|
-
humidity
|
33
|
-
fahrenheit = (celsius * 1.8 + 32).round(1)
|
42
|
+
reading[:temperature] = ((bytes[2] << 8) | bytes[3]).to_f / 10
|
43
|
+
reading[:humidity] = ((bytes[0] << 8) | bytes[1]).to_f / 10
|
34
44
|
|
35
|
-
|
45
|
+
reading
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_state(reading)
|
49
|
+
state_mutex.synchronize do
|
50
|
+
@state[:temperature] = reading[:temperature]
|
51
|
+
@state[:humidity] = reading[:humidity]
|
52
|
+
end
|
36
53
|
end
|
37
54
|
|
38
55
|
def crc(bytes)
|
data/lib/denko/sensor/ds18b20.rb
CHANGED
@@ -1,36 +1,24 @@
|
|
1
1
|
module Denko
|
2
2
|
module Sensor
|
3
3
|
class DS18B20 < OneWire::Peripheral
|
4
|
+
include Behaviors::Lifecycle
|
5
|
+
include TemperatureHelper
|
4
6
|
FAMILY_CODE = 0x28
|
5
7
|
|
6
|
-
def
|
7
|
-
|
8
|
+
def state
|
9
|
+
state_mutex.synchronize { @state ||= { temperature: nil } }
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
11
|
-
@
|
12
|
+
def reading
|
13
|
+
@reading ||= { temperature: nil }
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
return bits if decode_resolution(scratch) == bits
|
20
|
-
|
21
|
-
eeprom = scratch[2..4]
|
22
|
-
eeprom[2] = 0b00011111 | ((bits - 9) << 5)
|
23
|
-
write_scratch(eeprom)
|
24
|
-
copy_scratch
|
25
|
-
@resolution = bits
|
26
|
-
end
|
27
|
-
|
28
|
-
def set_convert_time
|
29
|
-
@convert_time = 0.75 / (2 ** (12 - @resolution))
|
16
|
+
def _read
|
17
|
+
convert
|
18
|
+
read_scratch(9) { |data| self.update(data) }
|
30
19
|
end
|
31
20
|
|
32
21
|
def convert
|
33
|
-
@resolution ||= 12
|
34
22
|
set_convert_time
|
35
23
|
|
36
24
|
atomically do
|
@@ -41,16 +29,29 @@ module Denko
|
|
41
29
|
sleep @convert_time unless bus.parasite_power
|
42
30
|
end
|
43
31
|
|
44
|
-
def
|
45
|
-
|
46
|
-
read_scratch(9) { |data| self.update(data) }
|
32
|
+
def set_convert_time
|
33
|
+
@convert_time = 0.75 / (2 ** (12 - (@resolution || 12)))
|
47
34
|
end
|
48
35
|
|
49
36
|
def pre_callback_filter(bytes)
|
50
37
|
return { crc_error: true } unless OneWire::Helper.crc(bytes)
|
51
|
-
@resolution = decode_resolution(bytes)
|
52
38
|
|
53
|
-
|
39
|
+
@resolution ||= decode_resolution(bytes)
|
40
|
+
reading[:temperature] = decode_temperature(bytes)
|
41
|
+
|
42
|
+
reading
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_state(reading)
|
46
|
+
state_mutex.synchronize do
|
47
|
+
@state[:temperature] = reading[:temperature]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def decode_resolution(bytes)
|
52
|
+
config_byte = bytes[4]
|
53
|
+
offset = config_byte >> 5
|
54
|
+
offset + 9
|
54
55
|
end
|
55
56
|
|
56
57
|
#
|
@@ -58,16 +59,21 @@ module Denko
|
|
58
59
|
# It's a signed, 2's complement, little-endian decimal. LSB = 2 ^ -4.
|
59
60
|
#
|
60
61
|
def decode_temperature(bytes)
|
61
|
-
|
62
|
-
fahrenheit = (celsius * 1.8 + 32).round(4)
|
63
|
-
|
64
|
-
{celsius: celsius, fahrenheit: fahrenheit}
|
62
|
+
bytes[0..1].pack('C*').unpack('s<')[0] * (2.0 ** -4)
|
65
63
|
end
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
attr_reader :resolution
|
66
|
+
|
67
|
+
def resolution=(bits)
|
68
|
+
unless (9..12).include?(bits)
|
69
|
+
raise ArgumentError, 'Invalid DS18B20 resolution, expected 9 to 12'
|
70
|
+
end
|
71
|
+
|
72
|
+
eeprom = read_scratch(9)[2..4]
|
73
|
+
eeprom[2] = 0b00011111 | ((bits - 9) << 5)
|
74
|
+
write_scratch(eeprom)
|
75
|
+
copy_scratch
|
76
|
+
@resolution = bits
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
data/lib/denko/sensor/hcsr04.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module Denko
|
2
2
|
module Sensor
|
3
3
|
class HCSR04
|
4
|
-
|
5
|
-
SPEED_OF_SOUND = 343.0
|
6
|
-
|
4
|
+
include Behaviors::Lifecycle
|
7
5
|
include Behaviors::MultiPin
|
8
6
|
include Behaviors::Poller
|
9
7
|
|
8
|
+
# Speed of sound in meters per second.
|
9
|
+
SPEED_OF_SOUND = 343.0
|
10
|
+
|
10
11
|
def initialize_pins(options={})
|
11
12
|
proxy_pin :trigger, DigitalIO::Output
|
12
13
|
proxy_pin :echo, DigitalIO::Input
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
after_initialize do
|
17
|
+
# Avoid generating extraneous alerts when used with Denko::PiBoard.
|
18
|
+
echo.stop
|
17
19
|
|
18
20
|
# Receive values from echo pin.
|
19
21
|
echo.add_callback { |data| self.update(data) }
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Denko
|
2
|
+
module Sensor
|
3
|
+
module TemperatureHelper
|
4
|
+
def temperature
|
5
|
+
state[:temperature]
|
6
|
+
end
|
7
|
+
|
8
|
+
def temperature_f
|
9
|
+
(temperature * 1.8 + 32).round(4)
|
10
|
+
end
|
11
|
+
|
12
|
+
def temperature_k
|
13
|
+
temperature + 273.15
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module PressureHelper
|
18
|
+
def pressure
|
19
|
+
state[:pressure]
|
20
|
+
end
|
21
|
+
|
22
|
+
def pressure_atm
|
23
|
+
pressure / 101325.0
|
24
|
+
end
|
25
|
+
|
26
|
+
def pressure_bar
|
27
|
+
pressure / 100000.0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module HumidityHelper
|
32
|
+
def humidity
|
33
|
+
state[:humidity]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|