ble: rename drivers to make them more obvious, and add test placeholders
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
480b739c02
commit
5ddfb632bc
|
@ -6,8 +6,7 @@ import (
|
|||
"gobot.io/x/gobot"
|
||||
)
|
||||
|
||||
var _ gobot.Driver = (*BatteryDriver)(nil)
|
||||
|
||||
// BatteryDriver represents the Battery Service for a BLE Peripheral
|
||||
type BatteryDriver struct {
|
||||
name string
|
||||
connection gobot.Connection
|
||||
|
@ -24,9 +23,15 @@ func NewBatteryDriver(a *ClientAdaptor) *BatteryDriver {
|
|||
|
||||
return n
|
||||
}
|
||||
|
||||
// Connection returns the Driver's Connection to the associated Adaptor
|
||||
func (b *BatteryDriver) Connection() gobot.Connection { return b.connection }
|
||||
func (b *BatteryDriver) Name() string { return b.name }
|
||||
func (b *BatteryDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// Name returns the Driver name
|
||||
func (b *BatteryDriver) Name() string { return b.name }
|
||||
|
||||
// SetName sets the Driver name
|
||||
func (b *BatteryDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// adaptor returns BLE adaptor
|
||||
func (b *BatteryDriver) adaptor() *ClientAdaptor {
|
||||
|
@ -41,6 +46,7 @@ func (b *BatteryDriver) Start() (err error) {
|
|||
// Halt stops battery driver (void)
|
||||
func (b *BatteryDriver) Halt() (err error) { return }
|
||||
|
||||
// GetBatteryLevel reads and returns the current battery level
|
||||
func (b *BatteryDriver) GetBatteryLevel() (level uint8) {
|
||||
var l uint8
|
||||
c, _ := b.adaptor().ReadCharacteristic("180f", "2a19")
|
|
@ -0,0 +1,20 @@
|
|||
package ble
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot"
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
)
|
||||
|
||||
var _ gobot.Driver = (*BatteryDriver)(nil)
|
||||
|
||||
func initTestBatteryDriver() *BatteryDriver {
|
||||
d := NewBatteryDriver(NewClientAdaptor("D7:99:5A:26:EC:38"))
|
||||
return d
|
||||
}
|
||||
|
||||
func TestBatteryDriver(t *testing.T) {
|
||||
d := initTestBatteryDriver()
|
||||
gobottest.Assert(t, d.Name(), "Battery")
|
||||
}
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
var _ gobot.Driver = (*DeviceInformationDriver)(nil)
|
||||
|
||||
// DeviceInformationDriver represents the Device Information Service for a BLE Peripheral
|
||||
type DeviceInformationDriver struct {
|
||||
name string
|
||||
connection gobot.Connection
|
||||
|
@ -24,9 +25,15 @@ func NewDeviceInformationDriver(a *ClientAdaptor) *DeviceInformationDriver {
|
|||
|
||||
return n
|
||||
}
|
||||
|
||||
// Connection returns the Driver's Connection to the associated Adaptor
|
||||
func (b *DeviceInformationDriver) Connection() gobot.Connection { return b.connection }
|
||||
func (b *DeviceInformationDriver) Name() string { return b.name }
|
||||
func (b *DeviceInformationDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// Name returns the Driver name
|
||||
func (b *DeviceInformationDriver) Name() string { return b.name }
|
||||
|
||||
// SetName sets the Driver name
|
||||
func (b *DeviceInformationDriver) SetName(n string) { b.name = n }
|
||||
|
||||
// adaptor returns BLE adaptor for this device
|
||||
func (b *DeviceInformationDriver) adaptor() *ClientAdaptor {
|
||||
|
@ -41,6 +48,7 @@ func (b *DeviceInformationDriver) Start() (err error) {
|
|||
// Halt stops driver (void)
|
||||
func (b *DeviceInformationDriver) Halt() (err error) { return }
|
||||
|
||||
// GetModelNumber returns the model number for the BLE Peripheral
|
||||
func (b *DeviceInformationDriver) GetModelNumber() (model string) {
|
||||
c, _ := b.adaptor().ReadCharacteristic("180a", "2a24")
|
||||
buf := bytes.NewBuffer(c)
|
||||
|
@ -48,6 +56,7 @@ func (b *DeviceInformationDriver) GetModelNumber() (model string) {
|
|||
return val
|
||||
}
|
||||
|
||||
// GetFirmwareRevision returns the firmware revision for the BLE Peripheral
|
||||
func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) {
|
||||
c, _ := b.adaptor().ReadCharacteristic("180a", "2a26")
|
||||
buf := bytes.NewBuffer(c)
|
||||
|
@ -55,6 +64,7 @@ func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) {
|
|||
return val
|
||||
}
|
||||
|
||||
// GetHardwareRevision returns the hardware revision for the BLE Peripheral
|
||||
func (b *DeviceInformationDriver) GetHardwareRevision() (revision string) {
|
||||
c, _ := b.adaptor().ReadCharacteristic("180a", "2a27")
|
||||
buf := bytes.NewBuffer(c)
|
||||
|
@ -62,6 +72,7 @@ func (b *DeviceInformationDriver) GetHardwareRevision() (revision string) {
|
|||
return val
|
||||
}
|
||||
|
||||
// GetManufacturerName returns the manufacturer name for the BLE Peripheral
|
||||
func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) {
|
||||
c, _ := b.adaptor().ReadCharacteristic("180a", "2a29")
|
||||
buf := bytes.NewBuffer(c)
|
||||
|
@ -69,6 +80,7 @@ func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) {
|
|||
return val
|
||||
}
|
||||
|
||||
// GetPnPId returns the PnP ID for the BLE Peripheral
|
||||
func (b *DeviceInformationDriver) GetPnPId() (model string) {
|
||||
c, _ := b.adaptor().ReadCharacteristic("180a", "2a50")
|
||||
buf := bytes.NewBuffer(c)
|
|
@ -0,0 +1,17 @@
|
|||
package ble
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gobot.io/x/gobot/gobottest"
|
||||
)
|
||||
|
||||
func initTestDeviceInformationDriver() *DeviceInformationDriver {
|
||||
d := NewDeviceInformationDriver(NewClientAdaptor("D7:99:5A:26:EC:38"))
|
||||
return d
|
||||
}
|
||||
|
||||
func TestDeviceInformationDriver(t *testing.T) {
|
||||
d := initTestDeviceInformationDriver()
|
||||
gobottest.Assert(t, d.Name(), "DeviceInformation")
|
||||
}
|
Loading…
Reference in New Issue