mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-11 19:29:20 +08:00
fix/add some comments (#901)
This commit is contained in:
parent
64b7c9c98a
commit
946131356e
@ -96,6 +96,7 @@ func (a *AnalogActuatorDriver) Value() (val float64) {
|
||||
return a.lastValue
|
||||
}
|
||||
|
||||
// AnalogActuatorLinearScaler creates a linear scaler function from the given values.
|
||||
func AnalogActuatorLinearScaler(fromMin, fromMax float64, toMin, toMax int) func(input float64) (value int) {
|
||||
m := float64(toMax-toMin) / (fromMax - fromMin)
|
||||
n := float64(toMin) - m*fromMin
|
||||
|
@ -157,6 +157,7 @@ func (a *AnalogSensorDriver) RawValue() int {
|
||||
return a.rawValue
|
||||
}
|
||||
|
||||
// AnalogSensorLinearScaler creates a linear scaler function from the given values.
|
||||
func AnalogSensorLinearScaler(fromMin, fromMax int, toMin, toMax float64) func(input int) (value float64) {
|
||||
m := (toMax - toMin) / float64(fromMax-fromMin)
|
||||
n := toMin - m*float64(fromMin)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
const kelvinOffset = 273.15
|
||||
|
||||
// TemperatureSensorNtcConf contains all attributes to calculate key parameters of a NTC thermistor.
|
||||
type TemperatureSensorNtcConf struct {
|
||||
TC0 int // °C
|
||||
R0 float64 // same unit as resistance of NTC (Ohm is recommended)
|
||||
@ -44,11 +45,11 @@ func NewTemperatureSensorDriver(a AnalogReader, pin string, v ...time.Duration)
|
||||
return d
|
||||
}
|
||||
|
||||
// SetNtcSaler sets a function for typical NTC scaling the read value.
|
||||
// SetNtcScaler sets a function for typical NTC scaling the read value.
|
||||
// The read value is related to the voltage over the thermistor in an series connection to a resistor.
|
||||
// If the thermistor is connected to ground, the reverse flag must be set to true.
|
||||
// This means the voltage decreases when temperature gets higher.
|
||||
// Currently no negative values are supported.
|
||||
// Currently no negative values for voltage are supported.
|
||||
func (t *TemperatureSensorDriver) SetNtcScaler(vRef uint, rOhm uint, reverse bool, ntc TemperatureSensorNtcConf) {
|
||||
t.SetScaler(TemperatureSensorNtcScaler(vRef, rOhm, reverse, ntc))
|
||||
}
|
||||
@ -60,6 +61,11 @@ func (t *TemperatureSensorDriver) SetLinearScaler(fromMin, fromMax int, toMin, t
|
||||
t.SetScaler(AnalogSensorLinearScaler(fromMin, fromMax, toMin, toMax))
|
||||
}
|
||||
|
||||
// TemperatureSensorNtcScaler creates a function for typical NTC scaling the read value.
|
||||
// The read value is related to the voltage over the thermistor in an series connection to a resistor.
|
||||
// If the thermistor is connected to ground, the reverse flag must be set to true.
|
||||
// This means the voltage decreases when temperature gets higher.
|
||||
// Currently no negative values for voltage are supported.
|
||||
func TemperatureSensorNtcScaler(vRef uint, rOhm uint, reverse bool, ntc TemperatureSensorNtcConf) func(input int) (value float64) {
|
||||
ntc.initialize()
|
||||
return (func(input int) (value float64) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
// Commands of the driver
|
||||
const (
|
||||
AIP1640DataCmd = 0x40
|
||||
AIP1640DispCtrl = 0x88
|
||||
@ -21,7 +22,7 @@ const (
|
||||
//
|
||||
// Library ported from: https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library
|
||||
type AIP1640Driver struct {
|
||||
pinClock *DirectPinDriver
|
||||
pinClock *DirectPinDriver
|
||||
pinData *DirectPinDriver
|
||||
name string
|
||||
intensity byte
|
||||
@ -34,7 +35,7 @@ type AIP1640Driver struct {
|
||||
func NewAIP1640Driver(a gobot.Connection, clockPin string, dataPin string) *AIP1640Driver {
|
||||
t := &AIP1640Driver{
|
||||
name: gobot.DefaultName("AIP1640Driver"),
|
||||
pinClock: NewDirectPinDriver(a, clockPin),
|
||||
pinClock: NewDirectPinDriver(a, clockPin),
|
||||
pinData: NewDirectPinDriver(a, dataPin),
|
||||
intensity: 7,
|
||||
connection: a,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
// Some useful divider
|
||||
const (
|
||||
Whole = 4
|
||||
Half = 2
|
||||
@ -13,6 +14,7 @@ const (
|
||||
Eighth = 0.500
|
||||
)
|
||||
|
||||
// Some items of the musical scale
|
||||
const (
|
||||
Rest = 0
|
||||
C0 = 16.35
|
||||
@ -202,6 +204,7 @@ func (l *BuzzerDriver) Toggle() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Tone is to make a sound with the given frequency
|
||||
func (l *BuzzerDriver) Tone(hz, duration float64) (err error) {
|
||||
// calculation based off https://www.arduino.cc/en/Tutorial/Melody
|
||||
tone := (1.0 / (2.0 * hz)) * 1000000.0
|
||||
|
@ -19,7 +19,6 @@ type DirectPinDriver struct {
|
||||
// Adds the following API Commands:
|
||||
// "DigitalRead" - See DirectPinDriver.DigitalRead
|
||||
// "DigitalWrite" - See DirectPinDriver.DigitalWrite
|
||||
// "AnalogWrite" - See DirectPinDriver.AnalogWrite
|
||||
// "PwmWrite" - See DirectPinDriver.PwmWrite
|
||||
// "ServoWrite" - See DirectPinDriver.ServoWrite
|
||||
func NewDirectPinDriver(a gobot.Connection, pin string) *DirectPinDriver {
|
||||
@ -68,7 +67,7 @@ func (d *DirectPinDriver) Start() (err error) { return }
|
||||
// Halt implements the Driver interface
|
||||
func (d *DirectPinDriver) Halt() (err error) { return }
|
||||
|
||||
// Turn Off pin
|
||||
// Off turn off pin
|
||||
func (d *DirectPinDriver) Off() (err error) {
|
||||
if writer, ok := d.Connection().(DigitalWriter); ok {
|
||||
return writer.DigitalWrite(d.Pin(), byte(0))
|
||||
@ -77,7 +76,7 @@ func (d *DirectPinDriver) Off() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Turn On pin
|
||||
// On turn on pin
|
||||
func (d *DirectPinDriver) On() (err error) {
|
||||
if writer, ok := d.Connection().(DigitalWriter); ok {
|
||||
return writer.DigitalWrite(d.Pin(), byte(1))
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
// Commands for the driver
|
||||
const (
|
||||
HD44780_CLEARDISPLAY = 0x01
|
||||
HD44780_RETURNHOME = 0x02
|
||||
@ -40,19 +41,21 @@ const (
|
||||
HD44780_8BITBUS = 0x10
|
||||
)
|
||||
|
||||
// Some useful constants for the driver
|
||||
const (
|
||||
HD44780_2NDLINEOFFSET = 0x40
|
||||
)
|
||||
|
||||
// data bus mode
|
||||
// HD44780BusMode is the data bus mode
|
||||
type HD44780BusMode int
|
||||
|
||||
// Bus modes of the driver
|
||||
const (
|
||||
HD44780_4BITMODE HD44780BusMode = iota + 1
|
||||
HD44780_8BITMODE
|
||||
)
|
||||
|
||||
// databit pins
|
||||
// HD44780DataPin are the data bit pins
|
||||
type HD44780DataPin struct {
|
||||
D0 string // not used if 4Bit mode
|
||||
D1 string // not used if 4Bit mode
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
// Access and command constants for the driver
|
||||
const (
|
||||
MAX7219Digit0 = 0x01
|
||||
MAX7219Digit1 = 0x02
|
||||
@ -96,7 +97,7 @@ func (a *MAX7219Driver) ClearAll() {
|
||||
}
|
||||
}
|
||||
|
||||
// ClearAll turns off all LEDs of the given module
|
||||
// ClearOne turns off all LEDs of the given module
|
||||
func (a *MAX7219Driver) ClearOne(which uint) {
|
||||
for i := 1; i <= 8; i++ {
|
||||
a.One(which, byte(i), 0)
|
||||
|
@ -8,12 +8,14 @@ import (
|
||||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
// Colors of the display
|
||||
const (
|
||||
TM1638None = iota
|
||||
TM1638Red
|
||||
TM1638Green
|
||||
)
|
||||
|
||||
// Commands of the driver
|
||||
const (
|
||||
TM1638DataCmd = 0x40
|
||||
TM1638DispCtrl = 0x80
|
||||
@ -31,9 +33,8 @@ const (
|
||||
// Datasheet CN: http://www.datasheetspdf.com/pdf/775356/TitanMicro/TM1638/1
|
||||
//
|
||||
// Ported from the Arduino driver https://github.com/rjbatista/tm1638-library
|
||||
|
||||
type TM1638Driver struct {
|
||||
pinClock *DirectPinDriver
|
||||
pinClock *DirectPinDriver
|
||||
pinData *DirectPinDriver
|
||||
pinStrobe *DirectPinDriver
|
||||
fonts map[string]byte
|
||||
@ -46,7 +47,7 @@ type TM1638Driver struct {
|
||||
func NewTM1638Driver(a gobot.Connection, clockPin string, dataPin string, strobePin string) *TM1638Driver {
|
||||
t := &TM1638Driver{
|
||||
name: gobot.DefaultName("TM1638"),
|
||||
pinClock: NewDirectPinDriver(a, clockPin),
|
||||
pinClock: NewDirectPinDriver(a, clockPin),
|
||||
pinData: NewDirectPinDriver(a, dataPin),
|
||||
pinStrobe: NewDirectPinDriver(a, strobePin),
|
||||
fonts: NewTM1638Fonts(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user