Files
compute-blade-agent/pkg/hal/hal_bcm2711_simulated.go
weslson 9477cc71c2 feat(hal): add BCM2712 (CM5/Pi 5) HAL support (#154)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Cedric Specht <cedric@specht-labs.de>
2026-03-04 15:21:39 +01:00

99 lines
2.2 KiB
Go

//go:build darwin
package hal
import (
"context"
"time"
"github.com/compute-blade-community/compute-blade-agent/pkg/hal/led"
"github.com/spechtlabs/go-otel-utils/otelzap"
"go.uber.org/zap"
)
// fails if SimulatedHal does not implement ComputeBladeHal
var _ ComputeBladeHal = &SimulatedHal{}
// SimulatedHal implements a mock for the ComputeBladeHal interface
type SimulatedHal struct {
logger *zap.Logger
isStealthMode bool
}
func NewHal(_ context.Context, _ ComputeBladeHalOpts) (ComputeBladeHal, error) {
logger := otelzap.L().Named("hal").Named("simulated-cm4")
logger.Warn("Using simulated hal")
computeModule.WithLabelValues("simulated").Set(1)
fanUnit.WithLabelValues("simulated").Set(1)
socTemperature.Set(42)
return &SimulatedHal{
logger: logger,
}, nil
}
func (m *SimulatedHal) Run(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
}
func (m *SimulatedHal) Close() error {
return nil
}
func (m *SimulatedHal) SetFanSpeed(percent uint8) error {
m.logger.Info("SetFanSpeed", zap.Uint8("percent", percent))
fanSpeed.Set(2500 * (float64(percent) / 100))
return nil
}
func (m *SimulatedHal) GetFanRPM() (float64, error) {
return 1337, nil
}
func (m *SimulatedHal) SetStealthMode(enabled bool) error {
if enabled {
stealthModeEnabled.Set(1)
} else {
stealthModeEnabled.Set(0)
}
m.isStealthMode = enabled
m.logger.Info("SetStealthMode", zap.Bool("enabled", enabled))
return nil
}
func (m *SimulatedHal) StealthModeActive() bool {
return m.isStealthMode
}
func (m *SimulatedHal) GetPowerStatus() (PowerStatus, error) {
m.logger.Info("GetPowerStatus")
powerStatus.WithLabelValues("simulated").Set(1)
return PowerPoe802at, nil
}
func (m *SimulatedHal) WaitForEdgeButtonPress(ctx context.Context) error {
m.logger.Info("WaitForEdgeButtonPress")
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(5 * time.Second):
edgeButtonEventCount.Inc()
return nil
}
}
func (m *SimulatedHal) SetLed(idx LedIndex, color led.Color) error {
ledColorChangeEventCount.Inc()
m.logger.Info("SetLed", zap.Uint("idx", uint(idx)), zap.Any("color", color))
return nil
}
func (m *SimulatedHal) GetTemperature() (float64, error) {
m.logger.Info("GetTemperature")
return 42, nil
}