1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

brightness: fix ddc erasing devices, fix OSD behaviors

This commit is contained in:
bbedward
2025-12-01 16:32:10 -05:00
parent 1d91d8fd94
commit bd99be15c2
10 changed files with 127 additions and 111 deletions

View File

@@ -37,25 +37,18 @@ func NewDDCBackend() (*DDCBackend, error) {
}
func (b *DDCBackend) scanI2CDevices() error {
b.scanMutex.Lock()
lastScan := b.lastScan
b.scanMutex.Unlock()
if time.Since(lastScan) < b.scanInterval {
return nil
}
return b.scanI2CDevicesInternal(false)
}
func (b *DDCBackend) scanI2CDevicesInternal(force bool) error {
b.scanMutex.Lock()
defer b.scanMutex.Unlock()
if time.Since(b.lastScan) < b.scanInterval {
if !force && time.Since(b.lastScan) < b.scanInterval {
return nil
}
b.devices.Range(func(key string, value *ddcDevice) bool {
b.devices.Delete(key)
return true
})
activeBuses := make(map[int]bool)
for i := 0; i < 32; i++ {
busPath := fmt.Sprintf("/dev/i2c-%d", i)
@@ -68,17 +61,31 @@ func (b *DDCBackend) scanI2CDevices() error {
continue
}
activeBuses[i] = true
id := fmt.Sprintf("ddc:i2c-%d", i)
if _, exists := b.devices.Load(id); exists {
continue
}
dev, err := b.probeDDCDevice(i)
if err != nil || dev == nil {
continue
}
id := fmt.Sprintf("ddc:i2c-%d", i)
dev.id = id
b.devices.Store(id, dev)
log.Debugf("found DDC device on i2c-%d", i)
}
b.devices.Range(func(id string, dev *ddcDevice) bool {
if !activeBuses[dev.bus] {
b.devices.Delete(id)
log.Debugf("removed DDC device %s (bus no longer exists)", id)
}
return true
})
b.lastScan = time.Now()
return nil
@@ -187,6 +194,13 @@ func (b *DDCBackend) SetBrightness(id string, value int, exponential bool, callb
func (b *DDCBackend) SetBrightnessWithExponent(id string, value int, exponential bool, exponent float64, callback func()) error {
_, ok := b.devices.Load(id)
if !ok {
if err := b.scanI2CDevicesInternal(true); err != nil {
log.Debugf("rescan failed for %s: %v", id, err)
}
_, ok = b.devices.Load(id)
}
if !ok {
return fmt.Errorf("device not found: %s", id)
}
@@ -234,6 +248,13 @@ func (b *DDCBackend) SetBrightnessWithExponent(id string, value int, exponential
func (b *DDCBackend) setBrightnessImmediateWithExponent(id string, value int) error {
dev, ok := b.devices.Load(id)
if !ok {
if err := b.scanI2CDevicesInternal(true); err != nil {
log.Debugf("rescan failed for %s: %v", id, err)
}
dev, ok = b.devices.Load(id)
}
if !ok {
return fmt.Errorf("device not found: %s", id)
}