some basic stuffs.

This commit is contained in:
2022-12-21 18:17:40 +01:00
parent e00fe2a4d2
commit 6f8def066f
9 changed files with 181 additions and 21 deletions
+1 -2
View File
@@ -88,10 +88,9 @@ func (s *effectEnforcer) runLoop(bus *lucifer3.EventBus) {
deleteList := make([]int, 0, 8)
batch := make(commands.SetStateBatch, 64)
for now := range time.NewTicker(time.Millisecond * 25).C {
for now := range time.NewTicker(time.Millisecond * 50).C {
s.mu.Lock()
for i, run := range s.list {
if run.dead {
deleteList = append(deleteList, i-len(deleteList))
continue
+66
View File
@@ -0,0 +1,66 @@
package services
import (
lucifer3 "git.aiterp.net/lucifer3/server"
"git.aiterp.net/lucifer3/server/commands"
"git.aiterp.net/lucifer3/server/device"
"git.aiterp.net/lucifer3/server/effects"
"git.aiterp.net/lucifer3/server/events"
"git.aiterp.net/lucifer3/server/internal/color"
"git.aiterp.net/lucifer3/server/internal/gentools"
"git.aiterp.net/lucifer3/server/internal/testutils"
"strconv"
"testing"
"time"
)
func TestEffectEnforcer(t *testing.T) {
bus := lucifer3.EventBus{}
resolver := NewResolver()
sceneMap := NewSceneMap(resolver)
logger := &testutils.TestEventLogger{}
bus.JoinPrivileged(resolver)
bus.JoinPrivileged(sceneMap)
bus.Join(NewEffectEnforcer(resolver, sceneMap))
bus.Join(logger)
for i := 1; i <= 9; i += 1 {
bus.RunEvents([]lucifer3.Event{
events.HardwareState{
ID: "test:" + strconv.Itoa(i),
InternalName: "Test Device " + strconv.Itoa(i),
SupportFlags: device.SFlagColor | device.SFlagIntensity | device.SFlagPower,
ColorFlags: device.CFlagXY | device.CFlagHS | device.CFlagRGB | device.CFlagKelvin,
ColorGamut: nil,
ColorKelvinRange: nil,
Buttons: nil,
State: device.State{
Power: gentools.Ptr(false),
Intensity: gentools.Ptr(1.0),
Color: &color.Color{K: gentools.Ptr(2900)},
},
BatteryPercentage: nil,
Unreachable: false,
},
events.DeviceReady{ID: "test:" + strconv.Itoa(i)},
})
}
bus.RunCommand(commands.Assign{
Match: "test:*",
Effect: effects.Pattern{
States: []device.State{
{Color: &color.Color{XY: &color.XY{X: 0.22, Y: 0.18}}},
{Color: &color.Color{XY: &color.XY{X: 0.27, Y: 0.23}}},
},
},
})
time.Sleep(time.Millisecond * 100)
logger.Sync(&bus)
logger.AssertEvent(t, "DeviceReady(id:test:1)")
logger.AssertEvent(t, "DeviceReady(id:test:9)")
logger.AssertCommand(t, "Assign(test:*, Pattern(states:[(xy:0.2200,0.1800), (xy:0.2700,0.2300)], anim:0ms))")
logger.AssertCommand(t, "SetStateBatch(9 devices)")
}
+20 -13
View File
@@ -93,6 +93,8 @@ func (b *bridge) Refresh(ctx context.Context) ([]string, error) {
b.mu.Lock()
PanelLoop:
for _, panelInfo := range overview.PanelLayout.Data.PositionData {
log.Printf("%#+v", panelInfo)
if shapeTypeMap[panelInfo.ShapeType] == "Shapes Controller" {
continue
}
@@ -290,7 +292,7 @@ func (b *bridge) Run(ctx context.Context, bus *lucifer3.EventBus) error {
}
panelUpdate.Add(panel.message())
if panelUpdate.Len() > 150 {
if panelUpdate.Len() > 1256 {
break
}
}
@@ -349,8 +351,7 @@ func (b *bridge) updateEffect(ctx context.Context) error {
}
func (b *bridge) runTouchListener(ctx context.Context, bus *lucifer3.EventBus) {
cooldownID := ""
cooldownUntil := time.Now()
cooldownMap := make(map[uint16]time.Time)
message := make(PanelEventMessage, 65536)
reqCloser := io.Closer(nil)
@@ -408,23 +409,29 @@ func (b *bridge) runTouchListener(ctx context.Context, bus *lucifer3.EventBus) {
}
for i := 0; i < message.Count(); i += 1 {
panelID := message.PanelID(i)
b.mu.Lock()
id, hasID := b.panelIDMap[message.PanelID(i)]
id, hasID := b.panelIDMap[panelID]
swipedFromID := b.panelIDMap[message.SwipedFromPanelID(i)]
b.mu.Unlock()
if !hasID || (id == cooldownID && time.Now().Before(cooldownUntil)) {
if time.Now().Before(cooldownMap[panelID]) {
continue
} else if !hasID {
bus.RunEvent(events.ButtonPressed{
ID: fmt.Sprintf("nanoleaf:%s:meta:%x", b.host, panelID),
SwipedID: swipedFromID,
Name: "Touch",
})
} else {
bus.RunEvent(events.ButtonPressed{
ID: id,
SwipedID: swipedFromID,
Name: "Touch",
})
}
bus.RunEvent(events.ButtonPressed{
ID: id,
SwipedID: swipedFromID,
Name: "Touch",
})
cooldownID = id
cooldownUntil = time.Now().Add(time.Second)
cooldownMap[panelID] = time.Now().Add(time.Second)
}
}
}
-2
View File
@@ -4,7 +4,6 @@ import (
lucifer3 "git.aiterp.net/lucifer3/server"
"git.aiterp.net/lucifer3/server/commands"
"git.aiterp.net/lucifer3/server/device"
"log"
"sync"
)
@@ -58,7 +57,6 @@ func (s *SceneMap) HandleCommand(_ *lucifer3.EventBus, command lucifer3.Command)
if len(matched) > 0 {
s.mu.Lock()
for _, ptr := range matched {
log.Println("Got")
delete(s.sceneMap, ptr.ID)
}
s.mu.Unlock()