Skip to content
Snippets Groups Projects
Commit 61f1c238 authored by jkerdreu's avatar jkerdreu
Browse files

Initial split between apps and lib


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Go/trunk/xaal-lib/apps@3107 b32b6428-25c9-4566-ad07-03861ab6144f
parents
No related branches found
No related tags found
No related merge requests found
main.go 0 → 100644
package main
import (
"fmt"
"os"
"os/signal"
"github.com/google/uuid"
)
func showMessage(msg *Message) {
if msg.IsAttributesChange() {
msg.Dump()
}
}
func main() {
eng := NewEngine()
eng.Start()
// eng.Subscribe(showMessage)
lamp := NewDevice("lamp.dimmer")
lamp.Address = uuid.MustParse("6558b72b-3ae6-4995-8c4c-e407b7119889")
light := lamp.AddAttribute("light", true)
brightness := lamp.AddAttribute("brightness", 0)
lamp.VendorID = "JKx Entreprise"
lamp.ProductID = "Really powerFull lamp"
lamp.URL = "http://example.com"
turn_on := func(MessageBody) *MessageBody {
light.SetValue(true)
return nil
}
turn_off := func(MessageBody) *MessageBody {
light.SetValue(false)
return nil
}
toggle := func(MessageBody) *MessageBody {
light.SetValue(!light.Value.(bool))
return nil
}
dim := func(args MessageBody) *MessageBody {
if value, ok := args["brightness"].(uint64); ok {
if value > 100 {
value = 100
}
brightness.SetValue(value)
if value == 0 {
turn_off(MessageBody{})
} else {
turn_on(MessageBody{})
}
}
return nil
}
lamp.AddMethod("turn_on", turn_on)
lamp.AddMethod("turn_off", turn_off)
lamp.AddMethod("toggle", toggle)
lamp.AddMethod("set_brightness", dim)
lamp.Dump()
eng.AddDevice(lamp)
// eng.test()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
fmt.Println("Exiting")
eng.Stop()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment