Skip to content

Commit

Permalink
fix/add some comments (hybridgroup#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored Feb 14, 2023
1 parent 64b7c9c commit 9461313
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions drivers/aio/analog_actuator_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/aio/analog_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions drivers/aio/temperature_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpio/aip1640_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"gobot.io/x/gobot"
)

// Commands of the driver
const (
AIP1640DataCmd = 0x40
AIP1640DispCtrl = 0x88
Expand All @@ -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
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpio/buzzer_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"gobot.io/x/gobot"
)

// Some useful divider
const (
Whole = 4
Half = 2
Quarter = 1
Eighth = 0.500
)

// Some items of the musical scale
const (
Rest = 0
C0 = 16.35
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions drivers/gpio/direct_pin_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
7 changes: 5 additions & 2 deletions drivers/gpio/hd44780_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gobot.io/x/gobot"
)

// Commands for the driver
const (
HD44780_CLEARDISPLAY = 0x01
HD44780_RETURNHOME = 0x02
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpio/max7219_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"gobot.io/x/gobot"
)

// Access and command constants for the driver
const (
MAX7219Digit0 = 0x01
MAX7219Digit1 = 0x02
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions drivers/gpio/tm1638_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(),
Expand Down

0 comments on commit 9461313

Please sign in to comment.