-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dino 0.12.0 #34
Dino 0.12.0 #34
Conversation
Awesome pull request, I'd love to see this merged, so I can adapt my LCD implementation to this |
@supherman I was just about to suggest that. You can branch off
|
I'm in for a chat discussion or something like that, I'm not an expert with arduino, but I'd like to see the progress in this project |
I opened irc room on freenode.net calls #dino-rb because looks like #dino is reserved. You can use online irc client: http://webchat.freenode.net/ or irssi. |
@supherman You should be able to just drop in your code from #39 now and it'll work. Couple changes I made:
And the CLI includes the |
Switched from serialport to rubyserial
DS18B20 (Dallas Temperature Sensor) Support
…'s being enumerated
Shift register modelling
# Conflicts: # src/lib/Dino.cpp # src/lib/DinoSPI.cpp
…yte order. Switched default order back to LSBFIRST to match output registers, since. Using MSBFIRST just hid the bug.
Bit order was reversed for these, like input registers, but byte order was also wrong. MS byte always first now.
This should finally be correct. MSBFIRST per byte, but LSBYTE FIRST
@austinbv this feels pretty solid now. I made a 0.11.x release branch from current master. Going to merge this into master and make a 0.12.x release branch. Trunk-based going forward. Can we release on RubyGems? |
New Boards
The
dino sketch
shell command now accepts a--target
argument. It includes/excludes features to tailor the sketch for different boards/chips. Rundino targets
for more info.ATmega Based Boards (default) (
--target mega
):--target
isn't specified, and works for Arduino (and other) products based on the ATmega AVR chips, like the Uno, Nano, Leonardo and Mega.ESP8266 (
--target esp8266
):ESP32 (
--target esp32
):LEDC
channels on the board. Maximum of 16 combined.Arduino Due (
--target sam3x
) :bits:
option toBoard#new
to set resolution for both.'DAC0'
,'DAC1'
, just as labeled on the board. Call#analog_write
or just#write
on anAnalogOutput
component that uses the pin.ATmega168 (
--target mega168
):DinoDefines.h
to suit your needs.New Components
TxRx::TCP
allows communication with the board over an IP network, instead of serial connection. Tested on Arduino Uno Ethernet Shield (Wiznet W5100), and ESP8266 native WiFi. Should work on Uno WiFi shield, but is untested. WiFi must be configured before flashing. Instad ofdino sketch serial
, usedino sketch wifi
.Hitachi HD44780 LCD support. Uses Arduino
LiquidCrystal
library.Seven Segment Display support. Ruby implementation as multiple LEDs.
Infrared Emitter support. Uses Arduino-IRremote, and the ESP8266 fork where applicable.
Tone (piezo) support. Uses Arduino
tone
,noTone
functions.SoftwareSerial (write only). Uses Arduino
SoftSerial
library. Only tested on ATmega chips.Potentiometer class, based on AnalogInput, but enables moving average smoothing by default, and adds #on_change callback method.
Rotary encoder support. Polls @ 1ms interval. WARNING: Not suitable for high speed or precise position needs. It will definitely miss steps. Sufficient for rotary knobs as user input.
DHT11 / DHT 21 (AM2301) / DHT22 temperature and relative humidity sensor support. Custom implementation where input pulses are measured on the board, then decoded in Ruby.
DS3231 RTC (real time clock) over I2C (Ruby implementation)
DS18B20 temperature sensor. Uses custom implementation of Dallas/Maxim 1-Wire bus below.
Dallas/Maxim 1-Wire bus support. Low level timing functions run on the board. High level logic in Ruby.
I2C bus support. Uses Arduino
Wire
library.Shift Register support. Uses Arduino
ShiftOut
andShiftIn
functions.SPI bus support (uses Arduino
SPI
library) :Generic input and output register classes for the above 2:
Register::ShiftIn
,Register::ShiftOut
,Register::SPIIn
,Register::SPIOut
.Board EEPROM support. Uses Arduino
EEPROM
library.Changed Components
Servos can now be connected to arbitrary pins as long as they are supported by the board.
Digital and analog listeners now have dividers on a per-pin basis.
#listen
with a value as the first argument. Eg.analog_sensor.listen(64)
will tell the board to send us that specific sensor's state every 64 ticks (~64ms) or around 16 times per second, without affecting other components' rates.1, 2, 4, 8, 16, 32, 64, 128
.4
for digital,16
for analog.Hardware Abstraction
MultiPin
abstraction for components using more than one pin:MultiPin
and contain multipleSinglePin
proxies
. AnRGBLed
is built from 3AnalogOutput
s, for example, one for each color, connected to a separate pin.MultiPin
implements a shortcut class methodproxy_pins
. Proxying a pin allows subcomponent pin numbers to be given as a hash when initializing an instance of aMultiPin
component. Eg:{red: 9, green: 10, blue: 11}
given as thepins:
option forRGBLed#new
.#proxies
andattr_reader
methods are created for each, corresponding to their key in thepins:
hash. Eg:RGBLed#green
andRGBLed#proxies[:green]
both give theAnalogOutput
component that represents the green LED inside the RGB LED, connected to pin 10.BoardProxy
abstraction for shift/SPI registers:Register
classes implement enough of theBoard
interface to satisfy components based onDigitalInput
andDigitalOutput
, such asLed
orButton
.Register
object for the type of register. To initialize a component connected to the register, use the register as theboard:
, and give the parallel I/O pin on the register that the component is connected to. Pin 0 maps to the lowest bit.MultiPin
components built out of onlyDigitalInput
orDigitalOutput
, eg.SSD
- seven segment display orRGBLed
. Seeexamples/register
for more.Input Components, Callbacks and State
@value
has been renamed to@state
.#state
and#state=
, which access@state
through@state_mutex
. This way we don't try to read with#state
while a callback is updating it with#state=
.@state
can be any Ruby object representing the state of the component.Callback functionality for components has been extracted into a mixin module,
Mixins::Callbacks
.#add_callback
and#remove_callback
methods are available, and take an optionalkey
as argument.#add_callback
are stored in@callbacks[key]
, to be called later, when the "update" thread receives data for the component. The default key is:persistent
.#remove_callbacks
with a key empties that array. Calling with no key removes all callbacks for the component.#pre_callback_filter
is defined in theCallbacks
module. The return value of this method is what is given to the component's callbacks and to update its@state
. By default, it returns whatever was given from the board.#pre_callback_filter
to process data before giving it to callbacks and@state
. Eg: given raw bytes from a DHT sensor, process them into a hash containing:celsius
,: fahrenheit
and:humidity
values. That hash is given to to callbacks and#update_state
instead of the original string of raw bytes.#update_state
is defined in theCallbacks
module. It is called after all callbacks are run and given the return value of#pre_callback_filter
. By default, it sets@state=
to the value given.@state
is more complex than this, but be sure to either use#state=
only once, or wrap the operation in@state_mutex.synchronize
.Input components no longer automatically start listening when created, since there are more options for reading inputs.
DigitalInput
and its subclasses are the exception to this. They automatically listen, since there is little advantage to other modes.Input components can have any combination of
#read
,#poll
and#listen
methods now, coming fromReader
,Poller
, andListener
respectively, insideMixins
.#read
sends a single read command by calling#_read
, and blocks the main thread, untildata
is received from#pre_callback_filter
. When received, any block that was given to#read
will run once as a callback and be removed immediately.#read
then stops blocking the main thread and returnsdata
.#poll
requires an interval (in seconds) as its first argument. It starts a new thread, and keeps calling#_read
in it, at the given interval.#poll
does not block the main thread, and does not return a value. A block given will be added as a callback inside the:poll
key.#listen
adds its block as a callback inside the:listen
key, calls#_listen
and returns immediately.#stop
stops polling and listening. It also removes all callbacks in the:poll
and:listen
keys (callbacks added as blocks when polling or listening).Minor Changes
rubyserial
gem instead ofserialport
.rspec
tominitest
for testing.Dino::Message
class to handle message construction.Dino::CLI
.Serial
library. No flow control for Ruby receiving data.