Skip to content
Snippets Groups Projects
Commit 9ecbb186 authored by jkerdreu's avatar jkerdreu
Browse files

- Cleanup Lamp

- Added chandelier (to test UUID tricks and GroupID) 

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Go/trunk/xaal-lib/apps@3116 b32b6428-25c9-4566-ad07-03861ab6144f
parent 946dab1f
No related branches found
No related tags found
No related merge requests found
package main
import (
"fmt"
"os"
"os/signal"
xAALLib "xAAL/lib"
"github.com/google/uuid"
)
type Lamp struct {
dev *xAALLib.Device
}
func newLamp(addr uuid.UUID, group uuid.UUID) *Lamp {
dev := xAALLib.NewDevice("lamp.dimmer")
l := &Lamp{dev: dev}
dev.Address = addr
dev.VendorID = "IMT Atlantique"
dev.ProductID = "Golang Chandelier Lamp"
dev.GroupID = group
dev.AddAttribute("light", false)
dev.AddAttribute("brightness", 0)
dev.AddMethod("turn_on", l.turnOn)
dev.AddMethod("turn_off", l.turnOff)
dev.AddMethod("set_brightness", l.setBrightness)
dev.Dump()
return l
}
func (l *Lamp) turnOn(xAALLib.MessageBody) *xAALLib.MessageBody {
l.dev.GetAttribute("light").SetValue(true)
return nil
}
func (l *Lamp) turnOff(xAALLib.MessageBody) *xAALLib.MessageBody {
l.dev.GetAttribute("light").SetValue(false)
return nil
}
func (l *Lamp) setBrightness(args xAALLib.MessageBody) *xAALLib.MessageBody {
if value, ok := args["brightness"].(uint64); ok {
if value > 100 {
value = 100
}
l.dev.GetAttribute("brightness").SetValue(value)
}
return nil
}
func main() {
eng := xAALLib.NewEngine()
eng.Start()
baseAddr := uuid.MustParse("89b11138-a76b-11ee-91c7-d6bd5fe18700")
group := baseAddr
group[15] = 0xff
for i := 0; i < 6; i++ {
baseAddr[15] = byte(i)
l := newLamp(baseAddr, group)
eng.AddDevice(l.dev)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
fmt.Println("Exiting")
eng.Stop()
}
......@@ -17,11 +17,12 @@ func main() {
lamp := xAALLib.NewDevice("lamp.dimmer")
lamp.Address = uuid.MustParse("6558b72b-3ae6-4995-8c4c-e407b7119889")
light := lamp.AddAttribute("light", true)
brightness := lamp.AddAttribute("brightness", 0)
brightness := lamp.AddAttribute("brightness", 50)
lamp.VendorID = "JKx Entreprise"
lamp.ProductID = "Really powerFull lamp"
lamp.VendorID = "IMT Atlantique"
lamp.ProductID = "Golang test lamp"
lamp.URL = "http://example.com"
turn_on := func(xAALLib.MessageBody) *xAALLib.MessageBody {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment