source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | denko-rb/denko | https://github.com/denko-rb/denko | tutorial/05-rgb_led/rgb_led.rb | Ruby | mit | 48 | master | 2,083 | #
# Example 5: RGB LED
#
require 'bundler/setup'
require 'denko'
# Set up the board, connecting with serial over USB
board = Denko::Board.new(Denko::Connection::Serial.new)
#
# To set up an RGB LED, connect its cathode leg to ground, and each of its 3 color
# anodes to PWM-capable pin on your board, through a current... |
github | denko-rb/denko | https://github.com/denko-rb/denko | tutorial/02-button/button.rb | Ruby | mit | 48 | master | 2,123 | #
# Example 2: Using a Button
#
require 'bundler/setup'
require 'denko'
# Set up the board, connecting with serial over USB.
board = Denko::Board.new(Denko::Connection::Serial.new)
#
# Create an object for a momentary button, giving the board, and the pin that
# the ungrounded side of the button is connected to.
#
# ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/test_helper.rb | Ruby | mit | 48 | master | 3,852 | if RUBY_VERSION.split(".").first.to_i > 2
require "minitest/mock"
end
require "minitest/autorun"
DENKO_TEST_SLEEP_TIME = 0.002
if RUBY_ENGINE == "ruby"
require 'simplecov'
SimpleCov.start do
track_files "lib/**/*.rb"
add_filter "test"
add_filter "lib/denko_cli"
end
end
require 'bundler/setup'
req... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/pulse_io/ir_output_test.rb | Ruby | mit | 48 | master | 833 | require_relative '../test_helper'
class IROutPutTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::PulseIO::IROutput.new(board: board, pin:1)
end
def test_does_not_set_pin_mode
refute part.params[:mode]
refute part.mode
end
def test_pulse_count_valid... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/pulse_io/buzzer_test.rb | Ruby | mit | 48 | master | 1,004 | require_relative '../test_helper'
class BuzzerTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::PulseIO::Buzzer.new(board: board, pin:8)
end
def test_low_on_initialize
mock = Minitest::Mock.new.expect :call, [part.pin]
board.stub(:no_tone, mock) do
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/pulse_io/pwm_output_test.rb | Ruby | mit | 48 | master | 3,490 | require_relative '../test_helper'
class PWMOutTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::PulseIO::PWMOutput.new(board: board, pin: 14)
end
def part2
@part2 ||= Denko::PulseIO::PWMOutput.new(board: board, pin: 6, frequency: 1000, resolution: 12)
end
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/display/canvas_test.rb | Ruby | mit | 48 | master | 14,856 | require_relative '../test_helper'
class CanvasTest < Minitest::Test
WIDTH = 32
HEIGHT = 32
FB_LENGTH = (WIDTH * HEIGHT / 8)
def subject
@subject ||= Denko::Display::Canvas.new(WIDTH, HEIGHT, colors: 2)
end
def test_framebuffer_default_state
assert_equal 2, subject.framebuffers.length
a... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/display/hd44780_test.rb | Ruby | mit | 48 | master | 2,014 | require_relative '../test_helper'
class HD44780Test < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::Display::HD44780.new cols: 16, rows: 2,
board: board,
pins: {
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/uart/bitbang_test.rb | Ruby | mit | 48 | master | 773 | require_relative '../test_helper'
class UARTBitBangTest < Minitest::Test
include TestPacker
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::UART::BitBang.new board: board, pins: { rx: 10, tx: 11 }, baud: 4800
end
def test_initialize
mock = Minitest::Mock.new
# Set RX to ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/one_wire/peripheral_test.rb | Ruby | mit | 48 | master | 3,905 | require_relative '../test_helper'
class OneWirePeripheralTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
return @bus if @bus
# Respond with disabled parasite power.
board.inject_read_for_pin(1, "1")
@bus ||= Denko::OneWire::Bus.new(board: board, pin: 1)
end
def part... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/one_wire/bus_enumerator_test.rb | Ruby | mit | 48 | master | 3,389 | require_relative '../test_helper'
# State machine simulating a bus during address search. Initialize with
# n devices with random addresses. Call #reset before each search.
class BusSimulator
def initialize(device_count)
@devices = []
device_count.times do
rando = rand(2**56)
crc = Denko::OneWire... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/one_wire/helper_test.rb | Ruby | mit | 48 | master | 544 | require_relative '../test_helper'
class OneWireHelper < Minitest::Test
def test_with_valid_crc
assert Denko::OneWire::Helper.crc(18086456125349333800)
assert Denko::OneWire::Helper.crc([121, 117, 144, 185, 6, 165, 43, 26])
end
def test_with_invalid_crc
refute Denko::OneWire::Helper.crc(18086456... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/one_wire/bus_test.rb | Ruby | mit | 48 | master | 3,869 | require_relative '../test_helper'
class OneWireBusTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
return @part if @part
# Respond with disabled parasite power.
board.inject_read_for_pin(1, "1")
@part ||= Denko::OneWire::Bus.new(board: board, pin: 1)
end
def test_in... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/motor/servo_test.rb | Ruby | mit | 48 | master | 1,493 | require_relative '../test_helper'
class ServoMotorTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::Motor::Servo.new(board: board, pin:1, min: 0, max: 360)
end
def test_toggle_on_initialize
mock = Minitest::Mock.new.expect(:call, nil, [1, :on], min: 500, max... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/motor/a3967_test.rb | Ruby | mit | 48 | master | 1,181 | require_relative '../test_helper'
class A3967MotorTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::Motor::A3967.new board: board,
pins: {step: 9, direction: 10}
end
def test_initialize
assert_equal Denko::DigitalI... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/rtc/ds3231_test.rb | Ruby | mit | 48 | master | 967 | require_relative '../test_helper'
class DS3231Test < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::I2C::Bus.new(board: board)
end
def part
@part ||= Denko::RTC::DS3231.new(bus: bus)
end
def test_time_to_bcd
time = Time.new(2000, 1, 1, 0, 0, 0.0)
byte... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/i2c/bus_test.rb | Ruby | mit | 48 | master | 3,840 | require_relative '../test_helper'
class I2CPeripheralBase
include Denko::I2C::Peripheral
end
class I2CBusTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::I2C::Bus.new(board: board)
end
def peripheral
@peripheral ||= I2CPeripheralBase.new(bus: bus, address:... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/i2c/peripheral_test.rb | Ruby | mit | 48 | master | 1,774 | require_relative '../test_helper'
class I2CPeripheralBase
include Denko::I2C::Peripheral
I2C_ADDRESS = 0x30
I2C_FREQUENCY = 400_000
I2C_REPEATED_START = true
end
class I2CPeripheralTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::I2C::Bus.new(boar... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/one_wire_test.rb | Ruby | mit | 48 | master | 2,086 | require_relative '../test_helper'
class APIOneWireTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_one_wire_reset
board
message = Denko::Message.encode command: 41, pin: 1, value:... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/infrared_test.rb | Ruby | mit | 48 | master | 837 | require_relative '../test_helper'
class APIInfraredTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_infrared_emit
board
aux = pack(:uint16, 4) + pack(:uint16, [255,0,255,0])
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/tone_test.rb | Ruby | mit | 48 | master | 1,015 | require_relative '../test_helper'
class APIToneTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_tone
mock = Minitest::Mock.new
aux1 = pack(:uint16, 150) + pack(:uint16, 2000)
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/helper_test.rb | Ruby | mit | 48 | master | 806 | # encoding: ascii-8bit
# For convenience when validating longer data types.
require_relative '../test_helper'
class APIHelperTest < Minitest::Test
include TestPacker
def test_single_integers
assert_equal pack(:uint8, 25), "\x19"
end
def test_other_formats
assert_equal pack(:uint16, 5*10**4), "P\x... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/core_test.rb | Ruby | mit | 48 | master | 5,989 | require_relative '../test_helper'
class BoardCoreTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_set_pin_mode
mock = Minitest::Mock.new
mock.expect(:call, nil, [Denko::Message.en... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/pulse_test.rb | Ruby | mit | 48 | master | 1,905 | require_relative '../test_helper'
class BoardPulseTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_pulse_read
# Default settings
mock = Minitest::Mock.new
aux = pack(:uint16, ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/eeprom_test.rb | Ruby | mit | 48 | master | 797 | require_relative '../test_helper'
class BoardEEPROMTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_eeprom_read
mock = Minitest::Mock.new
mock.expect :call, nil, [(Denko::Message.... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/i2c_test.rb | Ruby | mit | 48 | master | 3,490 | require_relative '../test_helper'
class APII2CTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_search
board
message = Denko::Message.encode command: 33
mock = Minitest::Mock.... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/message_test.rb | Ruby | mit | 48 | master | 2,558 | require_relative '../test_helper'
class MessageTest < Minitest::Test
def test_require_a_command
assert_raises(ArgumentError) { Denko::Message.encode }
assert_instance_of String, Denko::Message.encode(command: 90)
end
def test_require_command_in_correct_range
assert_raises(ArgumentError) { Denko::Mes... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/servo_test.rb | Ruby | mit | 48 | master | 1,190 | require_relative '../test_helper'
class APIServoTest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_on_off
mock = Minitest::Mock.new
aux = pack :uint16, [544, 2400]
mock.expect... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/board_test.rb | Ruby | mit | 48 | master | 3,617 | require_relative '../test_helper'
class BoardTest < Minitest::Test
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def test_require_a_connection_object
assert_raises(Exception) { Denko::Board.new }
end
def test_starts_observing_co... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/board/spi_test.rb | Ruby | mit | 48 | master | 3,305 | # encoding: ascii-8bit
# For convenience when validating longer data types.
require_relative '../test_helper'
class APISPITest < Minitest::Test
include TestPacker
def connection
@connection ||= ConnectionMock.new
end
def board
@board ||= Denko::Board.new(connection)
end
def header_args
leng... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/analog_io/output_test.rb | Ruby | mit | 48 | master | 489 | require_relative '../test_helper'
class AnalogIOOutputTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::AnalogIO::Output.new(board: board, pin: 14)
end
def test_mode_set
assert_equal :output_dac, part.mode
end
def test_dac_write
mock = Minitest:... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/analog_io/input_test.rb | Ruby | mit | 48 | master | 835 | require_relative '../test_helper'
class AnalogIOInputTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::AnalogIO::Input.new(board: board, pin: 14)
end
def test_read
board.inject_component_update(part, 128)
mock = Minitest::Mock.new.expect :call, nil, [14,... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/analog_io/potentiometer_test.rb | Ruby | mit | 48 | master | 1,175 | require_relative '../test_helper'
class AnalogIOPotentiometerTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::AnalogIO::Potentiometer.new(board: board, pin:14)
end
def test_setup
mock = Minitest::Mock.new.expect(:call, nil, [14,8])
board.stub(:analog_li... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/sensor/dht_test.rb | Ruby | mit | 48 | master | 2,241 | require_relative '../test_helper'
class DHTTest < Minitest::Test
PIN = 1
# Actual raw data from a sensor
GOOD_STRING = "14,82,77,57,26,52,26,57,26,51,32,51,26,57,26,52,72,57,26,67,72,57,26,51,27,56,72,52,77,52,77,51,26,57,72,67,26,52,26,57,26,52,26,57,26,51,31,52,26,57,72,67,26,52,26,56,72,57,26,52,26,57,72,52... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/sensor/ds18b20_test.rb | Ruby | mit | 48 | master | 3,205 | require_relative '../test_helper'
class DS18B20Test < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
return @bus if @bus
# Respond with disabled parasite power.
board.inject_read_for_pin(1, "1")
@bus ||= Denko::OneWire::Bus.new(board: board, pin: 1)
end
def part
@part... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/led/base_test.rb | Ruby | mit | 48 | master | 559 | require_relative '../test_helper'
class BaseLEDTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::LED::Base.new(board: board, pin:1)
end
def test_led_new_creates_base_led
part = Denko::LED.new(board: board, pin:2)
assert_equal Denko::LED::Base, part.class... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/led/apa102_test.rb | Ruby | mit | 48 | master | 378 | require_relative '../test_helper'
class APA102Test < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::SPI::Bus.new(board: board)
end
def options
{ bus: bus }
end
def part
@part ||= Denko::LED::APA102.new(options)
end
def test_added_to_bus_components
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/led/rgb_test.rb | Ruby | mit | 48 | master | 1,419 | require_relative '../test_helper'
class RGBLEDTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def options
{ board: board, pins: { red: 1, green: 2, blue: 3 } }
end
def part
@part ||= Denko::LED::RGB.new(options)
end
def test_proxies
assert_equal Denko::LED::Base, part.red.... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/led/seven_segment_test.rb | Ruby | mit | 48 | master | 2,602 | require_relative '../test_helper'
class SevenSegmentLEDTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def options
{ board: board,
pins: {anode: 11, a: 12, b: 13, c: 3, d: 4, e: 5, f: 10, g: 9} }
end
def part
@part ||= Denko::LED::SevenSegment.new(options)
end
def test_p... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/helpers/mruby_runner.rb | Ruby | mit | 48 | master | 368 | # Stub out require_relative to avoid issues.
def require_relative(*args)
end
# Load minimal Minitest clone for mruby.
minitest_source = "#{File.dirname(__FILE__)}/mruby_minitest.rb"
eval(File.read(minitest_source))
# Test Display::Canvas.
canvas_test = "#{File.dirname(__FILE__)}/../display/canvas_test.rb"
eval(File.r... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/helpers/mruby_minitest.rb | Ruby | mit | 48 | master | 2,624 | # Minimal implementation of Minitest for mruby.
# Only handles #assert, #refute, and #assert_equal.
module Minitest
class AssertionError < StandardError
end
class Test
@@test_count = 0
@@failures = []
@@errors = []
@@assertions = 0
def self.run_all_tests
@@start_time = Time.now
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/digital_io/rotary_encoder_test.rb | Ruby | mit | 48 | master | 3,207 | require_relative '../test_helper'
class RotaryEncoderTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::DigitalIO::RotaryEncoder.new board: board, pins: {b: 3, a: 4}
end
def test_alternate_pin_names
short = Denko::DigitalIO::RotaryEncoder.new board: board, pi... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/digital_io/relay_test.rb | Ruby | mit | 48 | master | 342 | require_relative '../test_helper'
class DigitalIORelaynTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def relay
@relay ||= Denko::DigitalIO::Relay.new(board: board, pin: 14)
end
def test_open_and_close
relay.close
assert_equal 1, relay.state
relay.open
assert_equal 0, ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/digital_io/button_test.rb | Ruby | mit | 48 | master | 286 | require_relative '../test_helper'
class DigitalIOButtonTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::DigitalIO::Button.new(board: board, pin: 14)
end
def test_divider_set_correctly
assert_equal 1, part.divider
end
end |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/digital_io/output_test.rb | Ruby | mit | 48 | master | 1,403 | require_relative '../test_helper'
class DigitalIOOutputTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::DigitalIO::Output.new(board: board, pin: 14)
end
def test_read_state_on_initialize
mock = Minitest::Mock.new.expect :call, nil, [14]
board.stub(:digi... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/digital_io/input_test.rb | Ruby | mit | 48 | master | 1,413 | require_relative '../test_helper'
class DigitalIOInputTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= Denko::DigitalIO::Input.new(board: board, pin: 14)
end
def test_start_listening_immediately
mock = Minitest::Mock.new.expect :call, nil, [14, 4]
board.stub(:... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/eeprom/board_test.rb | Ruby | mit | 48 | master | 988 | require_relative '../test_helper'
class BoardMock < Denko::Board
# Fake EEPROM
def eeprom_stub
@eeprom_stub ||= Array.new(eeprom_length){255}
end
def eeprom_read(start_address, length)
# Pack it up like a string coming from the board and update.
string = eeprom_stub[start_address, length].map{ |x|... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/connection/tcp_test.rb | Ruby | mit | 48 | master | 911 | require_relative '../test_helper'
class TCPConnectionTest < Minitest::Test
# Force autoload.
Denko::Connection::TCP
def test_connect_raises_if_server_unavailable
assert_raises(Denko::Connection::TCPConnectError) do
suppress_output do
io = Denko::Connection::TCP.new("127.0.0.1", 3466).send(:io)... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/connection/serial_test.rb | Ruby | mit | 48 | master | 4,923 | require_relative '../test_helper'
require "rubyserial"
class SerialConnectionTest < Minitest::Test
def mock_tty_device
"/dev/mock_serial"
end
def connection
@connection ||= Denko::Connection::Serial.new
end
def io
suppress_output do
connection.send(:io)
end
end
def test_connec... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/spi/input_register_test.rb | Ruby | mit | 48 | master | 3,463 | require_relative '../test_helper'
class InputRegisterTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::SPI::Bus.new(board: board)
end
def options
{ bus: bus, pin: 9, bytes: 2, spi_frequency: 800000, spi_mode: 2, spi_bit_order: :lsbfirst}
end
def part
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/spi/bitbang_test.rb | Ruby | mit | 48 | master | 649 | require_relative '../test_helper'
class TempSpiPeripheral
include Denko::SPI::Peripheral
end
class SPIBitBangTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@bus ||= Denko::SPI::BitBang.new(board: board, pins: {mosi: 4, miso: 5, clock: 6})
end
def test_no_miso
no_miso =... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/spi/bus_test.rb | Ruby | mit | 48 | master | 1,820 | require_relative '../test_helper'
class TempSpiPeripheral
include Denko::SPI::Peripheral
end
class SPIBusTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@bus ||= Denko::SPI::Bus.new(board: board, index: 5)
end
PIN = 9
OPTIONS = { read: 2, frequency: 800000, mode: 2, bit_o... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/spi/output_register_test.rb | Ruby | mit | 48 | master | 1,442 | require_relative '../test_helper'
class OutputRegisterTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def bus
@bus ||= Denko::SPI::Bus.new(board: board)
end
def options
{ bus: bus, pin: 9, bytes: 2, spi_frequency: 800000, spi_mode: 2, spi_bit_order: :lsbfirst }
end
def part
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/spi/peripheral_test.rb | Ruby | mit | 48 | master | 1,542 | require_relative '../test_helper'
class SPITester
include Denko::SPI::Peripheral
def initialize_pins
super
proxy_pin :other_pin, Denko::DigitalIO::Output
end
def some_callback(data)
end
end
class SPITesterSingle
include Denko::SPI::Peripheral
end
class SPIPeripheralTest < Minitest::Test
def b... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/component_test.rb | Ruby | mit | 48 | master | 876 | require_relative '../test_helper'
class BaseComponent
include Denko::Behaviors::Component
end
class ComponentTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= BaseComponent.new(board: board)
end
def test_requires_board
assert_raises(ArgumentError) { BaseComponen... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/multi_pin_test.rb | Ruby | mit | 48 | master | 2,218 | require_relative '../test_helper'
class MultiPinComponent
include Denko::Behaviors::MultiPin
def initialize_pins
require_pin :one
proxy_pin :two, Denko::DigitalIO::Output
proxy_pin :maybe, Denko::DigitalIO::Input, optional: true
proxy_pin :other_board, Denko::DigitalIO::Output... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/input_pin_test.rb | Ruby | mit | 48 | master | 1,054 | require_relative '../test_helper'
class InputComponent
include Denko::Behaviors::InputPin
end
class InputPinTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= InputComponent.new(board: board, pin: 1)
end
def test_mode_and_pullup
modes = [:input, :input_pulldown, ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/bus_controller_test.rb | Ruby | mit | 48 | master | 549 | require_relative '../test_helper'
class NoAddressController
include Denko::Behaviors::Component
include Denko::Behaviors::BusController
end
class BusControllerTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= NoAddressController.new(board: board)
end
def test_ha... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/lifecycle_test.rb | Ruby | mit | 48 | master | 3,837 | require_relative '../test_helper'
class Parent
include Denko::Behaviors::Component
include Denko::Behaviors::Lifecycle
attr_reader :before_flag, :after_flag, :before_order, :after_order
BEFORE_CALLBACK = proc {
@before_flag = true
@before_order ||= []
@before_order << :parent_before
}
AFTER_C... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/listener_test.rb | Ruby | mit | 48 | master | 1,319 | require_relative '../test_helper'
class ListenerComponent
include Denko::Behaviors::Component
include Denko::Behaviors::Listener
def _listen(divider=nil); end
def _stop_listener; end
end
class ListenerTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= ListenerCompo... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/single_pin_test.rb | Ruby | mit | 48 | master | 912 | require_relative '../test_helper'
class SinglePinComponent
include Denko::Behaviors::SinglePin
end
class SinglePinTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= SinglePinComponent.new(board: board, pin: 1)
end
def test_requires_pin
assert_raises(ArgumentError... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/threaded_test.rb | Ruby | mit | 48 | master | 2,483 | require_relative '../test_helper'
class ThreadedComponent
include Denko::Behaviors::Component
include Denko::Behaviors::Threaded
def foo(str="test")
@bar = str
end
attr_reader :bar
interrupt_with :foo
end
class ThreadedTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/subcomponents_test.rb | Ruby | mit | 48 | master | 2,198 | require_relative '../test_helper'
class PinlessComponentMock
def stop
end
end
class SinglePinComponentMock
def pin
1
end
end
class MultiPinComponentMock
def pin
{a: 1, b: 2}
end
end
class SubcomponentsTest < Minitest::Test
def connection
@connection ||= ConnectionMock.new
end
def boar... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/output_pin_test.rb | Ruby | mit | 48 | master | 755 | require_relative '../test_helper'
class OutputComponent
include Denko::Behaviors::OutputPin
end
class OutputPinTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def test_set_mode
modes = [:output, :output_pwm, :output_dac, :output_open_drain, :output_open_source]
mock = Minitest::Mock... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/poller_test.rb | Ruby | mit | 48 | master | 1,541 | require_relative '../test_helper'
class PollerComponent
include Denko::Behaviors::Component
include Denko::Behaviors::Poller
def _read; end
end
class PollerTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= PollerComponent.new(board: board, pin: 1)
end
def inject... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/bus_controller_addressed_test.rb | Ruby | mit | 48 | master | 896 | require_relative '../test_helper'
class AddressedBus
include Denko::Behaviors::Component
include Denko::Behaviors::BusControllerAddressed
end
class AddressedPeripheral
include Denko::Behaviors::Component
include Denko::Behaviors::BusPeripheralAddressed
end
class BusControllerAddressedTest < Minitest::Test
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/reader_test.rb | Ruby | mit | 48 | master | 1,382 | require_relative '../test_helper'
class ReaderComponent
include Denko::Behaviors::Component
include Denko::Behaviors::Reader
def _read; end
end
class ReaderTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= ReaderComponent.new(board: board, pin: 1)
end
def test_i... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/state_test.rb | Ruby | mit | 48 | master | 961 | require_relative '../test_helper'
class StateComponent
include Denko::Behaviors::State
include Denko::Behaviors::Component
end
class StateTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def component
@component ||= StateComponent.new(board: board)
end
def test_state_is_nil_by_defa... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/board_proxy_test.rb | Ruby | mit | 48 | master | 664 | require_relative '../test_helper'
class ProxiedComponent
include Denko::Behaviors::Component
include Denko::Behaviors::BoardProxy
def analog_read_high; end
def analog_write_high; end
end
class BoardProxyTest < Minitest::Test
def board
@board ||= BoardMock.new
end
def part
@part ||= ProxiedComp... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/callbacks_test.rb | Ruby | mit | 48 | master | 2,567 | require_relative '../test_helper'
class CallbackComponent
include Denko::Behaviors::Component
include Denko::Behaviors::Callbacks
def pre_callback_filter(data)
"denko: #{data}"
end
end
class CallbackComponentNilFilter
include Denko::Behaviors::Component
include Denko::Behaviors::Callbacks
def pre_... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/bus_peripheral_addressed_test.rb | Ruby | mit | 48 | master | 945 | require_relative '../test_helper'
class AddressedBus
include Denko::Behaviors::Component
include Denko::Behaviors::BusControllerAddressed
end
class AddressedPeripheral
include Denko::Behaviors::Component
include Denko::Behaviors::BusPeripheralAddressed
end
class BusPeripheralAddressedTest < Minitest::Test
... |
github | denko-rb/denko | https://github.com/denko-rb/denko | test/behaviors/bus_peripheral_test.rb | Ruby | mit | 48 | master | 775 | require_relative '../test_helper'
class NoAddressController
include Denko::Behaviors::Component
include Denko::Behaviors::BusController
end
class NoAddressPeripheral
include Denko::Behaviors::Component
include Denko::Behaviors::BusPeripheral
end
class BusPeripheralTest < Minitest::Test
def board
@board... |
github | denko-rb/denko | https://github.com/denko-rb/denko | benchmarks/digital_write.rb | Ruby | mit | 48 | master | 651 | #
# Benchmark digital write throughput for a Denko::Board instance.
#
require 'bundler/setup'
require 'denko'
# Pins > 63 will not benefit from the single-byte message optimization.
PIN = 4
TOTAL_WRITES = 200_000
connection = Denko::Connection::Serial.new
board = Denko::Board.new(connection)
output ... |
github | denko-rb/denko | https://github.com/denko-rb/denko | benchmarks/analog_listen.rb | Ruby | mit | 48 | master | 1,290 | #
# Find how much analog listen throughput is available from a Board.
#
# To find the limit, add more pins and/or reduce the divider until
# the rate per input pin can't meet the target.
# Example: Rate per input pin is < 500 Hz when divider is 2 ms.
#
require 'bundler/setup'
require 'denko'
# In seconds
TEST_TIME =... |
github | denko-rb/denko | https://github.com/denko-rb/denko | benchmarks/i2c_ssd1306_refresh.rb | Ruby | mit | 48 | master | 3,476 | #
# Repeatedly writes filled and empty frames to the OLED
# Calculates frames per second. Higher is better.
#
# RESULTS:
# July 6 2023 | i7 8700k CPU | CRuby 3.2.1 | 100 frames | 1 Mhz I2C frequency | Average of 3 runs
#
# Arduino Uno R3 : 5.3 fps (ATmega16u2 UART bridge @ 115200, no I2C level shifter)
# Ardu... |
github | SidOfc/cani | https://github.com/SidOfc/cani | cani.gemspec | Ruby | mit | 48 | master | 1,317 | lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cani/version'
Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.1'
spec.name = 'cani'
spec.version = Cani::VERSION
spec.authors = ['Sidney L... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani.rb | Ruby | mit | 48 | master | 6,952 | # frozen_string_literal: true
require 'io/console'
require 'fileutils'
require 'curses'
require 'colorize'
require 'json'
require 'yaml'
require 'tty-screen'
require 'cani/api'
require 'cani/fzf'
require 'cani/config'
require 'cani/version'
require 'cani/completions'
# Cani
module Cani
def self.api
@api ||= Ap... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/api.rb | Ruby | mit | 48 | master | 2,669 | require 'net/http'
require_relative 'api/browser'
require_relative 'api/feature'
require_relative 'api/feature/viewer'
module Cani
class Api
def initialize
@data = load_data
end
def load_data(fetch: false)
@upd = false
data_file = File.join Cani.config.directory, 'caniuse.json'
... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/config.rb | Ruby | mit | 48 | master | 5,175 | module Cani
class Config
attr_reader :settings, :modify_shell_configs
FILE = File.join(Dir.home, '.config', 'cani', 'config.yml').freeze
DIRECTORY = File.dirname(FILE).freeze
COMP_DIR = File.join(DIRECTORY, 'completions').freeze
FISH_DIR = File.join(Dir.home, '.config',... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/completions.rb | Ruby | mit | 48 | master | 4,458 | module Cani
module Completions
def self.generate_fish
gem_root = File.join File.dirname(__FILE__), '../../'
tpl = File.read File.join(gem_root, 'shell/completions/functions.fish')
shw = Cani.api.browsers.reduce String.new do |acc, browser|
versions = browser.versions.reverse.join('... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/fzf.rb | Ruby | mit | 48 | master | 3,708 | module Cani
module Fzf
def self.pick(rows, **opts)
if STDOUT.tty?
unless executable?
puts 'Cani fatal: command "fzf" not found, is it installed?'
exit 1
end
rows = tableize_rows(rows, **opts).join "\n"
ohdr = opts.fetch :header, []
query = "-... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/api/feature.rb | Ruby | mit | 48 | master | 2,412 | module Cani
class Api
class Feature
attr_reader :title, :status, :spec, :stats, :percent, :name, :browser_note_nums, :notes, :notes_by_num, :description
STATUSES = {
'rec' => 'rc',
'unoff' => 'un',
'other' => 'ot'
}.freeze
TYPES = {
'y' => { symbol: '+', n... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/api/browser.rb | Ruby | mit | 48 | master | 2,178 | module Cani
class Api
class Browser
attr_reader :name, :title, :prefix, :type, :versions, :usage, :abbr, :label, :eras
ABBR_MAP = { 'ios' => 'saf.ios' }.freeze
LABEL_MAP = {
'ie' => 'Internet Explorer',
'edge' => 'Edge',
'ff' => 'Firefox',
'chr' => 'Chrome',
... |
github | SidOfc/cani | https://github.com/SidOfc/cani | lib/cani/api/feature/viewer.rb | Ruby | mit | 48 | master | 16,813 | module Cani
class Api
class Feature
class Viewer
attr_reader :width, :height, :feature, :browsers, :viewable,
:col_width, :table_width
COLOR_PAIRS = {
# foreground colors
# green on default
# (legend supported, feature status, percentage co... |
github | SidOfc/cani | https://github.com/SidOfc/cani | spec/spec_helper.rb | Ruby | mit | 48 | master | 360 | require "bundler/setup"
require "cani"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec ... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | convert2ascii.gemspec | Ruby | mit | 48 | main | 1,745 | # frozen_string_literal: true
require_relative "lib/convert2ascii/version"
Gem::Specification.new do |spec|
spec.name = "convert2ascii"
spec.version = Convert2Ascii::VERSION
spec.authors = ["Mark24"]
spec.email = ["mark.zhangyoung@gmail.com"]
spec.summary = "Convert image or video to ASCII art"
spec.desc... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | Rakefile | Ruby | mit | 48 | main | 640 | # frozen_string_literal: true
require "bundler/gem_tasks"
desc "Run Test"
task :test do
tests = Dir.glob("./test/test_*.rb")
tests.each do |t|
system("ruby #{t}")
end
end
desc "Build Rdoc"
task :build_rdoc do
system("rdoc build")
end
desc "Build Docker image"
task :build_docker do
system("docker build ... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | test/test_02_video2ascii.rb | Ruby | mit | 48 | main | 815 | require "minitest/autorun"
require_relative '../lib/convert2ascii/video2ascii'
class TestDefaultParams < Minitest::Test
def setup
@width = 20
@fake_uri = "./test/assets/fireworks.mp4"
@generator = Convert2Ascii::Video2Ascii.new(uri: @fake_uri, width: @width)
end
def test_initialize_params_width
... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | test/test_03_video2ascii_play.rb | Ruby | mit | 48 | main | 423 | require "minitest/autorun"
require_relative '../lib/convert2ascii/video2ascii'
class Video2AsciiPlay < Minitest::Test
def setup
@width = 20
@fake_uri = "./test/assets/fireworks.mp4"
@generator = Convert2Ascii::Video2Ascii.new(uri:@fake_uri, width: @width)
end
def test_video_play
@generator.gener... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | test/test_01_image2ascii.rb | Ruby | mit | 48 | main | 1,640 | require "minitest/autorun"
require_relative '../lib/convert2ascii/image2ascii'
class TestDefaultParams < Minitest::Test
def setup
@width = 20
@fake_uri = "./test/assets/ruby.jpg"
@generator = Convert2Ascii::Image2Ascii.new(uri:@fake_uri, width: @width)
end
def test_initialize_params
assert_equal... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/terminal.rb | Ruby | mit | 48 | main | 703 | require "io/console"
# ANSI_escape_code
# Ref: https://xn--rpa.cc/irl/term.html
# https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection
module Convert2Ascii
class Terminal
class << self
def winsize
IO.console.winsize # [rows, columns]
end
def clear_buffer
print "\x1b[3J"
... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/multi-tasker.rb | Ruby | mit | 48 | main | 888 | require "parallel"
require "etc"
require "rainbow"
module Convert2Ascii
class MultiTasker
def initialize(proc_tasks)
@proc_tasks = proc_tasks
@count = set_threads_count
@finished = []
@time_start = nil
end
def set_threads_count
cpu_threads = (Etc.nprocessors || 1)
cpu... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/video2ascii.rb | Ruby | mit | 48 | main | 5,168 | require "open-uri"
require "json"
require "tmpdir"
require "etc"
require "io/console"
require "rainbow"
require_relative "./image2ascii"
require_relative "./terminal-player"
require_relative "./multi-tasker"
require_relative "./check_package"
require_relative "./version"
module Convert2Ascii
class Video2AsciiError <... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/check_package.rb | Ruby | mit | 48 | main | 3,655 | require 'rainbow'
module Convert2Ascii
module OS
module OS_ENUM
MacOS = :macos
Linux = :linux
Windows = :ms
Unknow = :unknow
end
def detect_os
if RUBY_PLATFORM =~ /linux/
return OS_ENUM::Linux
elsif RUBY_PLATFORM =~ /darwin/
return OS_ENUM::MacOS
... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/terminal-player.rb | Ruby | mit | 48 | main | 4,673 | require "rainbow"
require_relative "./terminal"
module Convert2Ascii
class TerminalPlayerError < StandardError
end
class TerminalPlayer
SAFE_SLOW_DELTA = 0.9 # seconds
SAFE_FAST_DELTA = 0.2 # seconds
attr_accessor :play_loop, :step_duration, :debug
def initialize(**args)
@debug = false
... |
github | Mark24Code/convert2ascii | https://github.com/Mark24Code/convert2ascii | lib/convert2ascii/image2ascii.rb | Ruby | mit | 48 | main | 3,507 | require "io/console"
require "rmagick"
require "rainbow"
require "open-uri"
require_relative "./check_package"
require_relative './version'
module Convert2Ascii
class Image2AsciiError < StandardError
end
class Image2Ascii
module STYLE_ENUM
Color = "color"
Text = "text"
end
module COLOR_... |
github | osunyorg/admin | https://github.com/osunyorg/admin | Gemfile | Ruby | mit | 48 | main | 3,553 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "4.0.2"
gem "activestorage-scaleway-service"#, path: "../activestorage-scaleway-service"
gem "active_hashcash"
gem "active_storage_validations", "~> 1"
gem "add_to_calendar"
gem "aws-sdk-s3"
gem "bootstrap"
gem "bootsna... |
github | osunyorg/admin | https://github.com/osunyorg/admin | test/test_helper.rb | Ruby | mit | 48 | main | 1,880 | require 'simplecov'
require 'simplecov_json_formatter'
SimpleCov.start 'rails' do
formatter SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::HTMLFormatter
])
end
ENV['RAILS_ENV'] ||= 'test'
require_relative "../config/environment"
require "rails/test_he... |
github | osunyorg/admin | https://github.com/osunyorg/admin | test/mailers/previews/extranet_mailer_preview.rb | Ruby | mit | 48 | main | 315 | # Preview all emails at http://localhost:3000/rails/mailers/extranet_mailer
class ExtranetMailerPreview < BaseMailerPreview
# Preview this email at http://localhost:3000/rails/mailers/extranet_mailer/invitation_message
def invitation_message
ExtranetMailer.invitation_message(extranet, person)
end
end |
github | osunyorg/admin | https://github.com/osunyorg/admin | test/mailers/previews/base_mailer_preview.rb | Ruby | mit | 48 | main | 3,659 | class BaseMailerPreview < ActionMailer::Preview
def self.call(email, params = {})
message = nil
ActiveRecord::Base.transaction do
message = super(email, params)
raise ActiveRecord::Rollback
end
message
end
protected
def university
@university ||= University.create!(
name... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.