From 3340214e6409a8b8ba156b0760eed766bffb7b71 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 11 Dec 2017 00:25:12 +0100 Subject: proto3 --- elegoo/elegoo.ino | 21 +++++---------------- elegoo/elegoo.pb.c | 26 +++++++++++++------------- elegoo/elegoo.pb.h | 22 +++++----------------- 3 files changed, 23 insertions(+), 46 deletions(-) (limited to 'elegoo') diff --git a/elegoo/elegoo.ino b/elegoo/elegoo.ino index 62d7d62..e354262 100644 --- a/elegoo/elegoo.ino +++ b/elegoo/elegoo.ino @@ -56,19 +56,19 @@ void onPacket(const uint8_t* buf, size_t size) { pb_istream_t istream = pb_istream_from_buffer(buf, size); pb_decode_delimited(&istream, Command_fields, &cmd); - if (cmd.has_SpeedR) { + if (cmd.SpeedR > 0) { motorR(cmd.SpeedR); } - if (cmd.has_SpeedL) { + if (cmd.SpeedL > 0) { motorL(cmd.SpeedL); } - if (cmd.has_Stop) { + if (cmd.Stop) { stop(); } - if (cmd.has_Direction) { + if (cmd.Direction > 0) { servo.write(cmd.Direction); } - if (cmd.has_StopAfter) { + if (cmd.StopAfter > 0) { timer.after(cmd.StopAfter, stop); } } @@ -79,28 +79,17 @@ void events() { Events evt = Events_init_zero; evt.Distance = readDistance(); - evt.has_Distance = evt.Distance > 0; - evt.SensorR = digitalRead(SR); - evt.has_SensorR = true; - evt.SensorC = digitalRead(SC); - evt.has_SensorC = true; - evt.SensorL = digitalRead(SL); - evt.has_SensorL = true; if (irrecv.decode(&ir)) { evt.KeyPress = ir.value; - evt.has_KeyPress = ir.bits > 0; irrecv.resume(); } evt.Direction = servo.read(); - evt.has_Direction = true; - evt.Time = millis(); - evt.has_Time = true; pb_ostream_t ostream = pb_ostream_from_buffer(buf, sizeof(buf)); pb_encode_delimited(&ostream, Events_fields, &evt); diff --git a/elegoo/elegoo.pb.c b/elegoo/elegoo.pb.c index 5cb5e7a..3545021 100644 --- a/elegoo/elegoo.pb.c +++ b/elegoo/elegoo.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.6 at Sun Aug 27 00:49:15 2017. */ +/* Generated by nanopb-0.3.9 at Mon Dec 11 00:21:17 2017. */ #include "elegoo.pb.h" @@ -11,22 +11,22 @@ const pb_field_t Command_fields[6] = { - PB_FIELD( 1, SINT32 , OPTIONAL, STATIC , FIRST, Command, SpeedR, SpeedR, 0), - PB_FIELD( 2, SINT32 , OPTIONAL, STATIC , OTHER, Command, SpeedL, SpeedR, 0), - PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, Command, Stop, SpeedL, 0), - PB_FIELD( 4, UINT32 , OPTIONAL, STATIC , OTHER, Command, Direction, Stop, 0), - PB_FIELD( 5, UINT32 , OPTIONAL, STATIC , OTHER, Command, StopAfter, Direction, 0), + PB_FIELD( 1, SINT32 , SINGULAR, STATIC , FIRST, Command, SpeedR, SpeedR, 0), + PB_FIELD( 2, SINT32 , SINGULAR, STATIC , OTHER, Command, SpeedL, SpeedR, 0), + PB_FIELD( 3, BOOL , SINGULAR, STATIC , OTHER, Command, Stop, SpeedL, 0), + PB_FIELD( 4, UINT32 , SINGULAR, STATIC , OTHER, Command, Direction, Stop, 0), + PB_FIELD( 5, UINT32 , SINGULAR, STATIC , OTHER, Command, StopAfter, Direction, 0), PB_LAST_FIELD }; const pb_field_t Events_fields[8] = { - PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, Events, Distance, Distance, 0), - PB_FIELD( 2, SINT32 , OPTIONAL, STATIC , OTHER, Events, Direction, Distance, 0), - PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, Events, SensorR, Direction, 0), - PB_FIELD( 4, BOOL , OPTIONAL, STATIC , OTHER, Events, SensorC, SensorR, 0), - PB_FIELD( 5, BOOL , OPTIONAL, STATIC , OTHER, Events, SensorL, SensorC, 0), - PB_FIELD( 6, UINT32 , OPTIONAL, STATIC , OTHER, Events, KeyPress, SensorL, 0), - PB_FIELD( 7, UINT32 , OPTIONAL, STATIC , OTHER, Events, Time, KeyPress, 0), + PB_FIELD( 1, UINT32 , SINGULAR, STATIC , FIRST, Events, Distance, Distance, 0), + PB_FIELD( 2, SINT32 , SINGULAR, STATIC , OTHER, Events, Direction, Distance, 0), + PB_FIELD( 3, BOOL , SINGULAR, STATIC , OTHER, Events, SensorR, Direction, 0), + PB_FIELD( 4, BOOL , SINGULAR, STATIC , OTHER, Events, SensorC, SensorR, 0), + PB_FIELD( 5, BOOL , SINGULAR, STATIC , OTHER, Events, SensorL, SensorC, 0), + PB_FIELD( 6, UINT32 , SINGULAR, STATIC , OTHER, Events, KeyPress, SensorL, 0), + PB_FIELD( 7, UINT32 , SINGULAR, STATIC , OTHER, Events, Time, KeyPress, 0), PB_LAST_FIELD }; diff --git a/elegoo/elegoo.pb.h b/elegoo/elegoo.pb.h index 3510675..05d023c 100644 --- a/elegoo/elegoo.pb.h +++ b/elegoo/elegoo.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.6 at Sun Aug 27 00:49:15 2017. */ +/* Generated by nanopb-0.3.9 at Mon Dec 11 00:21:17 2017. */ #ifndef PB_ELEGOO_PB_H_INCLUDED #define PB_ELEGOO_PB_H_INCLUDED @@ -16,33 +16,21 @@ extern "C" { /* Struct definitions */ typedef struct _Command { - bool has_SpeedR; int32_t SpeedR; - bool has_SpeedL; int32_t SpeedL; - bool has_Stop; bool Stop; - bool has_Direction; uint32_t Direction; - bool has_StopAfter; uint32_t StopAfter; /* @@protoc_insertion_point(struct:Command) */ } Command; typedef struct _Events { - bool has_Distance; uint32_t Distance; - bool has_Direction; int32_t Direction; - bool has_SensorR; bool SensorR; - bool has_SensorC; bool SensorC; - bool has_SensorL; bool SensorL; - bool has_KeyPress; uint32_t KeyPress; - bool has_Time; uint32_t Time; /* @@protoc_insertion_point(struct:Events) */ } Events; @@ -50,10 +38,10 @@ typedef struct _Events { /* Default values for struct fields */ /* Initializer values for message structs */ -#define Command_init_default {false, 0, false, 0, false, 0, false, 0, false, 0} -#define Events_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} -#define Command_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0} -#define Events_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define Command_init_default {0, 0, 0, 0, 0} +#define Events_init_default {0, 0, 0, 0, 0, 0, 0} +#define Command_init_zero {0, 0, 0, 0, 0} +#define Events_init_zero {0, 0, 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define Command_SpeedR_tag 1 -- cgit v1.2.3