Add runtime UV protection toggle and treat near-zero sense as external power.
Per-pod NVS enable (default off) via UART/ESP-NOW/dashboard, and skip UV latch when LiPo ADC reads ~0 mV so USB/external supply still boots. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -290,6 +290,44 @@ func (m *managedSerial) tapConfigExchange(poll bool, req *pb.TapConfigRequest) (
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (m *managedSerial) BatteryUv(req *pb.BatteryUvRequest) (*pb.BatteryUvResponse, error) {
|
||||
return m.batteryUvExchange(false, req)
|
||||
}
|
||||
|
||||
func (m *managedSerial) BatteryUvPoll(req *pb.BatteryUvRequest) (*pb.BatteryUvResponse, error) {
|
||||
return m.batteryUvExchange(true, req)
|
||||
}
|
||||
|
||||
func (m *managedSerial) batteryUvExchange(poll bool, req *pb.BatteryUvRequest) (*pb.BatteryUvResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_BATTERY_UV,
|
||||
Payload: &pb.UartMessage_BatteryUvRequest{BatteryUvRequest: req},
|
||||
}
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode: %w", err)
|
||||
}
|
||||
payload := append([]byte{byte(pb.MessageType_BATTERY_UV)}, body...)
|
||||
var respPayload []byte
|
||||
if poll {
|
||||
respPayload, err = m.exchangePayloadPoll(payload, "BATTERY_UV")
|
||||
} else {
|
||||
respPayload, err = m.exchangePayload(payload, "BATTERY_UV")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var respMsg pb.UartMessage
|
||||
if err := proto.Unmarshal(respPayload[1:], &respMsg); err != nil {
|
||||
return nil, fmt.Errorf("decode: %w", err)
|
||||
}
|
||||
r := respMsg.GetBatteryUvResponse()
|
||||
if r == nil {
|
||||
return nil, fmt.Errorf("missing battery_uv_response")
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (m *managedSerial) accelDeadzoneExchange(poll bool, req *pb.AccelDeadzoneRequest) (*pb.AccelDeadzoneResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_ACCEL_DEADZONE,
|
||||
@@ -510,6 +548,33 @@ func (s *serialPort) tapConfig(req *pb.TapConfigRequest) (*pb.TapConfigResponse,
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (s *serialPort) batteryUv(req *pb.BatteryUvRequest) (*pb.BatteryUvResponse, error) {
|
||||
msg := &pb.UartMessage{
|
||||
Type: pb.MessageType_BATTERY_UV,
|
||||
Payload: &pb.UartMessage_BatteryUvRequest{
|
||||
BatteryUvRequest: req,
|
||||
},
|
||||
}
|
||||
body, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode: %w", err)
|
||||
}
|
||||
payload := append([]byte{byte(pb.MessageType_BATTERY_UV)}, body...)
|
||||
respPayload, err := s.exchangePayload(payload, "BATTERY_UV")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var respMsg pb.UartMessage
|
||||
if err := proto.Unmarshal(respPayload[1:], &respMsg); err != nil {
|
||||
return nil, fmt.Errorf("decode: %w", err)
|
||||
}
|
||||
r := respMsg.GetBatteryUvResponse()
|
||||
if r == nil {
|
||||
return nil, fmt.Errorf("missing battery_uv_response")
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (s *serialPort) espnowUnicastTest(clientID, seq uint32) (*pb.EspNowUnicastTestResponse, error) {
|
||||
req := &pb.EspNowUnicastTestRequest{ClientId: clientID, Seq: seq}
|
||||
msg := &pb.UartMessage{
|
||||
@@ -681,6 +746,10 @@ func (s *serialPort) TapConfig(req *pb.TapConfigRequest) (*pb.TapConfigResponse,
|
||||
return s.tapConfig(req)
|
||||
}
|
||||
|
||||
func (s *serialPort) BatteryUv(req *pb.BatteryUvRequest) (*pb.BatteryUvResponse, error) {
|
||||
return s.batteryUv(req)
|
||||
}
|
||||
|
||||
func (s *serialPort) EspnowUnicastTest(clientID, seq uint32) (*pb.EspNowUnicastTestResponse, error) {
|
||||
return s.espnowUnicastTest(clientID, seq)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user