denko 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build_avr.yml +61 -0
- data/.github/workflows/build_esp32.yml +58 -0
- data/.github/workflows/build_esp8266.yml +57 -0
- data/.github/workflows/build_megaavr.yml +61 -0
- data/.github/workflows/build_rp2040.yml +61 -0
- data/.github/workflows/build_sam3x.yml +59 -0
- data/.github/workflows/build_samd.yml +61 -0
- data/.github/workflows/ruby.yml +47 -0
- data/.gitignore +24 -0
- data/.gitmodules +3 -0
- data/.vscode/settings.json +5 -0
- data/.vscode/tasks.json +20 -0
- data/CHANGELOG.md +466 -0
- data/DEPS_CLI.md +80 -0
- data/DEPS_IDE.md +120 -0
- data/Gemfile +4 -0
- data/HARDWARE.md +195 -0
- data/LICENSE +22 -0
- data/README.md +152 -0
- data/Rakefile +11 -0
- data/bin/denko +22 -0
- data/build +27 -0
- data/denko.gemspec +47 -0
- data/examples/advanced/rotary_encoder_mac_volume.rb +48 -0
- data/examples/advanced/ssd1306_time_temp_rh.rb +48 -0
- data/examples/analog_io/ads1118.rb +74 -0
- data/examples/analog_io/dac_loopback.rb +32 -0
- data/examples/analog_io/input.rb +52 -0
- data/examples/connection/tcp.rb +34 -0
- data/examples/digital_io/rotary_encoder.rb +26 -0
- data/examples/display/hd44780.png +0 -0
- data/examples/display/hd44780.rb +39 -0
- data/examples/display/ssd1306.rb +40 -0
- data/examples/display/ssd1306_s2_pico.rb +29 -0
- data/examples/eeprom/built_in.rb +32 -0
- data/examples/i2c/search.rb +53 -0
- data/examples/led/apa102_bounce.rb +33 -0
- data/examples/led/apa102_breathe.rb +45 -0
- data/examples/led/builtin_blink.rb +12 -0
- data/examples/led/seven_segment_char_echo.rb +15 -0
- data/examples/led/ws2812_bounce.rb +32 -0
- data/examples/led/ws2812_builtin_blink.rb +21 -0
- data/examples/motor/l298.rb +43 -0
- data/examples/motor/servo.rb +16 -0
- data/examples/motor/stepper.png +0 -0
- data/examples/motor/stepper.rb +43 -0
- data/examples/pulse_io/buzzer.rb +30 -0
- data/examples/pulse_io/ir_transmitter.rb +55 -0
- data/examples/rtc/ds3231.rb +48 -0
- data/examples/sensor/aht10.rb +15 -0
- data/examples/sensor/aht20.rb +15 -0
- data/examples/sensor/bme280.rb +75 -0
- data/examples/sensor/dht.rb +24 -0
- data/examples/sensor/ds18b20.rb +58 -0
- data/examples/sensor/htu21d.rb +54 -0
- data/examples/sensor/htu31d.rb +31 -0
- data/examples/spi/input_register.rb +50 -0
- data/examples/spi/output_register.rb +49 -0
- data/examples/spi/ssd_through_register.rb +40 -0
- data/examples/spi/two_registers.rb +46 -0
- data/examples/uart/bit_bang_read.rb +16 -0
- data/examples/uart/bit_bang_write.rb +16 -0
- data/examples/uart/board_passthrough.rb +34 -0
- data/examples/uart/hardware_loopback.rb +16 -0
- data/lib/denko/analog_io/ads1118.rb +182 -0
- data/lib/denko/analog_io/input.rb +79 -0
- data/lib/denko/analog_io/output.rb +20 -0
- data/lib/denko/analog_io/potentiometer.rb +15 -0
- data/lib/denko/analog_io/sensor.rb +6 -0
- data/lib/denko/analog_io.rb +9 -0
- data/lib/denko/behaviors/board_proxy.rb +23 -0
- data/lib/denko/behaviors/bus_controller.rb +11 -0
- data/lib/denko/behaviors/bus_controller_addressed.rb +15 -0
- data/lib/denko/behaviors/bus_peripheral.rb +21 -0
- data/lib/denko/behaviors/bus_peripheral_addressed.rb +15 -0
- data/lib/denko/behaviors/callbacks.rb +67 -0
- data/lib/denko/behaviors/component.rb +48 -0
- data/lib/denko/behaviors/input_pin.rb +24 -0
- data/lib/denko/behaviors/listener.rb +22 -0
- data/lib/denko/behaviors/multi_pin.rb +72 -0
- data/lib/denko/behaviors/output_pin.rb +13 -0
- data/lib/denko/behaviors/poller.rb +31 -0
- data/lib/denko/behaviors/reader.rb +49 -0
- data/lib/denko/behaviors/single_pin.rb +26 -0
- data/lib/denko/behaviors/state.rb +24 -0
- data/lib/denko/behaviors/subcomponents.rb +35 -0
- data/lib/denko/behaviors/threaded.rb +54 -0
- data/lib/denko/behaviors.rb +26 -0
- data/lib/denko/board/core.rb +151 -0
- data/lib/denko/board/eeprom.rb +20 -0
- data/lib/denko/board/i2c.rb +68 -0
- data/lib/denko/board/infrared.rb +18 -0
- data/lib/denko/board/led_array.rb +18 -0
- data/lib/denko/board/map.rb +46 -0
- data/lib/denko/board/message_pack.rb +7 -0
- data/lib/denko/board/one_wire.rb +34 -0
- data/lib/denko/board/pulse.rb +26 -0
- data/lib/denko/board/servo.rb +22 -0
- data/lib/denko/board/spi.rb +65 -0
- data/lib/denko/board/spi_bit_bang.rb +41 -0
- data/lib/denko/board/tone.rb +23 -0
- data/lib/denko/board/uart.rb +42 -0
- data/lib/denko/board/uart_bit_bang.rb +33 -0
- data/lib/denko/board.rb +104 -0
- data/lib/denko/connection/base.rb +75 -0
- data/lib/denko/connection/board_uart.rb +36 -0
- data/lib/denko/connection/flow_control.rb +153 -0
- data/lib/denko/connection/handshake.rb +60 -0
- data/lib/denko/connection/serial.rb +90 -0
- data/lib/denko/connection/tcp.rb +44 -0
- data/lib/denko/connection.rb +10 -0
- data/lib/denko/digital_io/button.rb +8 -0
- data/lib/denko/digital_io/input.rb +44 -0
- data/lib/denko/digital_io/output.rb +47 -0
- data/lib/denko/digital_io/relay.rb +6 -0
- data/lib/denko/digital_io/rotary_encoder.rb +107 -0
- data/lib/denko/digital_io.rb +9 -0
- data/lib/denko/display/canvas.rb +282 -0
- data/lib/denko/display/hd44780.rb +266 -0
- data/lib/denko/display/ssd1306.rb +179 -0
- data/lib/denko/display.rb +7 -0
- data/lib/denko/eeprom/built_in.rb +69 -0
- data/lib/denko/eeprom.rb +5 -0
- data/lib/denko/fonts.rb +106 -0
- data/lib/denko/i2c/bus.rb +52 -0
- data/lib/denko/i2c/peripheral.rb +38 -0
- data/lib/denko/i2c.rb +6 -0
- data/lib/denko/led/apa102.rb +87 -0
- data/lib/denko/led/base.rb +12 -0
- data/lib/denko/led/rgb.rb +38 -0
- data/lib/denko/led/seven_segment.rb +111 -0
- data/lib/denko/led/ws2812.rb +48 -0
- data/lib/denko/led.rb +13 -0
- data/lib/denko/message.rb +92 -0
- data/lib/denko/motor/l298.rb +49 -0
- data/lib/denko/motor/servo.rb +51 -0
- data/lib/denko/motor/stepper.rb +71 -0
- data/lib/denko/motor.rb +7 -0
- data/lib/denko/one_wire/bus.rb +61 -0
- data/lib/denko/one_wire/bus_enumeration.rb +88 -0
- data/lib/denko/one_wire/constants.rb +17 -0
- data/lib/denko/one_wire/helper.rb +33 -0
- data/lib/denko/one_wire/peripheral.rb +62 -0
- data/lib/denko/one_wire.rb +9 -0
- data/lib/denko/pulse_io/buzzer.rb +25 -0
- data/lib/denko/pulse_io/ir_transmitter.rb +22 -0
- data/lib/denko/pulse_io/pwm_output.rb +34 -0
- data/lib/denko/pulse_io.rb +7 -0
- data/lib/denko/rtc/ds3231.rb +48 -0
- data/lib/denko/rtc.rb +5 -0
- data/lib/denko/sensor/aht.rb +165 -0
- data/lib/denko/sensor/bme280.rb +366 -0
- data/lib/denko/sensor/dht.rb +43 -0
- data/lib/denko/sensor/ds18b20.rb +74 -0
- data/lib/denko/sensor/htu21d.rb +168 -0
- data/lib/denko/sensor/htu31d.rb +187 -0
- data/lib/denko/sensor/virtual.rb +42 -0
- data/lib/denko/sensor.rb +13 -0
- data/lib/denko/spi/base_register.rb +37 -0
- data/lib/denko/spi/bit_bang.rb +74 -0
- data/lib/denko/spi/bus.rb +44 -0
- data/lib/denko/spi/input_register.rb +130 -0
- data/lib/denko/spi/output_register.rb +67 -0
- data/lib/denko/spi/peripheral.rb +43 -0
- data/lib/denko/spi.rb +10 -0
- data/lib/denko/uart/bit_bang.rb +69 -0
- data/lib/denko/uart/hardware.rb +65 -0
- data/lib/denko/uart.rb +6 -0
- data/lib/denko/version.rb +3 -0
- data/lib/denko.rb +39 -0
- data/lib/denko_cli/generator.rb +171 -0
- data/lib/denko_cli/helper.rb +29 -0
- data/lib/denko_cli/missing_files.txt +20 -0
- data/lib/denko_cli/packages.rb +101 -0
- data/lib/denko_cli/parser.rb +73 -0
- data/lib/denko_cli/targets.rb +30 -0
- data/lib/denko_cli/targets.txt +113 -0
- data/lib/denko_cli/usage.txt +34 -0
- data/lib/denko_cli.rb +18 -0
- data/src/denko_ethernet.ino +78 -0
- data/src/denko_serial.ino +41 -0
- data/src/denko_wifi.ino +157 -0
- data/src/lib/Denko.cpp +330 -0
- data/src/lib/Denko.h +259 -0
- data/src/lib/DenkoCoreIO.cpp +322 -0
- data/src/lib/DenkoDefines.h +116 -0
- data/src/lib/DenkoEEPROM.cpp +64 -0
- data/src/lib/DenkoI2C.cpp +155 -0
- data/src/lib/DenkoIROut.cpp +33 -0
- data/src/lib/DenkoIROutESP.cpp +26 -0
- data/src/lib/DenkoLEDArray.cpp +49 -0
- data/src/lib/DenkoOneWire.cpp +156 -0
- data/src/lib/DenkoPulseInput.cpp +57 -0
- data/src/lib/DenkoSPI.cpp +165 -0
- data/src/lib/DenkoSPIBB.cpp +156 -0
- data/src/lib/DenkoServo.cpp +83 -0
- data/src/lib/DenkoTone.cpp +25 -0
- data/src/lib/DenkoUART.cpp +118 -0
- data/src/lib/DenkoUARTBB.cpp +62 -0
- data/target.yml +3 -0
- data/test/analog_io/input_test.rb +38 -0
- data/test/analog_io/output_test.rb +26 -0
- data/test/analog_io/potentiometer_test.rb +62 -0
- data/test/behaviors/board_proxy_test.rb +24 -0
- data/test/behaviors/bus_controller_addressed_test.rb +40 -0
- data/test/behaviors/bus_controller_test.rb +28 -0
- data/test/behaviors/bus_peripheral_addressed.rb +44 -0
- data/test/behaviors/bus_peripheral_test.rb +39 -0
- data/test/behaviors/callbacks_test.rb +118 -0
- data/test/behaviors/component_test.rb +56 -0
- data/test/behaviors/input_pin_test.rb +42 -0
- data/test/behaviors/listener_test.rb +60 -0
- data/test/behaviors/multi_pin_test.rb +70 -0
- data/test/behaviors/output_pin_test.rb +27 -0
- data/test/behaviors/poller_test.rb +64 -0
- data/test/behaviors/reader_test.rb +68 -0
- data/test/behaviors/single_pin_test.rb +41 -0
- data/test/behaviors/subcomponents_test.rb +75 -0
- data/test/behaviors/threaded_test.rb +98 -0
- data/test/board/board_test.rb +130 -0
- data/test/board/core_test.rb +182 -0
- data/test/board/eeprom_test.rb +34 -0
- data/test/board/helper_test.rb +38 -0
- data/test/board/i2c_test.rb +114 -0
- data/test/board/infrared_test.rb +37 -0
- data/test/board/message_test.rb +54 -0
- data/test/board/one_wire_test.rb +69 -0
- data/test/board/pulse_test.rb +51 -0
- data/test/board/servo_test.rb +47 -0
- data/test/board/spi_test.rb +97 -0
- data/test/board/tone_test.rb +42 -0
- data/test/connection/serial_test.rb +172 -0
- data/test/connection/tcp_test.rb +37 -0
- data/test/digital_io/input_test.rb +65 -0
- data/test/digital_io/output_test.rb +64 -0
- data/test/digital_io/rotary_encoder_test.rb +99 -0
- data/test/display/hd44780_test.rb +23 -0
- data/test/eeprom/built_in_test.rb +61 -0
- data/test/i2c/bus_test.rb +66 -0
- data/test/i2c/peripheral_test.rb +50 -0
- data/test/led/base_test.rb +24 -0
- data/test/led/rgb_test.rb +64 -0
- data/test/led/seven_segment_test.rb +86 -0
- data/test/motor/servo_test.rb +62 -0
- data/test/motor/stepper_test.rb +51 -0
- data/test/one_wire/bus_enumerator_test.rb +134 -0
- data/test/one_wire/bus_test.rb +142 -0
- data/test/one_wire/helper_test.rb +18 -0
- data/test/one_wire/peripheral_test.rb +158 -0
- data/test/pulse_io/buzzer_test.rb +48 -0
- data/test/pulse_io/ir_transmitter_test.rb +38 -0
- data/test/pulse_io/pwm_output_test.rb +72 -0
- data/test/rtc/ds3231_test.rb +55 -0
- data/test/sensor/dht_test.rb +64 -0
- data/test/sensor/ds18b20_test.rb +107 -0
- data/test/spi/base_register_test.rb +34 -0
- data/test/spi/bus_test.rb +76 -0
- data/test/spi/input_register_test.rb +140 -0
- data/test/spi/output_register_test.rb +93 -0
- data/test/test_helper.rb +223 -0
- data/test/uart/bitbang_test.rb +37 -0
- data/tutorial/01-led/led.fzz +0 -0
- data/tutorial/01-led/led.pdf +0 -0
- data/tutorial/01-led/led.rb +73 -0
- data/tutorial/02-button/button.fzz +0 -0
- data/tutorial/02-button/button.pdf +0 -0
- data/tutorial/02-button/button.rb +64 -0
- data/tutorial/03-potentiometer/potentiometer.fzz +0 -0
- data/tutorial/03-potentiometer/potentiometer.pdf +0 -0
- data/tutorial/03-potentiometer/potentiometer.rb +62 -0
- data/tutorial/04-pwm_led/pwm_led.fzz +0 -0
- data/tutorial/04-pwm_led/pwm_led.pdf +0 -0
- data/tutorial/04-pwm_led/pwm_led.rb +66 -0
- data/tutorial/05-rgb_led/rgb_led.fzz +0 -0
- data/tutorial/05-rgb_led/rgb_led.pdf +0 -0
- data/tutorial/05-rgb_led/rgb_led.rb +58 -0
- data/tutorial/05-rgb_led/rgb_mapping.rb +76 -0
- data/vendor/board-maps/.gitignore +56 -0
- data/vendor/board-maps/.gitmodules +21 -0
- data/vendor/board-maps/BoardMap.h +1364 -0
- data/vendor/board-maps/README.md +51 -0
- data/vendor/board-maps/lib/boards_parser.rb +66 -0
- data/vendor/board-maps/lib/header_parser.rb +164 -0
- data/vendor/board-maps/run.rb +47 -0
- data/vendor/board-maps/yaml/0XCB_HELIOS.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S2.yml +25 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S2_REVTFT.yml +25 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S2_TFT.yml +27 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3.yml +29 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3_NOPSRAM.yml +29 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3_REVTFT.yml +25 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3_TFT.yml +27 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32_V2.yml +30 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_CAN.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_DVI.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_PROP_MAKER.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_RFM.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_SCORPIO.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_THINKINK.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_USB_HOST.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_ITSYBITSY_ESP32.yml +24 -0
- data/vendor/board-maps/yaml/ADAFRUIT_ITSYBITSY_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_KB2040_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_MACROPAD_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_MATRIXPORTAL_ESP32S3.yml +16 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32C3.yml +12 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S2.yml +22 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_NOPSRAM.yml +20 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32_PICO.yml +27 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_STEMMAFRIEND_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ADAFRUIT_TRINKEYQT_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/ALKS.yml +34 -0
- data/vendor/board-maps/yaml/AMPERKA_WIFI_SLOT.yml +16 -0
- data/vendor/board-maps/yaml/AVR_ADK.yml +24 -0
- data/vendor/board-maps/yaml/AVR_BT.yml +16 -0
- data/vendor/board-maps/yaml/AVR_CIRCUITPLAY.yml +14 -0
- data/vendor/board-maps/yaml/AVR_DUEMILANOVE.yml +16 -0
- data/vendor/board-maps/yaml/AVR_ESPLORA.yml +20 -0
- data/vendor/board-maps/yaml/AVR_ETHERNET.yml +16 -0
- data/vendor/board-maps/yaml/AVR_FIO.yml +16 -0
- data/vendor/board-maps/yaml/AVR_GEMMA.yml +6 -0
- data/vendor/board-maps/yaml/AVR_INDUSTRIAL101.yml +20 -0
- data/vendor/board-maps/yaml/AVR_LEONARDO.yml +20 -0
- data/vendor/board-maps/yaml/AVR_LEONARDO_ETH.yml +20 -0
- data/vendor/board-maps/yaml/AVR_LILYPAD.yml +16 -0
- data/vendor/board-maps/yaml/AVR_LILYPAD_USB.yml +20 -0
- data/vendor/board-maps/yaml/AVR_LININO_ONE.yml +20 -0
- data/vendor/board-maps/yaml/AVR_MEGA.yml +24 -0
- data/vendor/board-maps/yaml/AVR_MEGA2560.yml +24 -0
- data/vendor/board-maps/yaml/AVR_MICRO.yml +20 -0
- data/vendor/board-maps/yaml/AVR_MINI.yml +16 -0
- data/vendor/board-maps/yaml/AVR_NANO.yml +16 -0
- data/vendor/board-maps/yaml/AVR_NANO_EVERY.yml +22 -0
- data/vendor/board-maps/yaml/AVR_NG.yml +16 -0
- data/vendor/board-maps/yaml/AVR_PRO.yml +16 -0
- data/vendor/board-maps/yaml/AVR_ROBOT_CONTROL.yml +22 -0
- data/vendor/board-maps/yaml/AVR_ROBOT_MOTOR.yml +19 -0
- data/vendor/board-maps/yaml/AVR_UNO.yml +16 -0
- data/vendor/board-maps/yaml/AVR_UNO_WIFI_DEV_ED.yml +16 -0
- data/vendor/board-maps/yaml/AVR_UNO_WIFI_REV2.yml +22 -0
- data/vendor/board-maps/yaml/AVR_YUN.yml +20 -0
- data/vendor/board-maps/yaml/AVR_YUNMINI.yml +20 -0
- data/vendor/board-maps/yaml/AirM2M_CORE_ESP32C3.yml +14 -0
- data/vendor/board-maps/yaml/BEE_DATA_LOGGER.yml +39 -0
- data/vendor/board-maps/yaml/BPI_BIT.yml +9 -0
- data/vendor/board-maps/yaml/BPI_LEAF_S3.yml +31 -0
- data/vendor/board-maps/yaml/BRIDGETEK_IDM2040-7A.yml +48 -0
- data/vendor/board-maps/yaml/BeeMotionS3.yml +40 -0
- data/vendor/board-maps/yaml/Bee_Motion.yml +27 -0
- data/vendor/board-maps/yaml/Bee_Motion_Mini.yml +1 -0
- data/vendor/board-maps/yaml/Bee_S3.yml +38 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_LORA_RP2040.yml +39 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_LTE_RP2040.yml +38 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_NFC_RP2040.yml +32 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_SDRTC_RP2040.yml +36 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_SUBGHZ_RP2040.yml +39 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_UWB_RP2040.yml +39 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_WIFI_BLE_RP2040.yml +42 -0
- data/vendor/board-maps/yaml/CHALLENGER_2040_WIFI_RP2040.yml +38 -0
- data/vendor/board-maps/yaml/CHALLENGER_NB_2040_WIFI_RP2040.yml +38 -0
- data/vendor/board-maps/yaml/CRABIK_SLOT_ESP32_S3.yml +19 -0
- data/vendor/board-maps/yaml/CYTRON_MAKER_FEATHER_AIOT_S3.yml +26 -0
- data/vendor/board-maps/yaml/CYTRON_MAKER_NANO_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/CYTRON_MAKER_PI_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/CoreESP32.yml +49 -0
- data/vendor/board-maps/yaml/D1_MINI32.yml +36 -0
- data/vendor/board-maps/yaml/D1_UNO32.yml +28 -0
- data/vendor/board-maps/yaml/DATANOISETV_PICOADK.yml +48 -0
- data/vendor/board-maps/yaml/DENKY.yml +26 -0
- data/vendor/board-maps/yaml/DENKY_PICOV3.yml +26 -0
- data/vendor/board-maps/yaml/DENKY_WROOM32.yml +26 -0
- data/vendor/board-maps/yaml/DEPARTMENT_OF_ALCHEMY_MINIMAIN_ESP32S2.yml +26 -0
- data/vendor/board-maps/yaml/DFROBOT_BEETLE_ESP32_C3.yml +14 -0
- data/vendor/board-maps/yaml/DFROBOT_BEETLE_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32E.yml +44 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32S3.yml +38 -0
- data/vendor/board-maps/yaml/DFROBOT_ROMEO_ESP32S3.yml +7 -0
- data/vendor/board-maps/yaml/DPU_ESP32.yml +26 -0
- data/vendor/board-maps/yaml/DYDK.yml +38 -0
- data/vendor/board-maps/yaml/DYDK1A.yml +37 -0
- data/vendor/board-maps/yaml/DYDK1Av2.yml +45 -0
- data/vendor/board-maps/yaml/DYG.yml +20 -0
- data/vendor/board-maps/yaml/DYM.yml +40 -0
- data/vendor/board-maps/yaml/DYMv2.yml +39 -0
- data/vendor/board-maps/yaml/D_Duino_32.yml +29 -0
- data/vendor/board-maps/yaml/ELECTRONICCATS_HUNTERCAT_NFC.yml +44 -0
- data/vendor/board-maps/yaml/ESP320.yml +8 -0
- data/vendor/board-maps/yaml/ESP32C3_DEV.yml +14 -0
- data/vendor/board-maps/yaml/ESP32C3_M1_I_KIT.yml +13 -0
- data/vendor/board-maps/yaml/ESP32S2_DEV.yml +33 -0
- data/vendor/board-maps/yaml/ESP32S2_THING_PLUS.yml +34 -0
- data/vendor/board-maps/yaml/ESP32S2_USB.yml +33 -0
- data/vendor/board-maps/yaml/ESP32S3_CAM_LCD.yml +7 -0
- data/vendor/board-maps/yaml/ESP32S3_DEV.yml +38 -0
- data/vendor/board-maps/yaml/ESP32_DEV.yml +26 -0
- data/vendor/board-maps/yaml/ESP32_DEVKIT_LIPO.yml +26 -0
- data/vendor/board-maps/yaml/ESP32_EVB.yml +7 -0
- data/vendor/board-maps/yaml/ESP32_GATEWAY.yml +13 -0
- data/vendor/board-maps/yaml/ESP32_GATEWAY_C.yml +13 -0
- data/vendor/board-maps/yaml/ESP32_GATEWAY_E.yml +13 -0
- data/vendor/board-maps/yaml/ESP32_GATEWAY_F.yml +13 -0
- data/vendor/board-maps/yaml/ESP32_IOT_REDBOARD.yml +27 -0
- data/vendor/board-maps/yaml/ESP32_MICROMOD.yml +24 -0
- data/vendor/board-maps/yaml/ESP32_PICO.yml +26 -0
- data/vendor/board-maps/yaml/ESP32_POE.yml +7 -0
- data/vendor/board-maps/yaml/ESP32_POE_ISO.yml +7 -0
- data/vendor/board-maps/yaml/ESP32_S3_BOX.yml +16 -0
- data/vendor/board-maps/yaml/ESP32_S3_USB_OTG.yml +11 -0
- data/vendor/board-maps/yaml/ESP32_THING.yml +27 -0
- data/vendor/board-maps/yaml/ESP32_THING_PLUS.yml +30 -0
- data/vendor/board-maps/yaml/ESP32_THING_PLUS_C.yml +30 -0
- data/vendor/board-maps/yaml/ESP32_WROOM_DA.yml +26 -0
- data/vendor/board-maps/yaml/ESP32_WROVER_KIT.yml +26 -0
- data/vendor/board-maps/yaml/ESP8266_ADAFRUIT_HUZZAH.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_AGRUMINO_LEMON_V4.yml +8 -0
- data/vendor/board-maps/yaml/ESP8266_ARDUINO_PRIMO.yml +7 -0
- data/vendor/board-maps/yaml/ESP8266_ARDUINO_STAR_OTTO.yml +7 -0
- data/vendor/board-maps/yaml/ESP8266_ARDUINO_UNOWIFI.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESP01.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESP07.yml +20 -0
- data/vendor/board-maps/yaml/ESP8266_ESP12.yml +20 -0
- data/vendor/board-maps/yaml/ESP8266_ESP13.yml +17 -0
- data/vendor/board-maps/yaml/ESP8266_ESP210.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESPECTRO_CORE.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESPINO_ESP12.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESPINO_ESP13.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESPRESSO_LITE_V1.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_ESPRESSO_LITE_V2.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_GENERIC.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_INVENT_ONE.yml +22 -0
- data/vendor/board-maps/yaml/ESP8266_NODEMCU_ESP12.yml +20 -0
- data/vendor/board-maps/yaml/ESP8266_NODEMCU_ESP12E.yml +20 -0
- data/vendor/board-maps/yaml/ESP8266_OAK.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_PHOENIX_V1.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_PHOENIX_V2.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_SCHIRMILABS_EDUINO_WIFI.yml +25 -0
- data/vendor/board-maps/yaml/ESP8266_SONOFF_BASIC.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_SONOFF_S20.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_SONOFF_SV.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_SONOFF_TH.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_THING.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_THING_DEV.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_WEMOS_D1MINI.yml +18 -0
- data/vendor/board-maps/yaml/ESP8266_WEMOS_D1MINILITE.yml +18 -0
- data/vendor/board-maps/yaml/ESP8266_WEMOS_D1MINIPRO.yml +18 -0
- data/vendor/board-maps/yaml/ESP8266_WEMOS_D1R1.yml +25 -0
- data/vendor/board-maps/yaml/ESP8266_WEMOS_D1WROOM02.yml +18 -0
- data/vendor/board-maps/yaml/ESP8266_WIO_LINK.yml +9 -0
- data/vendor/board-maps/yaml/ESP8266_XINABOX_CW01.yml +9 -0
- data/vendor/board-maps/yaml/ESPECTRO32.yml +27 -0
- data/vendor/board-maps/yaml/ESPea32.yml +27 -0
- data/vendor/board-maps/yaml/ESPino32.yml +27 -0
- data/vendor/board-maps/yaml/ET-Board.yml +26 -0
- data/vendor/board-maps/yaml/EXTREMEELEXTRONICS_RC2040.yml +46 -0
- data/vendor/board-maps/yaml/Edgebox-ESP-100.yml +7 -0
- data/vendor/board-maps/yaml/FEATHERS2.yml +33 -0
- data/vendor/board-maps/yaml/FEATHERS2NEO.yml +30 -0
- data/vendor/board-maps/yaml/FEATHERS3.yml +29 -0
- data/vendor/board-maps/yaml/FEATHER_ESP32.yml +28 -0
- data/vendor/board-maps/yaml/FLYBOARD2040_CORE.yml +48 -0
- data/vendor/board-maps/yaml/FRANZININHO_WIFI.yml +33 -0
- data/vendor/board-maps/yaml/FRANZININHO_WIFI_MSC.yml +33 -0
- data/vendor/board-maps/yaml/FROG_ESP32.yml +26 -0
- data/vendor/board-maps/yaml/FUNHOUSE_ESP32S2.yml +22 -0
- data/vendor/board-maps/yaml/GEN4_IOD.yml +9 -0
- data/vendor/board-maps/yaml/GENERIC_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/HEALTHYPI_4.yml +27 -0
- data/vendor/board-maps/yaml/HONEYLEMON.yml +27 -0
- data/vendor/board-maps/yaml/HORNBILL_ESP32_DEV.yml +27 -0
- data/vendor/board-maps/yaml/HORNBILL_ESP32_MINIMA.yml +16 -0
- data/vendor/board-maps/yaml/ILABS_2040_RPICO32_RP2040.yml +47 -0
- data/vendor/board-maps/yaml/IMBRIOS_LOGSENS_V1P1.yml +19 -0
- data/vendor/board-maps/yaml/INTOROBOT_ESP32_DEV.yml +34 -0
- data/vendor/board-maps/yaml/LILYGO_T_DISPLAY_S3.yml +26 -0
- data/vendor/board-maps/yaml/LOLIN32.yml +27 -0
- data/vendor/board-maps/yaml/LOLIN32_LITE.yml +27 -0
- data/vendor/board-maps/yaml/LOLIN_C3_MINI.yml +14 -0
- data/vendor/board-maps/yaml/LOLIN_D32.yml +27 -0
- data/vendor/board-maps/yaml/LOLIN_D32_PRO.yml +27 -0
- data/vendor/board-maps/yaml/LOLIN_S2_MINI.yml +34 -0
- data/vendor/board-maps/yaml/LOLIN_S2_PICO.yml +34 -0
- data/vendor/board-maps/yaml/LOLIN_S3.yml +32 -0
- data/vendor/board-maps/yaml/LOLIN_S3_MINI.yml +32 -0
- data/vendor/board-maps/yaml/LOLIN_S3_PRO.yml +32 -0
- data/vendor/board-maps/yaml/Lion_Bit_Dev_Board.yml +18 -0
- data/vendor/board-maps/yaml/LoPy.yml +27 -0
- data/vendor/board-maps/yaml/LoPy4.yml +27 -0
- data/vendor/board-maps/yaml/M5STACK_CORES3.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_Core2.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_FIRE.yml +10 -0
- data/vendor/board-maps/yaml/M5Stack-Timer-CAM.yml +10 -0
- data/vendor/board-maps/yaml/M5Stack_ATOM.yml +10 -0
- data/vendor/board-maps/yaml/M5Stack_ATOMS3.yml +7 -0
- data/vendor/board-maps/yaml/M5Stack_CoreInk.yml +9 -0
- data/vendor/board-maps/yaml/M5Stack_Core_ESP32.yml +10 -0
- data/vendor/board-maps/yaml/M5Stack_Station.yml +10 -0
- data/vendor/board-maps/yaml/M5Stick_C.yml +10 -0
- data/vendor/board-maps/yaml/MAGTAG29_ESP32S2.yml +21 -0
- data/vendor/board-maps/yaml/MELOPERO_COOKIE_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/MELOPERO_SHAKE_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/METRO_ESP32S2.yml +34 -0
- data/vendor/board-maps/yaml/MGBOT_IOTIK32A.yml +27 -0
- data/vendor/board-maps/yaml/MGBOT_IOTIK32B.yml +27 -0
- data/vendor/board-maps/yaml/MH_ET_LIVE_ESP32DEVKIT.yml +27 -0
- data/vendor/board-maps/yaml/MH_ET_LIVE_ESP32MINIKIT.yml +27 -0
- data/vendor/board-maps/yaml/MICROS2.yml +34 -0
- data/vendor/board-maps/yaml/MOD_WIFI_ESP8266.yml +9 -0
- data/vendor/board-maps/yaml/Metro.yml +8 -0
- data/vendor/board-maps/yaml/NANO32.yml +27 -0
- data/vendor/board-maps/yaml/NANO_RP2040_CONNECT.yml +35 -0
- data/vendor/board-maps/yaml/NEBULAS3.yml +33 -0
- data/vendor/board-maps/yaml/NEKOSYSTEMS_BL2040_MINI.yml +48 -0
- data/vendor/board-maps/yaml/NULLBITS_BIT_C_PRO.yml +48 -0
- data/vendor/board-maps/yaml/Node32s.yml +27 -0
- data/vendor/board-maps/yaml/NodeMCU_32S.yml +27 -0
- data/vendor/board-maps/yaml/ODROID_ESP32.yml +10 -0
- data/vendor/board-maps/yaml/ONEHORSE_ESP32_DEV.yml +24 -0
- data/vendor/board-maps/yaml/OROCA_EDUBOT.yml +33 -0
- data/vendor/board-maps/yaml/PIMORONI_PGA2040.yml +48 -0
- data/vendor/board-maps/yaml/PROS3.yml +28 -0
- data/vendor/board-maps/yaml/PYCOM_GPY.yml +27 -0
- data/vendor/board-maps/yaml/Piranha.yml +16 -0
- data/vendor/board-maps/yaml/Pocket32.yml +27 -0
- data/vendor/board-maps/yaml/QUANTUM.yml +26 -0
- data/vendor/board-maps/yaml/RASPBERRY_PI_PICO.yml +48 -0
- data/vendor/board-maps/yaml/RASPBERRY_PI_PICO_W.yml +48 -0
- data/vendor/board-maps/yaml/REDPILL_ESP32S3.yml +32 -0
- data/vendor/board-maps/yaml/RMP.yml +33 -0
- data/vendor/board-maps/yaml/SAMD_CIRCUITPLAYGROUND_EXPRESS.yml +12 -0
- data/vendor/board-maps/yaml/SAMD_MKR1000.yml +20 -0
- data/vendor/board-maps/yaml/SAMD_MKRFox1200.yml +19 -0
- data/vendor/board-maps/yaml/SAMD_MKRGSM1400.yml +15 -0
- data/vendor/board-maps/yaml/SAMD_MKRNB1500.yml +15 -0
- data/vendor/board-maps/yaml/SAMD_MKRVIDOR4000.yml +19 -0
- data/vendor/board-maps/yaml/SAMD_MKRWAN1300.yml +18 -0
- data/vendor/board-maps/yaml/SAMD_MKRWAN1310.yml +18 -0
- data/vendor/board-maps/yaml/SAMD_MKRWIFI1010.yml +19 -0
- data/vendor/board-maps/yaml/SAMD_MKRZERO.yml +19 -0
- data/vendor/board-maps/yaml/SAMD_NANO_33_IOT.yml +13 -0
- data/vendor/board-maps/yaml/SAMD_TIAN.yml +15 -0
- data/vendor/board-maps/yaml/SAMD_ZERO.yml +14 -0
- data/vendor/board-maps/yaml/SAM_DUE.yml +26 -0
- data/vendor/board-maps/yaml/SAM_ZERO.yml +15 -0
- data/vendor/board-maps/yaml/SEEED_INDICATOR_RP2040.yml +47 -0
- data/vendor/board-maps/yaml/SEEED_XIAO_RP2040.yml +29 -0
- data/vendor/board-maps/yaml/SOLDERPARTY_RP2040_STAMP.yml +48 -0
- data/vendor/board-maps/yaml/SONOFF_DUALR3.yml +26 -0
- data/vendor/board-maps/yaml/SPARKFUN_PROMICRO_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/SPARKFUN_THINGPLUS_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/STAMP_S3.yml +4 -0
- data/vendor/board-maps/yaml/TAMC_TERMOD_S3.yml +31 -0
- data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1262.yml +23 -0
- data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1268.yml +23 -0
- data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1276.yml +23 -0
- data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1278.yml +23 -0
- data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1280.yml +23 -0
- data/vendor/board-maps/yaml/TBeam.yml +23 -0
- data/vendor/board-maps/yaml/TINYPICO.yml +26 -0
- data/vendor/board-maps/yaml/TINYS2.yml +33 -0
- data/vendor/board-maps/yaml/TINYS3.yml +25 -0
- data/vendor/board-maps/yaml/TTGO-T-OI-PLUS_DEV.yml +11 -0
- data/vendor/board-maps/yaml/TTGO_LoRa32_V1.yml +28 -0
- data/vendor/board-maps/yaml/TTGO_LoRa32_V2.yml +28 -0
- data/vendor/board-maps/yaml/TTGO_LoRa32_v21new.yml +28 -0
- data/vendor/board-maps/yaml/TTGO_T1.yml +27 -0
- data/vendor/board-maps/yaml/TTGO_T7_V13_Mini32.yml +27 -0
- data/vendor/board-maps/yaml/TTGO_T7_V14_Mini32.yml +27 -0
- data/vendor/board-maps/yaml/TWATCH_2020_V1.yml +10 -0
- data/vendor/board-maps/yaml/TWATCH_2020_V2.yml +10 -0
- data/vendor/board-maps/yaml/TWATCH_2020_V3.yml +10 -0
- data/vendor/board-maps/yaml/TWATCH_BASE.yml +10 -0
- data/vendor/board-maps/yaml/TWatch.yml +10 -0
- data/vendor/board-maps/yaml/Trueverit_ESP32_Universal_IoT_Driver.yml +18 -0
- data/vendor/board-maps/yaml/Trueverit_ESP32_Universal_IoT_Driver_MK_II.yml +18 -0
- data/vendor/board-maps/yaml/UBLOX_NINA_W10.yml +48 -0
- data/vendor/board-maps/yaml/UBLOX_NORA_W10.yml +43 -0
- data/vendor/board-maps/yaml/UPESY_RP2040_DEVKIT.yml +48 -0
- data/vendor/board-maps/yaml/VALTRACK_V4_MFW_ESP32_C3.yml +23 -0
- data/vendor/board-maps/yaml/VALTRACK_V4_VTS_ESP32_C3.yml +23 -0
- data/vendor/board-maps/yaml/VIYALAB_MIZU_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/WATCHY.yml +7 -0
- data/vendor/board-maps/yaml/WATCHY_V10.yml +7 -0
- data/vendor/board-maps/yaml/WATCHY_V15.yml +7 -0
- data/vendor/board-maps/yaml/WATCHY_V20.yml +7 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_LCD_0_96.yml +47 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_LCD_1_28.yml +47 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ONE.yml +47 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_PLUS.yml +48 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ZERO.yml +47 -0
- data/vendor/board-maps/yaml/WESP32.yml +17 -0
- data/vendor/board-maps/yaml/WIDORA_AIR.yml +34 -0
- data/vendor/board-maps/yaml/WIFIDUINO_ESP8266.yml +23 -0
- data/vendor/board-maps/yaml/WIFINFO.yml +20 -0
- data/vendor/board-maps/yaml/WIPY3.yml +27 -0
- data/vendor/board-maps/yaml/WIZNET_5100S_EVB_PICO.yml +48 -0
- data/vendor/board-maps/yaml/WIZNET_5500_EVB_PICO.yml +48 -0
- data/vendor/board-maps/yaml/WIZNET_WIZFI360_EVB_PICO.yml +48 -0
- data/vendor/board-maps/yaml/WT32_ETH01.yml +8 -0
- data/vendor/board-maps/yaml/WiFiduino32S3.yml +27 -0
- data/vendor/board-maps/yaml/WiFiduinoV2.yml +27 -0
- data/vendor/board-maps/yaml/Wifiduino32.yml +40 -0
- data/vendor/board-maps/yaml/XIAO_ESP32C3.yml +22 -0
- data/vendor/board-maps/yaml/XIAO_ESP32S3.yml +36 -0
- data/vendor/board-maps/yaml/YD_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/atmegazero_esp32s2.yml +30 -0
- data/vendor/board-maps/yaml/connaxio_espoir.yml +18 -0
- data/vendor/board-maps/yaml/esp32vn_iot_uno.yml +22 -0
- data/vendor/board-maps/yaml/fm_devkit.yml +15 -0
- data/vendor/board-maps/yaml/heltec_wifi_32_lora_V3.yml +31 -0
- data/vendor/board-maps/yaml/heltec_wifi_kit_32.yml +28 -0
- data/vendor/board-maps/yaml/heltec_wifi_kit_32_V3.yml +32 -0
- data/vendor/board-maps/yaml/heltec_wifi_lora_32.yml +27 -0
- data/vendor/board-maps/yaml/heltec_wifi_lora_32_V2.yml +27 -0
- data/vendor/board-maps/yaml/heltec_wireless_stick.yml +27 -0
- data/vendor/board-maps/yaml/heltec_wireless_stick_LITE.yml +27 -0
- data/vendor/board-maps/yaml/openkb.yml +27 -0
- data/vendor/board-maps/yaml/roboheart_hercules.yml +17 -0
- data/vendor/board-maps/yaml/sensesiot_weizen.yml +26 -0
- data/vendor/board-maps/yaml/uPesy_WROOM.yml +27 -0
- data/vendor/board-maps/yaml/uPesy_WROVER.yml +27 -0
- data/vendor/board-maps/yaml/unphone8.yml +32 -0
- data/vendor/board-maps/yaml/unphone9.yml +32 -0
- data/vendor/board-maps/yaml/wifi_kit_8.yml +15 -0
- metadata +800 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class InputRegisterTest < Minitest::Test
|
4
|
+
def board
|
5
|
+
@board ||= BoardMock.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def bus
|
9
|
+
@bus ||= Denko::SPI::Bus.new(board: board)
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
{ bus: bus, pin: 9, bytes: 2, spi_frequency: 800000, spi_mode: 2, spi_bit_order: :lsbfirst}
|
14
|
+
end
|
15
|
+
|
16
|
+
def part
|
17
|
+
@part ||= Denko::SPI::InputRegister.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def button
|
21
|
+
@button ||= Denko::DigitalIO::Button.new(board: part, pin: 0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_state_setup
|
25
|
+
assert_equal part.instance_variable_get(:@reading_pins), Array.new(16) { false }
|
26
|
+
assert_equal part.instance_variable_get(:@listening_pins), Array.new(16) { false }
|
27
|
+
refute_nil part.callbacks[:board_proxy]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_read
|
31
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9], read: 2, frequency: 800000, mode: 2, bit_order: :lsbfirst
|
32
|
+
bus.stub(:transfer, mock) do
|
33
|
+
part.read
|
34
|
+
end
|
35
|
+
mock.verify
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_listen
|
39
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9], read: 2, frequency: 800000, mode: 2, bit_order: :lsbfirst
|
40
|
+
bus.stub(:listen, mock) do
|
41
|
+
part.listen
|
42
|
+
end
|
43
|
+
mock.verify
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_stop
|
47
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9]
|
48
|
+
bus.stub(:stop, mock) do
|
49
|
+
part.stop
|
50
|
+
end
|
51
|
+
mock.verify
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_updates_child_components
|
55
|
+
button
|
56
|
+
part.update("1")
|
57
|
+
assert button.high?
|
58
|
+
part.update("0")
|
59
|
+
assert button.low?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_bit_array_conversion_and_state_update
|
63
|
+
part.update("127")
|
64
|
+
assert_equal [1,1,1,1,1,1,1,0], part.state
|
65
|
+
|
66
|
+
new_part = Denko::SPI::InputRegister.new(options.merge(bytes: 2, pin: 10))
|
67
|
+
new_part.update("127,128")
|
68
|
+
assert_equal [1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1], new_part.state
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_callbacks_get_bit_array
|
72
|
+
mock = MiniTest::Mock.new.expect :call, nil, [[1,1,1,1,1,1,1,0]]
|
73
|
+
part.add_callback do |data|
|
74
|
+
mock.call(data)
|
75
|
+
end
|
76
|
+
part.update("127")
|
77
|
+
mock.verify
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_read_proxy
|
81
|
+
# Stop automatic listening first.
|
82
|
+
button.stop
|
83
|
+
|
84
|
+
# Give #read some value so it stops blocking.
|
85
|
+
Thread.new do
|
86
|
+
sleep(0.01) while !part.callbacks[:force_update]
|
87
|
+
part.update("255")
|
88
|
+
end
|
89
|
+
|
90
|
+
mock = MiniTest::Mock.new
|
91
|
+
mock.expect :call, nil
|
92
|
+
part.stub(:read, mock) do
|
93
|
+
button.read
|
94
|
+
end
|
95
|
+
mock.verify
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_listener_proxy
|
99
|
+
mock = MiniTest::Mock.new
|
100
|
+
mock.expect :call, nil
|
101
|
+
part.stub(:listen, mock) do
|
102
|
+
# Tells the register to start listening when it initializees.
|
103
|
+
button
|
104
|
+
|
105
|
+
# Should not make a second listen call to the board.
|
106
|
+
Denko::DigitalIO::Button.new(board: part, pin: 1)
|
107
|
+
end
|
108
|
+
mock.verify
|
109
|
+
|
110
|
+
expected_array = Array.new(options[:bytes] * 8) { false }
|
111
|
+
expected_array[0] = true
|
112
|
+
expected_array[1] = true
|
113
|
+
|
114
|
+
# Should be listening to the lowest 2 bits now.
|
115
|
+
assert_equal expected_array, part.instance_variable_get(:@listening_pins)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_stop_listener_proxy
|
119
|
+
button
|
120
|
+
|
121
|
+
# Calling stop on a child part, when only it is listening, should call stop on the register too.
|
122
|
+
mock = MiniTest::Mock.new.expect :call, nil
|
123
|
+
part.stub(:stop, mock) do
|
124
|
+
button.stop
|
125
|
+
end
|
126
|
+
mock.verify
|
127
|
+
|
128
|
+
# Check listener tracking is correct.
|
129
|
+
assert_equal Array.new(options[:bytes] * 8) { false }, part.instance_variable_get(:@listening_pins)
|
130
|
+
refute part.any_listening
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_gets_reads_through_pin
|
134
|
+
mock = MiniTest::Mock.new.expect :call, nil, ["127,255"]
|
135
|
+
part.stub(:update, mock) do
|
136
|
+
board.update("#{part.pin}:127,255")
|
137
|
+
end
|
138
|
+
mock.verify
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class OutputRegisterTest < Minitest::Test
|
4
|
+
def board
|
5
|
+
@board ||= BoardMock.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def bus
|
9
|
+
@bus ||= Denko::SPI::Bus.new(board: board)
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
{ bus: bus, pin: 9, bytes: 2, spi_frequency: 800000, spi_mode: 2, spi_bit_order: :lsbfirst }
|
14
|
+
end
|
15
|
+
|
16
|
+
def part
|
17
|
+
@part ||= Denko::SPI::OutputRegister.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def led
|
21
|
+
@led ||= Denko::LED.new(board: part, pin: 0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_write
|
25
|
+
part
|
26
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9], write: [255,127], frequency: 800000, mode: 2, bit_order: :lsbfirst
|
27
|
+
bus.stub(:transfer, mock) do
|
28
|
+
arr = Array.new(16) { 1 }; arr[7] = 0
|
29
|
+
part.instance_variable_set(:@state, arr)
|
30
|
+
part.write
|
31
|
+
end
|
32
|
+
mock.verify
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_state_setup
|
36
|
+
assert_equal part.instance_variable_get(:@write_delay), 0.001
|
37
|
+
assert_equal part.instance_variable_get(:@buffer_writes), true
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_write_buffering_control
|
41
|
+
new_part = Denko::SPI::OutputRegister.new(options.merge(buffer_writes: false, write_delay: 0.5))
|
42
|
+
assert_equal new_part.instance_variable_get(:@write_delay), 0.5
|
43
|
+
assert_equal new_part.instance_variable_get(:@buffer_writes), false
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_updates_and_writes_state_for_children
|
47
|
+
led
|
48
|
+
|
49
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9], write: [0, 1], frequency: 800000, mode: 2, bit_order: :lsbfirst
|
50
|
+
bus.stub(:transfer, mock) do
|
51
|
+
led.on
|
52
|
+
sleep 0.050
|
53
|
+
end
|
54
|
+
mock.verify
|
55
|
+
|
56
|
+
expected_state = Array.new(options[:bytes] * 8) { |i| 0 }
|
57
|
+
expected_state[0] = 1
|
58
|
+
|
59
|
+
assert_equal expected_state, part.state
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_implements_digital_read_for_children
|
63
|
+
led
|
64
|
+
|
65
|
+
mock = MiniTest::Mock.new.expect :call, nil, [0]
|
66
|
+
part.stub(:digital_read, mock) do
|
67
|
+
led.board.digital_read(led.pin)
|
68
|
+
end
|
69
|
+
mock.verify
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_bit_and_byte_orders_correct
|
73
|
+
part.instance_variable_set(:@bytes, 2)
|
74
|
+
bit_array = "0101010100001111".split("")
|
75
|
+
|
76
|
+
mock = MiniTest::Mock.new.expect :call, nil, [9], write: [0b11110000, 0b10101010], frequency: 800000, mode: 2, bit_order: :lsbfirst
|
77
|
+
bus.stub(:transfer, mock) do
|
78
|
+
part.instance_variable_set(:@state, bit_array)
|
79
|
+
part.write
|
80
|
+
sleep 0.002
|
81
|
+
end
|
82
|
+
mock.verify
|
83
|
+
|
84
|
+
assert_equal part.state, bit_array
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_disable_buffering
|
88
|
+
part.instance_variable_set(:@buffer_writes, false)
|
89
|
+
part.instance_variable_set(:@write_delay, 1)
|
90
|
+
led.on
|
91
|
+
assert_nil part.thread
|
92
|
+
end
|
93
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
|
3
|
+
if RUBY_ENGINE == "ruby"
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
track_files "lib/**/*.rb"
|
7
|
+
add_filter "test"
|
8
|
+
add_filter "lib/denko_cli"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'bundler/setup'
|
13
|
+
require 'denko'
|
14
|
+
|
15
|
+
# Touch each class to trigger auto load for simplecov.
|
16
|
+
# Analog IO
|
17
|
+
Denko::AnalogIO::ADS1118
|
18
|
+
Denko::AnalogIO::Input
|
19
|
+
Denko::AnalogIO::Output
|
20
|
+
Denko::AnalogIO::Potentiometer
|
21
|
+
Denko::AnalogIO::Sensor
|
22
|
+
|
23
|
+
# Behaviors
|
24
|
+
# Not needed, since every behavior will be included by at least one class.
|
25
|
+
|
26
|
+
# Board
|
27
|
+
# BoardMock inherits from Denko::Board
|
28
|
+
|
29
|
+
# Connection
|
30
|
+
Denko::Connection::Serial
|
31
|
+
Denko::Connection::TCP
|
32
|
+
|
33
|
+
# Digital IO
|
34
|
+
Denko::DigitalIO::Button
|
35
|
+
Denko::DigitalIO::Input
|
36
|
+
Denko::DigitalIO::Output
|
37
|
+
Denko::DigitalIO::Relay
|
38
|
+
Denko::DigitalIO::RotaryEncoder
|
39
|
+
|
40
|
+
# Display
|
41
|
+
Denko::Display::Canvas
|
42
|
+
Denko::Display::HD44780
|
43
|
+
Denko::Display::SSD1306
|
44
|
+
|
45
|
+
# EEPROM
|
46
|
+
Denko::EEPROM::BuiltIn
|
47
|
+
|
48
|
+
# I2C
|
49
|
+
Denko::I2C::Bus
|
50
|
+
Denko::I2C::Peripheral
|
51
|
+
|
52
|
+
# LED
|
53
|
+
Denko::LED::APA102
|
54
|
+
Denko::LED::Base
|
55
|
+
Denko::LED::RGB
|
56
|
+
Denko::LED::SevenSegment
|
57
|
+
Denko::LED::WS2812
|
58
|
+
|
59
|
+
# Motor
|
60
|
+
Denko::Motor::L298
|
61
|
+
Denko::Motor::Servo
|
62
|
+
Denko::Motor::Stepper
|
63
|
+
|
64
|
+
# OneWire
|
65
|
+
Denko::OneWire::Bus
|
66
|
+
Denko::OneWire::Peripheral
|
67
|
+
Denko::OneWire::Helper
|
68
|
+
|
69
|
+
# Pulse IO
|
70
|
+
Denko::PulseIO::Buzzer
|
71
|
+
Denko::PulseIO::IRTransmitter
|
72
|
+
Denko::PulseIO::PWMOutput
|
73
|
+
|
74
|
+
# RTC
|
75
|
+
Denko::RTC::DS3231
|
76
|
+
|
77
|
+
# Sensor
|
78
|
+
Denko::Sensor::Temperature
|
79
|
+
Denko::Sensor::Humidity
|
80
|
+
Denko::Sensor::BME280
|
81
|
+
Denko::Sensor::BMP280
|
82
|
+
Denko::Sensor::DHT
|
83
|
+
Denko::Sensor::DS18B20
|
84
|
+
Denko::Sensor::HTU21D
|
85
|
+
|
86
|
+
# SPI
|
87
|
+
Denko::SPI::BaseRegister
|
88
|
+
Denko::SPI::BitBang
|
89
|
+
Denko::SPI::Bus
|
90
|
+
Denko::SPI::InputRegister
|
91
|
+
Denko::SPI::OutputRegister
|
92
|
+
|
93
|
+
# UART
|
94
|
+
Denko::UART::BitBang
|
95
|
+
|
96
|
+
# Helper module to redefine constants quietly.
|
97
|
+
module Constants
|
98
|
+
def self.redefine(const, value, opts={})
|
99
|
+
opts = {:on => self.class}.merge(opts)
|
100
|
+
opts[:on].send(:remove_const, const) if self.class.const_defined?(const)
|
101
|
+
opts[:on].const_set(const, value)
|
102
|
+
end
|
103
|
+
ACK = "SAMD_ZERO,0.13.0,528,1024"
|
104
|
+
|
105
|
+
# Some test redefine RUBY_PLATFORM. Save the original to reset it.
|
106
|
+
ORIGINAL_RUBY_PLATFORM = RUBY_PLATFORM
|
107
|
+
end
|
108
|
+
|
109
|
+
# Taken from: https://gist.github.com/moertel/11091573
|
110
|
+
def suppress_output
|
111
|
+
begin
|
112
|
+
original_stderr = $stderr.clone
|
113
|
+
original_stdout = $stdout.clone
|
114
|
+
if Constants::ORIGINAL_RUBY_PLATFORM.match(/mswin|mingw/i)
|
115
|
+
$stderr.reopen('NUL:')
|
116
|
+
$stdout.reopen('NUL:')
|
117
|
+
else
|
118
|
+
$stderr.reopen(File.new('/dev/null', 'w'))
|
119
|
+
$stdout.reopen(File.new('/dev/null', 'w'))
|
120
|
+
end
|
121
|
+
retval = yield
|
122
|
+
rescue Exception => e
|
123
|
+
$stdout.reopen(original_stdout)
|
124
|
+
$stderr.reopen(original_stderr)
|
125
|
+
raise e
|
126
|
+
ensure
|
127
|
+
$stdout.reopen(original_stdout)
|
128
|
+
$stderr.reopen(original_stderr)
|
129
|
+
end
|
130
|
+
retval
|
131
|
+
end
|
132
|
+
|
133
|
+
class ConnectionMock
|
134
|
+
def add_observer(board); true; end
|
135
|
+
def read; true; end
|
136
|
+
def write(str); true; end
|
137
|
+
def handshake
|
138
|
+
Constants::ACK
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class BoardMock < Denko::Board
|
143
|
+
def initialize
|
144
|
+
super(ConnectionMock.new)
|
145
|
+
@read_injection_mutex = Mutex.new
|
146
|
+
end
|
147
|
+
|
148
|
+
WAITING_ON_READ_KEYS = [:read, :bus_controller, :board_proxy, :force_udpate]
|
149
|
+
|
150
|
+
def component_exists_for_pin(pin)
|
151
|
+
self.components.each do |component|
|
152
|
+
return component if component.pin == pin
|
153
|
+
end
|
154
|
+
false
|
155
|
+
end
|
156
|
+
|
157
|
+
def waiting_on_read(component)
|
158
|
+
WAITING_ON_READ_KEYS.each do |key|
|
159
|
+
return true if component.callbacks[key]
|
160
|
+
end
|
161
|
+
false
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Inject a message into the Board instance as if it were coming from the phsyical board.
|
166
|
+
# Use this to mock input data for the blocking #read pattern in the Reader behavior.
|
167
|
+
#
|
168
|
+
def inject_read_for_pin(pin, message)
|
169
|
+
Thread.new do
|
170
|
+
# Wait for a component to be added.
|
171
|
+
component = false
|
172
|
+
while !component
|
173
|
+
sleep(0.001)
|
174
|
+
component = component_exists_for_pin(pin)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Wait for the component to have a "WAITING_ON_READ" callback.
|
178
|
+
sleep(0.001) while !component.callback_mutex
|
179
|
+
sleep(0.001) while !component.callbacks
|
180
|
+
sleep(0.001) while !waiting_on_read(component)
|
181
|
+
|
182
|
+
# Then inject the message.
|
183
|
+
@read_injection_mutex.synchronize do
|
184
|
+
self.update("#{pin}:#{message}")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Inject a message into the Board instance as if it were coming from the phsyical board.
|
191
|
+
# Use this to mock input data for the blocking #read pattern in the Reader behavior.
|
192
|
+
#
|
193
|
+
def inject_read_for_component(component, pin, message)
|
194
|
+
Thread.new do
|
195
|
+
# Wait for the component to have a "WAITING_ON_READ" callback.
|
196
|
+
sleep(0.001) while !component.callback_mutex
|
197
|
+
sleep(0.001) while !component.callbacks
|
198
|
+
sleep(0.001) while !waiting_on_read(component)
|
199
|
+
|
200
|
+
# Then inject the message.
|
201
|
+
@read_injection_mutex.synchronize do
|
202
|
+
self.update("#{pin}:#{message}")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
module TestPacker
|
209
|
+
def pack(*args, **kwargs)
|
210
|
+
Denko::Message.pack(*args, **kwargs)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Speed up one wire tests.
|
215
|
+
module Denko
|
216
|
+
module OneWire
|
217
|
+
class Bus
|
218
|
+
def sleep(time)
|
219
|
+
super(0.001)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class UARTBitBangTest < MiniTest::Test
|
4
|
+
include TestPacker
|
5
|
+
|
6
|
+
def board
|
7
|
+
@board ||= BoardMock.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def part
|
11
|
+
@part ||= Denko::UART::BitBang.new board: board, pins: { rx: 10, tx: 11 }, baud: 4800
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
mock = MiniTest::Mock.new
|
16
|
+
# Set RX to input
|
17
|
+
mock.expect :call, nil, ["0.10.1\n"]
|
18
|
+
# Start BB UART
|
19
|
+
aux = pack(:uint32, 4800) + pack(:uint8, 0b11000000)
|
20
|
+
mock.expect :call, nil, ["12.11.10.#{aux}\n"]
|
21
|
+
|
22
|
+
board.stub(:write, mock) do
|
23
|
+
part
|
24
|
+
end
|
25
|
+
mock.verify
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_write
|
29
|
+
part
|
30
|
+
mock = MiniTest::Mock.new
|
31
|
+
mock.expect :call, nil, ["13..8.Testing\\\n\n"]
|
32
|
+
board.stub(:write, mock) do
|
33
|
+
part.write("Testing\n")
|
34
|
+
end
|
35
|
+
mock.verify
|
36
|
+
end
|
37
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Example 1: Controlling an LED
|
3
|
+
#
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'denko'
|
6
|
+
|
7
|
+
# If the board is plugged into a USB port, we can connect with serial over USB.
|
8
|
+
connection = Denko::Connection::Serial.new
|
9
|
+
|
10
|
+
# Create a new board object, giving the connection.
|
11
|
+
board = Denko::Board.new(connection)
|
12
|
+
|
13
|
+
#
|
14
|
+
# Create an LED object, giving the board, and the pin that the positive
|
15
|
+
# leg of the LED is connected to. The longer leg is usually positive.
|
16
|
+
#
|
17
|
+
# See led.pdf in this folder for a hook-up diagram.
|
18
|
+
# Use a current limiting resistor with external LEDs to protect them.
|
19
|
+
#
|
20
|
+
# The on-board LED can also be used. It is connected to pin 13 on most Arduinos,
|
21
|
+
# but can vary for other boards. The symbol :LED_BUILTIN should map to the right pin.
|
22
|
+
# If it doesn't, change it to the pin number from your board's documentation.
|
23
|
+
#
|
24
|
+
# Note: Some boards use an addressable LED on-board. In those cases, connect an external
|
25
|
+
# LED and use its pin for this example instead.
|
26
|
+
#
|
27
|
+
led = Denko::LED.new(board: board, pin: :LED_BUILTIN)
|
28
|
+
|
29
|
+
# Now we can make it blink.
|
30
|
+
puts "Blinking every half second..."
|
31
|
+
|
32
|
+
#
|
33
|
+
# A digital output can only have one of two states:
|
34
|
+
# 1 / high / on
|
35
|
+
# 0 / low / off
|
36
|
+
# We can use led.digital_write to set it directly, or named convenience methods.
|
37
|
+
# These 3 lines all do the same thing: turn on, wait half a second, turn off.
|
38
|
+
#
|
39
|
+
led.digital_write(1); sleep 0.5; led.digital_write(0)
|
40
|
+
led.high; sleep 0.5; led.low
|
41
|
+
led.on; sleep 0.5; led.off
|
42
|
+
|
43
|
+
#
|
44
|
+
# led.toggle will set it to the opposite state each time it's called.
|
45
|
+
# Keep it blinking for 3 more seconds using #toggle.
|
46
|
+
#
|
47
|
+
6.times do
|
48
|
+
led.toggle
|
49
|
+
sleep 0.5
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# What if we want to blink in the background?
|
54
|
+
#
|
55
|
+
# led.blink runs in a separate thread, managed by the led, and doesn't block the
|
56
|
+
# main thread. Give it the blink interval in seconds.
|
57
|
+
#
|
58
|
+
led.blink 0.5
|
59
|
+
puts "Blinking in the background... Hello from the main thread!"
|
60
|
+
sleep 3
|
61
|
+
|
62
|
+
#
|
63
|
+
# Calling a method that sets the state (#digital_write, #high, #low, #on, #off)
|
64
|
+
# automatically stops the blink thread.
|
65
|
+
#
|
66
|
+
puts "Turning off for 2 seconds..."
|
67
|
+
led.off
|
68
|
+
sleep 2
|
69
|
+
|
70
|
+
# Blink faster indefinitely.
|
71
|
+
puts "Blinking faster forever... (Press Ctrl+C to exit)"
|
72
|
+
led.blink 0.1
|
73
|
+
sleep
|
Binary file
|
Binary file
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Example 2: Using a Button
|
3
|
+
#
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'denko'
|
6
|
+
|
7
|
+
# Set up the board, connecting with serial over USB.
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
|
10
|
+
#
|
11
|
+
# Create an object for a momentary button, giving the board, and the pin that
|
12
|
+
# the ungrounded side of the button is connected to.
|
13
|
+
#
|
14
|
+
# `pullup: true` tells the board to keep the input pin high (logical 1) when the
|
15
|
+
# button is not pressed. Without this (or an external pullup resistor), the pin
|
16
|
+
# might float between 0 and 1, giving incorrect readings. When the button is
|
17
|
+
# pressed, it pulls the input pin down to ground (0).
|
18
|
+
#
|
19
|
+
# See button.pdf in this folder for a hook-up diagram.
|
20
|
+
#
|
21
|
+
button = Denko::DigitalIO::Button.new(board: board, pin: 7, pullup: true)
|
22
|
+
|
23
|
+
#
|
24
|
+
# As soon as a Button (or any DigitalInput) is created, the board starts
|
25
|
+
# listening for changes to the physical button. When that happens, our button
|
26
|
+
# object is notified. To catch these notifications, we have to use a callback.
|
27
|
+
# button.add_callback saves a block of code to run each time the button state changes.
|
28
|
+
#
|
29
|
+
# The callback below checks if the state is 0 (the button went from up to down),
|
30
|
+
# then counts and prints the number of times pressed.
|
31
|
+
#
|
32
|
+
presses = 0
|
33
|
+
button.add_callback(:count_presses) do |state|
|
34
|
+
if state == 0
|
35
|
+
presses = presses + 1
|
36
|
+
puts "Button press ##{presses}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Wait for the button to be pressed 3 times.
|
41
|
+
sleep 0.005 while presses < 3
|
42
|
+
|
43
|
+
# Button keeps its callbacks in a Hash. We can be specific and use keys to add and remove.
|
44
|
+
button.remove_callback(:count_presses)
|
45
|
+
|
46
|
+
# Or remove them all. Either way, the block above won't run anymore.
|
47
|
+
button.remove_callbacks
|
48
|
+
|
49
|
+
#
|
50
|
+
# button.down and button.up add callbacks that automatically check state for you.
|
51
|
+
#
|
52
|
+
# #down runs only when state goes from high (1) to low (0).
|
53
|
+
# #up runs only when state goes from low (0) to high (1).
|
54
|
+
#
|
55
|
+
# We can use them to control the internal LED from example 1.
|
56
|
+
#
|
57
|
+
led = Denko::LED.new(board: board, pin: 13)
|
58
|
+
|
59
|
+
button.up { led.off }
|
60
|
+
button.down { led.on }
|
61
|
+
|
62
|
+
puts "Press the button to turn on the LED... (Ctrl+C to exit)"
|
63
|
+
|
64
|
+
sleep
|
Binary file
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Example 3: Potentiometer and Analog Inputs
|
3
|
+
#
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'denko'
|
6
|
+
|
7
|
+
# Set up the board, connecting with serial over USB.
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
|
10
|
+
#
|
11
|
+
# Connect the potentiometer's outer 2 pins to Ground and Vcc respectively.
|
12
|
+
# The center is the wiper, and should be connected to one of the board's analog
|
13
|
+
# pins. On most boards these pins start with 'A' and can be given as strings.
|
14
|
+
#
|
15
|
+
# See potentiometer.pdf in this folder for a hook-up diagram.
|
16
|
+
#
|
17
|
+
potentiometer = Denko::AnalogIO::Potentiometer.new(pin: 'A0', board: board)
|
18
|
+
|
19
|
+
#
|
20
|
+
# Like with Button, the Board starts reading the Potentiometer value immediately,
|
21
|
+
# but we need to add a callback to do something with it.
|
22
|
+
#
|
23
|
+
potentiometer.on_change do |value|
|
24
|
+
print "Potentiometer value: #{value} \r"
|
25
|
+
end
|
26
|
+
puts "Turn the potentiometer to change value. Press Enter to continue..."
|
27
|
+
|
28
|
+
# Stop the callback.
|
29
|
+
gets; puts
|
30
|
+
potentiometer.remove_callbacks
|
31
|
+
|
32
|
+
#
|
33
|
+
# The default resolution for Analog Input is 10-bits, so you should have seen
|
34
|
+
# values from 0 - 1023. We can use the value to control the blinking
|
35
|
+
# speed of the LED from the earlier example.
|
36
|
+
#
|
37
|
+
led = Denko::LED.new(board: board, pin: 13)
|
38
|
+
|
39
|
+
# Helper method to calculate the blink time.
|
40
|
+
def map_pot_value(value)
|
41
|
+
# Map 10 bit value into 0 to 1 range.
|
42
|
+
fraction = value / 1023.to_f
|
43
|
+
|
44
|
+
# Linearization hack for audio taper potentiometers.
|
45
|
+
# Adjust k for different tapers. This was an A500K.
|
46
|
+
k = 5
|
47
|
+
linearized = (fraction * (k + 1)) / ((k * fraction) + 1)
|
48
|
+
# Use this for linear potentiometers instead.
|
49
|
+
# linearized = fraction
|
50
|
+
|
51
|
+
# Map to the 0.1 to 0.5 seconds range in reverse. Clockwise = faster.
|
52
|
+
0.5 - (linearized * 0.4)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Callback that calculates the blink interval and tells the LED.
|
56
|
+
potentiometer.on_change do |value|
|
57
|
+
interval = map_pot_value(value)
|
58
|
+
print "LED blink interval: #{interval.round(4)} seconds \r"
|
59
|
+
led.blink(interval)
|
60
|
+
end
|
61
|
+
puts "Turn potentiometer to control the LED blink. Press Ctrl+C to exit..."
|
62
|
+
sleep
|
Binary file
|
Binary file
|