modify drivers

This commit is contained in:
Adrian Zuercher
2025-07-29 12:37:04 +02:00
parent eabac1b11b
commit 4221815def
5 changed files with 62 additions and 25 deletions

View File

@@ -4,28 +4,33 @@ import "slices"
// bus model
type Bus struct {
Name string `json:"name,omitemtpy"`
Address []uint `json:"address,omitemtpy"` // address of bus
Topic *Topic `json:"topic,omitemtpy"` // address of bus
Name string `json:"name,omitempty"`
Address []uint `json:"address,omitempty"` // address of bus
Topic *Topic `json:"topic,omitempty"` // address of bus
}
func (b *Bus) AddAddress(address uint) {
if !slices.Contains(b.Address, address) {
b.Address = append(b.Address, address)
func (b *Bus) AddAddress(address ...uint) {
for _, a := range address {
if slices.Contains(b.Address, a) {
continue
}
b.Address = append(b.Address, a)
slices.Sort(b.Address)
}
}
func (b *Bus) AddSubscription(sub string) {
func (b *Bus) AddSubscription(sub ...string) {
if b.Topic == nil {
b.Topic = &Topic{}
}
b.Topic.AddSubscription(sub)
b.Topic.AddSubscription(sub...)
}
func (b *Bus) AddPublish(pub string) {
func (b *Bus) AddPublish(pub ...string) {
if b.Topic == nil {
b.Topic = &Topic{}
}
b.Topic.AddPublish(pub)
b.Topic.AddPublish(pub...)
}