1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/platforms/ble/device_information.go
2016-03-02 22:43:41 -08:00

52 lines
1.3 KiB
Go

package ble
import (
"bytes"
"github.com/hybridgroup/gobot"
)
var _ gobot.Driver = (*BLEDeviceInformationDriver)(nil)
type BLEDeviceInformationDriver struct {
name string
connection gobot.Connection
gobot.Eventer
}
// NewBLEDeviceInformationDriver creates a BLEDeviceInformationDriver
// by name
func NewBLEDeviceInformationDriver(a *BLEAdaptor, name string) *BLEDeviceInformationDriver {
n := &BLEDeviceInformationDriver{
name: name,
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
func (b *BLEDeviceInformationDriver) Connection() gobot.Connection { return b.connection }
func (b *BLEDeviceInformationDriver) Name() string { return b.name }
// adaptor returns BLE adaptor for this device
func (b *BLEDeviceInformationDriver) adaptor() *BLEAdaptor {
return b.Connection().(*BLEAdaptor)
}
// Start tells driver to get ready to do work
func (b *BLEDeviceInformationDriver) Start() (errs []error) {
return
}
// Halt stops driver (void)
func (b *BLEDeviceInformationDriver) Halt() (errs []error) { return }
func (b *BLEDeviceInformationDriver) GetModelNumber() (model string) {
var l string
c, _ := b.adaptor().ReadCharacteristic("180a", "2a24")
buf := bytes.NewBuffer(c)
val, _ := buf.ReadByte()
l = string(val)
return l
}