Skip to content
Snippets Groups Projects
Commit 140d905b authored by jkerdreu's avatar jkerdreu
Browse files

- Added some stuff to test grouped attributes messages

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Go/trunk/xaal-lib/apps@3123 b32b6428-25c9-4566-ad07-03861ab6144f
parent 0f0bf538
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
package main
import (
"time"
xAALLib "xAAL/lib"
"github.com/google/uuid"
......@@ -24,23 +25,50 @@ func newLamp(addr uuid.UUID, group uuid.UUID) *Lamp {
dev.AddAttribute("brightness", 0)
dev.AddMethod("turn_on", l.turnOn)
dev.AddMethod("turn_off", l.turnOff)
dev.AddMethod("toggle", l.toggle)
dev.AddMethod("set_brightness", l.setBrightness)
dev.Dump()
return l
}
// turnOn set the brightness to 50 to test attributes grouped msg
func (l *Lamp) turnOn(xAALLib.MessageBody) *xAALLib.MessageBody {
l.dev.GetAttribute("light").SetValue(true)
light := l.dev.GetAttribute("light")
if light.Value.(bool) == true {
return nil
}
light.SetValue(true)
brightness := l.dev.GetAttribute("brightness")
if brightness.Value.(int) == 0 {
brightness.SetValue(50)
}
return nil
}
// turnOff set the brightness to 0 to test attributes grouped msg
func (l *Lamp) turnOff(xAALLib.MessageBody) *xAALLib.MessageBody {
l.dev.GetAttribute("light").SetValue(false)
light := l.dev.GetAttribute("light")
if light.Value.(bool) == false {
return nil
}
light.SetValue(false)
l.dev.GetAttribute("brightness").SetValue(0)
return nil
}
// toggle the light
func (l *Lamp) toggle(xAALLib.MessageBody) *xAALLib.MessageBody {
light := l.dev.GetAttribute("light")
if light.Value.(bool) == true {
l.turnOff(nil)
} else {
l.turnOn(nil)
}
return nil
}
func (l *Lamp) setBrightness(args xAALLib.MessageBody) *xAALLib.MessageBody {
if value, ok := args["brightness"].(uint64); ok {
if value, ok := args["brightness"].(int64); ok {
if value > 100 {
value = 100
}
......@@ -49,8 +77,15 @@ func (l *Lamp) setBrightness(args xAALLib.MessageBody) *xAALLib.MessageBody {
return nil
}
func main() {
// used to make it blink w/ a goroutine
func (l *Lamp) blink(args xAALLib.MessageBody) *xAALLib.MessageBody {
for {
l.toggle(nil)
time.Sleep(time.Second * 3)
}
}
func main() {
eng := xAALLib.NewEngine()
eng.Start()
......@@ -61,6 +96,9 @@ func main() {
baseAddr[15] = byte(i)
l := newLamp(baseAddr, group)
eng.AddDevice(l.dev)
if i == 0 {
go l.blink(nil)
}
}
eng.Run()
......
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