Add accelerometer deadzone via UART and ESP-NOW.

Filter BMA456 logs by configurable LSB threshold; master can set deadzone
for local sensor or slaves using ACCEL_DEADZONE (UART) and ESP-NOW broadcast
until unicast delivery is restored.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-18 23:06:25 +02:00
co-authored by Cursor
parent e5db0b21c7
commit ee38ce551a
24 changed files with 838 additions and 73 deletions
+237 -43
View File
@@ -30,6 +30,7 @@ const (
MessageType_VERSION MessageType = 3
MessageType_CLIENT_INFO MessageType = 4
MessageType_CLIENT_INPUT MessageType = 5
MessageType_ACCEL_DEADZONE MessageType = 6
MessageType_OTA_START MessageType = 16
MessageType_OTA_PAYLOAD MessageType = 17
MessageType_OTA_END MessageType = 18
@@ -46,6 +47,7 @@ var (
3: "VERSION",
4: "CLIENT_INFO",
5: "CLIENT_INPUT",
6: "ACCEL_DEADZONE",
16: "OTA_START",
17: "OTA_PAYLOAD",
18: "OTA_END",
@@ -59,6 +61,7 @@ var (
"VERSION": 3,
"CLIENT_INFO": 4,
"CLIENT_INPUT": 5,
"ACCEL_DEADZONE": 6,
"OTA_START": 16,
"OTA_PAYLOAD": 17,
"OTA_END": 18,
@@ -108,6 +111,8 @@ type UartMessage struct {
// *UartMessage_OtaPayload
// *UartMessage_OtaEnd
// *UartMessage_OtaStatus
// *UartMessage_AccelDeadzoneRequest
// *UartMessage_AccelDeadzoneResponse
Payload isUartMessage_Payload `protobuf_oneof:"payload"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -238,6 +243,24 @@ func (x *UartMessage) GetOtaStatus() *OtaStatusPayload {
return nil
}
func (x *UartMessage) GetAccelDeadzoneRequest() *AccelDeadzoneRequest {
if x != nil {
if x, ok := x.Payload.(*UartMessage_AccelDeadzoneRequest); ok {
return x.AccelDeadzoneRequest
}
}
return nil
}
func (x *UartMessage) GetAccelDeadzoneResponse() *AccelDeadzoneResponse {
if x != nil {
if x, ok := x.Payload.(*UartMessage_AccelDeadzoneResponse); ok {
return x.AccelDeadzoneResponse
}
}
return nil
}
type isUartMessage_Payload interface {
isUartMessage_Payload()
}
@@ -278,6 +301,14 @@ type UartMessage_OtaStatus struct {
OtaStatus *OtaStatusPayload `protobuf:"bytes,10,opt,name=ota_status,json=otaStatus,proto3,oneof"`
}
type UartMessage_AccelDeadzoneRequest struct {
AccelDeadzoneRequest *AccelDeadzoneRequest `protobuf:"bytes,11,opt,name=accel_deadzone_request,json=accelDeadzoneRequest,proto3,oneof"`
}
type UartMessage_AccelDeadzoneResponse struct {
AccelDeadzoneResponse *AccelDeadzoneResponse `protobuf:"bytes,12,opt,name=accel_deadzone_response,json=accelDeadzoneResponse,proto3,oneof"`
}
func (*UartMessage_AckPayload) isUartMessage_Payload() {}
func (*UartMessage_EchoPayload) isUartMessage_Payload() {}
@@ -296,6 +327,10 @@ func (*UartMessage_OtaEnd) isUartMessage_Payload() {}
func (*UartMessage_OtaStatus) isUartMessage_Payload() {}
func (*UartMessage_AccelDeadzoneRequest) isUartMessage_Payload() {}
func (*UartMessage_AccelDeadzoneResponse) isUartMessage_Payload() {}
type Ack struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
@@ -676,6 +711,145 @@ func (x *ClientInputResponse) GetClients() []*ClientInput {
return nil
}
// write=false: read deadzone; write=true: apply deadzone (LSB per axis, raw accel units).
// client_id 0 = local BMA456 on this node; >0 = slave id on master; ignored on slave.
// all_clients = true (master only): push deadzone to every registered slave via ESP-NOW.
type AccelDeadzoneRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Write bool `protobuf:"varint,1,opt,name=write,proto3" json:"write,omitempty"`
Deadzone uint32 `protobuf:"varint,2,opt,name=deadzone,proto3" json:"deadzone,omitempty"`
ClientId uint32 `protobuf:"varint,3,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
AllClients bool `protobuf:"varint,4,opt,name=all_clients,json=allClients,proto3" json:"all_clients,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AccelDeadzoneRequest) Reset() {
*x = AccelDeadzoneRequest{}
mi := &file_uart_messages_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AccelDeadzoneRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AccelDeadzoneRequest) ProtoMessage() {}
func (x *AccelDeadzoneRequest) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AccelDeadzoneRequest.ProtoReflect.Descriptor instead.
func (*AccelDeadzoneRequest) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{8}
}
func (x *AccelDeadzoneRequest) GetWrite() bool {
if x != nil {
return x.Write
}
return false
}
func (x *AccelDeadzoneRequest) GetDeadzone() uint32 {
if x != nil {
return x.Deadzone
}
return 0
}
func (x *AccelDeadzoneRequest) GetClientId() uint32 {
if x != nil {
return x.ClientId
}
return 0
}
func (x *AccelDeadzoneRequest) GetAllClients() bool {
if x != nil {
return x.AllClients
}
return false
}
type AccelDeadzoneResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Deadzone uint32 `protobuf:"varint,1,opt,name=deadzone,proto3" json:"deadzone,omitempty"`
ClientId uint32 `protobuf:"varint,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
Success bool `protobuf:"varint,3,opt,name=success,proto3" json:"success,omitempty"`
SlavesUpdated uint32 `protobuf:"varint,4,opt,name=slaves_updated,json=slavesUpdated,proto3" json:"slaves_updated,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AccelDeadzoneResponse) Reset() {
*x = AccelDeadzoneResponse{}
mi := &file_uart_messages_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AccelDeadzoneResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AccelDeadzoneResponse) ProtoMessage() {}
func (x *AccelDeadzoneResponse) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AccelDeadzoneResponse.ProtoReflect.Descriptor instead.
func (*AccelDeadzoneResponse) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{9}
}
func (x *AccelDeadzoneResponse) GetDeadzone() uint32 {
if x != nil {
return x.Deadzone
}
return 0
}
func (x *AccelDeadzoneResponse) GetClientId() uint32 {
if x != nil {
return x.ClientId
}
return 0
}
func (x *AccelDeadzoneResponse) GetSuccess() bool {
if x != nil {
return x.Success
}
return false
}
func (x *AccelDeadzoneResponse) GetSlavesUpdated() uint32 {
if x != nil {
return x.SlavesUpdated
}
return 0
}
type OtaStartPayload struct {
state protoimpl.MessageState `protogen:"open.v1"`
TotalSize uint32 `protobuf:"varint,1,opt,name=total_size,json=totalSize,proto3" json:"total_size,omitempty"`
@@ -686,7 +860,7 @@ type OtaStartPayload struct {
func (x *OtaStartPayload) Reset() {
*x = OtaStartPayload{}
mi := &file_uart_messages_proto_msgTypes[8]
mi := &file_uart_messages_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -698,7 +872,7 @@ func (x *OtaStartPayload) String() string {
func (*OtaStartPayload) ProtoMessage() {}
func (x *OtaStartPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[8]
mi := &file_uart_messages_proto_msgTypes[10]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -711,7 +885,7 @@ func (x *OtaStartPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaStartPayload.ProtoReflect.Descriptor instead.
func (*OtaStartPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{8}
return file_uart_messages_proto_rawDescGZIP(), []int{10}
}
func (x *OtaStartPayload) GetTotalSize() uint32 {
@@ -739,7 +913,7 @@ type OtaPayload struct {
func (x *OtaPayload) Reset() {
*x = OtaPayload{}
mi := &file_uart_messages_proto_msgTypes[9]
mi := &file_uart_messages_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -751,7 +925,7 @@ func (x *OtaPayload) String() string {
func (*OtaPayload) ProtoMessage() {}
func (x *OtaPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[9]
mi := &file_uart_messages_proto_msgTypes[11]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -764,7 +938,7 @@ func (x *OtaPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaPayload.ProtoReflect.Descriptor instead.
func (*OtaPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{9}
return file_uart_messages_proto_rawDescGZIP(), []int{11}
}
func (x *OtaPayload) GetBlockId() uint32 {
@@ -797,7 +971,7 @@ type OtaEndPayload struct {
func (x *OtaEndPayload) Reset() {
*x = OtaEndPayload{}
mi := &file_uart_messages_proto_msgTypes[10]
mi := &file_uart_messages_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -809,7 +983,7 @@ func (x *OtaEndPayload) String() string {
func (*OtaEndPayload) ProtoMessage() {}
func (x *OtaEndPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[10]
mi := &file_uart_messages_proto_msgTypes[12]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -822,7 +996,7 @@ func (x *OtaEndPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaEndPayload.ProtoReflect.Descriptor instead.
func (*OtaEndPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{10}
return file_uart_messages_proto_rawDescGZIP(), []int{12}
}
func (x *OtaEndPayload) GetStatus() uint32 {
@@ -841,7 +1015,7 @@ type OtaStatusPayload struct {
func (x *OtaStatusPayload) Reset() {
*x = OtaStatusPayload{}
mi := &file_uart_messages_proto_msgTypes[11]
mi := &file_uart_messages_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -853,7 +1027,7 @@ func (x *OtaStatusPayload) String() string {
func (*OtaStatusPayload) ProtoMessage() {}
func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message {
mi := &file_uart_messages_proto_msgTypes[11]
mi := &file_uart_messages_proto_msgTypes[13]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -866,7 +1040,7 @@ func (x *OtaStatusPayload) ProtoReflect() protoreflect.Message {
// Deprecated: Use OtaStatusPayload.ProtoReflect.Descriptor instead.
func (*OtaStatusPayload) Descriptor() ([]byte, []int) {
return file_uart_messages_proto_rawDescGZIP(), []int{11}
return file_uart_messages_proto_rawDescGZIP(), []int{13}
}
func (x *OtaStatusPayload) GetStatus() uint32 {
@@ -880,7 +1054,7 @@ var File_uart_messages_proto protoreflect.FileDescriptor
const file_uart_messages_proto_rawDesc = "" +
"\n" +
"\x13uart_messages.proto\x12\x04alox\"\xdc\x04\n" +
"\x13uart_messages.proto\x12\x04alox\"\x87\x06\n" +
"\vUartMessage\x12%\n" +
"\x04type\x18\x01 \x01(\x0e2\x11.alox.MessageTypeR\x04type\x12,\n" +
"\vack_payload\x18\x02 \x01(\v2\t.alox.AckH\x00R\n" +
@@ -895,7 +1069,9 @@ const file_uart_messages_proto_rawDesc = "" +
"\aota_end\x18\t \x01(\v2\x13.alox.OtaEndPayloadH\x00R\x06otaEnd\x127\n" +
"\n" +
"ota_status\x18\n" +
" \x01(\v2\x16.alox.OtaStatusPayloadH\x00R\totaStatusB\t\n" +
" \x01(\v2\x16.alox.OtaStatusPayloadH\x00R\totaStatus\x12R\n" +
"\x16accel_deadzone_request\x18\v \x01(\v2\x1a.alox.AccelDeadzoneRequestH\x00R\x14accelDeadzoneRequest\x12U\n" +
"\x17accel_deadzone_response\x18\f \x01(\v2\x1b.alox.AccelDeadzoneResponseH\x00R\x15accelDeadzoneResponseB\t\n" +
"\apayload\"\x05\n" +
"\x03Ack\"!\n" +
"\vEchoPayload\x12\x12\n" +
@@ -920,7 +1096,18 @@ const file_uart_messages_proto_rawDesc = "" +
"\x06lage_y\x18\x03 \x01(\x02R\x05lageY\x12\x18\n" +
"\abitmask\x18\x04 \x01(\rR\abitmask\"B\n" +
"\x13ClientInputResponse\x12+\n" +
"\aclients\x18\x01 \x03(\v2\x11.alox.ClientInputR\aclients\"O\n" +
"\aclients\x18\x01 \x03(\v2\x11.alox.ClientInputR\aclients\"\x86\x01\n" +
"\x14AccelDeadzoneRequest\x12\x14\n" +
"\x05write\x18\x01 \x01(\bR\x05write\x12\x1a\n" +
"\bdeadzone\x18\x02 \x01(\rR\bdeadzone\x12\x1b\n" +
"\tclient_id\x18\x03 \x01(\rR\bclientId\x12\x1f\n" +
"\vall_clients\x18\x04 \x01(\bR\n" +
"allClients\"\x91\x01\n" +
"\x15AccelDeadzoneResponse\x12\x1a\n" +
"\bdeadzone\x18\x01 \x01(\rR\bdeadzone\x12\x1b\n" +
"\tclient_id\x18\x02 \x01(\rR\bclientId\x12\x18\n" +
"\asuccess\x18\x03 \x01(\bR\asuccess\x12%\n" +
"\x0eslaves_updated\x18\x04 \x01(\rR\rslavesUpdated\"O\n" +
"\x0fOtaStartPayload\x12\x1d\n" +
"\n" +
"total_size\x18\x01 \x01(\rR\ttotalSize\x12\x1d\n" +
@@ -934,14 +1121,15 @@ const file_uart_messages_proto_rawDesc = "" +
"\rOtaEndPayload\x12\x16\n" +
"\x06status\x18\x01 \x01(\rR\x06status\"*\n" +
"\x10OtaStatusPayload\x12\x16\n" +
"\x06status\x18\x01 \x01(\rR\x06status*\xb0\x01\n" +
"\x06status\x18\x01 \x01(\rR\x06status*\xc4\x01\n" +
"\vMessageType\x12\v\n" +
"\aUNKNOWN\x10\x00\x12\a\n" +
"\x03ACK\x10\x01\x12\b\n" +
"\x04ECHO\x10\x02\x12\v\n" +
"\aVERSION\x10\x03\x12\x0f\n" +
"\vCLIENT_INFO\x10\x04\x12\x10\n" +
"\fCLIENT_INPUT\x10\x05\x12\r\n" +
"\fCLIENT_INPUT\x10\x05\x12\x12\n" +
"\x0eACCEL_DEADZONE\x10\x06\x12\r\n" +
"\tOTA_START\x10\x10\x12\x0f\n" +
"\vOTA_PAYLOAD\x10\x11\x12\v\n" +
"\aOTA_END\x10\x12\x12\x0e\n" +
@@ -962,21 +1150,23 @@ func file_uart_messages_proto_rawDescGZIP() []byte {
}
var file_uart_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_uart_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_uart_messages_proto_goTypes = []any{
(MessageType)(0), // 0: alox.MessageType
(*UartMessage)(nil), // 1: alox.UartMessage
(*Ack)(nil), // 2: alox.Ack
(*EchoPayload)(nil), // 3: alox.EchoPayload
(*VersionResponse)(nil), // 4: alox.VersionResponse
(*ClientInfo)(nil), // 5: alox.ClientInfo
(*ClientInfoResponse)(nil), // 6: alox.ClientInfoResponse
(*ClientInput)(nil), // 7: alox.ClientInput
(*ClientInputResponse)(nil), // 8: alox.ClientInputResponse
(*OtaStartPayload)(nil), // 9: alox.OtaStartPayload
(*OtaPayload)(nil), // 10: alox.OtaPayload
(*OtaEndPayload)(nil), // 11: alox.OtaEndPayload
(*OtaStatusPayload)(nil), // 12: alox.OtaStatusPayload
(MessageType)(0), // 0: alox.MessageType
(*UartMessage)(nil), // 1: alox.UartMessage
(*Ack)(nil), // 2: alox.Ack
(*EchoPayload)(nil), // 3: alox.EchoPayload
(*VersionResponse)(nil), // 4: alox.VersionResponse
(*ClientInfo)(nil), // 5: alox.ClientInfo
(*ClientInfoResponse)(nil), // 6: alox.ClientInfoResponse
(*ClientInput)(nil), // 7: alox.ClientInput
(*ClientInputResponse)(nil), // 8: alox.ClientInputResponse
(*AccelDeadzoneRequest)(nil), // 9: alox.AccelDeadzoneRequest
(*AccelDeadzoneResponse)(nil), // 10: alox.AccelDeadzoneResponse
(*OtaStartPayload)(nil), // 11: alox.OtaStartPayload
(*OtaPayload)(nil), // 12: alox.OtaPayload
(*OtaEndPayload)(nil), // 13: alox.OtaEndPayload
(*OtaStatusPayload)(nil), // 14: alox.OtaStatusPayload
}
var file_uart_messages_proto_depIdxs = []int32{
0, // 0: alox.UartMessage.type:type_name -> alox.MessageType
@@ -985,17 +1175,19 @@ var file_uart_messages_proto_depIdxs = []int32{
4, // 3: alox.UartMessage.version_response:type_name -> alox.VersionResponse
6, // 4: alox.UartMessage.client_info_response:type_name -> alox.ClientInfoResponse
8, // 5: alox.UartMessage.client_input_response:type_name -> alox.ClientInputResponse
9, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload
10, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload
11, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload
12, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload
5, // 10: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo
7, // 11: alox.ClientInputResponse.clients:type_name -> alox.ClientInput
12, // [12:12] is the sub-list for method output_type
12, // [12:12] is the sub-list for method input_type
12, // [12:12] is the sub-list for extension type_name
12, // [12:12] is the sub-list for extension extendee
0, // [0:12] is the sub-list for field type_name
11, // 6: alox.UartMessage.ota_start:type_name -> alox.OtaStartPayload
12, // 7: alox.UartMessage.ota_payload:type_name -> alox.OtaPayload
13, // 8: alox.UartMessage.ota_end:type_name -> alox.OtaEndPayload
14, // 9: alox.UartMessage.ota_status:type_name -> alox.OtaStatusPayload
9, // 10: alox.UartMessage.accel_deadzone_request:type_name -> alox.AccelDeadzoneRequest
10, // 11: alox.UartMessage.accel_deadzone_response:type_name -> alox.AccelDeadzoneResponse
5, // 12: alox.ClientInfoResponse.clients:type_name -> alox.ClientInfo
7, // 13: alox.ClientInputResponse.clients:type_name -> alox.ClientInput
14, // [14:14] is the sub-list for method output_type
14, // [14:14] is the sub-list for method input_type
14, // [14:14] is the sub-list for extension type_name
14, // [14:14] is the sub-list for extension extendee
0, // [0:14] is the sub-list for field type_name
}
func init() { file_uart_messages_proto_init() }
@@ -1013,6 +1205,8 @@ func file_uart_messages_proto_init() {
(*UartMessage_OtaPayload)(nil),
(*UartMessage_OtaEnd)(nil),
(*UartMessage_OtaStatus)(nil),
(*UartMessage_AccelDeadzoneRequest)(nil),
(*UartMessage_AccelDeadzoneResponse)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -1020,7 +1214,7 @@ func file_uart_messages_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_uart_messages_proto_rawDesc), len(file_uart_messages_proto_rawDesc)),
NumEnums: 1,
NumMessages: 12,
NumMessages: 14,
NumExtensions: 0,
NumServices: 0,
},