add read write lock to dmx data

This commit is contained in:
Adrian Zuercher
2025-07-26 07:18:26 +02:00
parent 05409c2544
commit a503b71fb6
5 changed files with 49 additions and 23 deletions

View File

@@ -1,12 +1,27 @@
package models
type DMX []byte
import "sync"
type DMX struct {
Data []byte
mu sync.Mutex
}
func NewDMXUniverse() *DMX {
dmx := make(DMX, 512)
return &dmx
return &DMX{
Data: make([]byte, 512),
}
}
func (d *DMX) GetDMXData() (data []byte) {
d.mu.Lock()
data = d.Data
d.mu.Unlock()
return data
}
func (d *DMX) SetValue(channel uint, value uint8) {
(*d)[channel] = value
d.mu.Lock()
d.Data[channel] = value
d.mu.Unlock()
}