aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-20 22:44:22 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-20 22:44:22 +0200
commit16ebef12d25b8174d387f6c4f7cfa97eb2b26089 (patch)
tree5a5150ac50faa8fc1754ba05a555bda151933d3b
parente913a1a8fb468a5b28501234e4358e4cc01e4e8d (diff)
Add KeyPress
-rw-r--r--car/car.ino54
-rw-r--r--car/elegoo.pb.c5
-rw-r--r--car/elegoo.pb.h13
-rw-r--r--car/elegoo/elegoo.pb.go31
-rw-r--r--car/elegoo/elegoo.proto1
5 files changed, 38 insertions, 66 deletions
diff --git a/car/car.ino b/car/car.ino
index b87a3d4..a0c6f3c 100644
--- a/car/car.ino
+++ b/car/car.ino
@@ -59,56 +59,13 @@ void look(int deg) {
#define lookleft(deg) do look( deg); while (0)
#define lookright(deg) do look(-deg); while (0)
-int sensor() {
- int s1 = digitalRead(S1);
- int s2 = digitalRead(S2);
- int s3 = digitalRead(S3);
- return s1 | (s2 << 1) | (s3 << 2);
-}
-
-void ultra() {
- if (distance() > dist) {
- forward(velo);
- return;
- }
- stop();
- lookleft(60);
- if (distance() > dist) {
- toleft(velo);
- lookahead();
- return;
- }
- lookright(60);
- if (distance() > dist) {
- toright(velo);
- lookahead();
- return;
- }
-}
-void ir() {
- decode_results results;
+int ir() {
+ decode_results results = {};
if (irrecv.decode(&results)) {
- switch (results.value) {
- case KeyUp:
- forward(velo);
- break;
- case KeyDown:
- backward(velo);
- break;
- case KeyLeft:
- toleft(velo);
- break;
- case KeyRight:
- toright(velo);
- break;
- case KeyOk:
- stop();
- break;
- }
irrecv.resume();
- delay(150);
}
+ return results.value;
}
void setup() {
@@ -158,9 +115,10 @@ void loop() {
evt.SensorC = digitalRead(S3);
evt.has_SensorC = true;
+ evt.KeyPress = ir();
+ evt.has_KeyPress = evt.KeyPress != 0;
+
pb_encode_delimited(&ostream, Event_fields, &evt);
delay(1000);
- //ultra();
- ir();
}
diff --git a/car/elegoo.pb.c b/car/elegoo.pb.c
index 73a2267..9c450b9 100644
--- a/car/elegoo.pb.c
+++ b/car/elegoo.pb.c
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
-/* Generated by nanopb-0.3.6 at Sun Aug 20 17:58:26 2017. */
+/* Generated by nanopb-0.3.6 at Sun Aug 20 22:42:38 2017. */
#include "elegoo.pb.h"
@@ -17,11 +17,12 @@ const pb_field_t Command_fields[4] = {
PB_LAST_FIELD
};
-const pb_field_t Event_fields[5] = {
+const pb_field_t Event_fields[6] = {
PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, Event, Distance, Distance, 0),
PB_FIELD( 2, BOOL , OPTIONAL, STATIC , OTHER, Event, SensorA, Distance, 0),
PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, Event, SensorB, SensorA, 0),
PB_FIELD( 4, BOOL , OPTIONAL, STATIC , OTHER, Event, SensorC, SensorB, 0),
+ PB_FIELD( 5, UINT32 , OPTIONAL, STATIC , OTHER, Event, KeyPress, SensorC, 0),
PB_LAST_FIELD
};
diff --git a/car/elegoo.pb.h b/car/elegoo.pb.h
index 7c8e5b2..d353a56 100644
--- a/car/elegoo.pb.h
+++ b/car/elegoo.pb.h
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
-/* Generated by nanopb-0.3.6 at Sun Aug 20 17:58:26 2017. */
+/* Generated by nanopb-0.3.6 at Sun Aug 20 22:42:38 2017. */
#ifndef PB_ELEGOO_PB_H_INCLUDED
#define PB_ELEGOO_PB_H_INCLUDED
@@ -34,6 +34,8 @@ typedef struct _Event {
bool SensorB;
bool has_SensorC;
bool SensorC;
+ bool has_KeyPress;
+ uint32_t KeyPress;
/* @@protoc_insertion_point(struct:Event) */
} Event;
@@ -41,9 +43,9 @@ typedef struct _Event {
/* Initializer values for message structs */
#define Command_init_default {false, 0, false, 0, false, 0}
-#define Event_init_default {false, 0, false, 0, false, 0, false, 0}
+#define Event_init_default {false, 0, false, 0, false, 0, false, 0, false, 0}
#define Command_init_zero {false, 0, false, 0, false, 0}
-#define Event_init_zero {false, 0, false, 0, false, 0, false, 0}
+#define Event_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0}
/* Field tags (for use in manual encoding/decoding) */
#define Command_LeftSpeed_tag 1
@@ -53,14 +55,15 @@ typedef struct _Event {
#define Event_SensorA_tag 2
#define Event_SensorB_tag 3
#define Event_SensorC_tag 4
+#define Event_KeyPress_tag 5
/* Struct field encoding specification for nanopb */
extern const pb_field_t Command_fields[4];
-extern const pb_field_t Event_fields[5];
+extern const pb_field_t Event_fields[6];
/* Maximum encoded size of messages (where known) */
#define Command_size 33
-#define Event_size 17
+#define Event_size 23
/* Message IDs (where set with "msgid" option) */
#ifdef PB_MSGID
diff --git a/car/elegoo/elegoo.pb.go b/car/elegoo/elegoo.pb.go
index 01de1cf..e07627e 100644
--- a/car/elegoo/elegoo.pb.go
+++ b/car/elegoo/elegoo.pb.go
@@ -61,10 +61,11 @@ func (m *Command) GetTurnHead() int32 {
}
type Event struct {
- Distance int32 `protobuf:"varint,1,opt,name=Distance" json:"Distance,omitempty"`
- SensorA bool `protobuf:"varint,2,opt,name=SensorA" json:"SensorA,omitempty"`
- SensorB bool `protobuf:"varint,3,opt,name=SensorB" json:"SensorB,omitempty"`
- SensorC bool `protobuf:"varint,4,opt,name=SensorC" json:"SensorC,omitempty"`
+ Distance int32 `protobuf:"varint,1,opt,name=Distance" json:"Distance,omitempty"`
+ SensorA bool `protobuf:"varint,2,opt,name=SensorA" json:"SensorA,omitempty"`
+ SensorB bool `protobuf:"varint,3,opt,name=SensorB" json:"SensorB,omitempty"`
+ SensorC bool `protobuf:"varint,4,opt,name=SensorC" json:"SensorC,omitempty"`
+ KeyPress uint32 `protobuf:"varint,5,opt,name=KeyPress" json:"KeyPress,omitempty"`
}
func (m *Event) Reset() { *m = Event{} }
@@ -100,6 +101,13 @@ func (m *Event) GetSensorC() bool {
return false
}
+func (m *Event) GetKeyPress() uint32 {
+ if m != nil {
+ return m.KeyPress
+ }
+ return 0
+}
+
func init() {
proto.RegisterType((*Command)(nil), "Command")
proto.RegisterType((*Event)(nil), "Event")
@@ -108,16 +116,17 @@ func init() {
func init() { proto.RegisterFile("elegoo.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
- // 172 bytes of a gzipped FileDescriptorProto
+ // 192 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xcd, 0x49, 0x4d,
0xcf, 0xcf, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x57, 0x4a, 0xe6, 0x62, 0x77, 0xce, 0xcf, 0xcd,
0x4d, 0xcc, 0x4b, 0x11, 0x92, 0xe1, 0xe2, 0xf4, 0x49, 0x4d, 0x2b, 0x09, 0x2e, 0x48, 0x4d, 0x4d,
0x91, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x0d, 0x42, 0x08, 0x08, 0xc9, 0x71, 0x71, 0x05, 0x65, 0xa6,
0x67, 0x40, 0xa5, 0x99, 0xc0, 0xd2, 0x48, 0x22, 0x42, 0x52, 0x5c, 0x1c, 0x21, 0xa5, 0x45, 0x79,
- 0x1e, 0xa9, 0x89, 0x29, 0x12, 0xcc, 0x60, 0x59, 0x38, 0x5f, 0xa9, 0x90, 0x8b, 0xd5, 0xb5, 0x2c,
- 0x35, 0xaf, 0x04, 0xa4, 0xc8, 0x25, 0xb3, 0xb8, 0x24, 0x31, 0x2f, 0x39, 0x15, 0x6a, 0x03, 0x9c,
- 0x2f, 0x24, 0xc1, 0xc5, 0x1e, 0x9c, 0x9a, 0x57, 0x9c, 0x5f, 0xe4, 0x08, 0x36, 0x9d, 0x23, 0x08,
- 0xc6, 0x45, 0xc8, 0x38, 0x81, 0x4d, 0x86, 0xcb, 0x38, 0x21, 0x64, 0x9c, 0x25, 0x58, 0x90, 0x65,
- 0x9c, 0x9d, 0xd8, 0xa2, 0x58, 0x72, 0x13, 0x33, 0xf3, 0x92, 0xd8, 0xc0, 0xde, 0x34, 0x06, 0x04,
- 0x00, 0x00, 0xff, 0xff, 0xdc, 0x14, 0x3e, 0x06, 0xf6, 0x00, 0x00, 0x00,
+ 0x1e, 0xa9, 0x89, 0x29, 0x12, 0xcc, 0x60, 0x59, 0x38, 0x5f, 0xa9, 0x97, 0x91, 0x8b, 0xd5, 0xb5,
+ 0x2c, 0x35, 0xaf, 0x04, 0xa4, 0xca, 0x25, 0xb3, 0xb8, 0x24, 0x31, 0x2f, 0x39, 0x15, 0x6a, 0x05,
+ 0x9c, 0x2f, 0x24, 0xc1, 0xc5, 0x1e, 0x9c, 0x9a, 0x57, 0x9c, 0x5f, 0xe4, 0x08, 0x36, 0x9e, 0x23,
+ 0x08, 0xc6, 0x45, 0xc8, 0x38, 0x81, 0x8d, 0x86, 0xcb, 0x38, 0x21, 0x64, 0x9c, 0x25, 0x58, 0x90,
+ 0x65, 0x9c, 0x41, 0x36, 0x79, 0xa7, 0x56, 0x06, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0xb0, 0x2a, 0x30,
+ 0x6a, 0xf0, 0x06, 0xc1, 0xf9, 0x4e, 0x6c, 0x51, 0x2c, 0xb9, 0x89, 0x99, 0x79, 0x49, 0x6c, 0xe0,
+ 0x30, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x2f, 0x3b, 0x79, 0x13, 0x01, 0x00, 0x00,
}
diff --git a/car/elegoo/elegoo.proto b/car/elegoo/elegoo.proto
index 703ac71..2915a11 100644
--- a/car/elegoo/elegoo.proto
+++ b/car/elegoo/elegoo.proto
@@ -13,4 +13,5 @@ message Event {
bool SensorA = 2;
bool SensorB = 3;
bool SensorC = 4;
+ uint32 KeyPress = 5;
}