aboutsummaryrefslogtreecommitdiff
path: root/car/elegoo
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-27 00:49:24 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-27 00:49:24 +0200
commit64a552f7a69e20c174f929c5d4e800aa24b480f3 (patch)
tree2e27e65e623021904fcce43b2382ecd7d95e6baa /car/elegoo
parente4cabee7b53ba8f71826b79cc09b3ecba1a02f13 (diff)
Make go getable
Diffstat (limited to 'car/elegoo')
-rw-r--r--car/elegoo/elegoo.pb.go167
-rw-r--r--car/elegoo/elegoo.proto23
-rw-r--r--car/elegoo/main.go143
3 files changed, 0 insertions, 333 deletions
diff --git a/car/elegoo/elegoo.pb.go b/car/elegoo/elegoo.pb.go
deleted file mode 100644
index 3a367e0..0000000
--- a/car/elegoo/elegoo.pb.go
+++ /dev/null
@@ -1,167 +0,0 @@
-// Code generated by protoc-gen-go. DO NOT EDIT.
-// source: elegoo.proto
-
-/*
-Package main is a generated protocol buffer package.
-
-It is generated from these files:
- elegoo.proto
-
-It has these top-level messages:
- Command
- Events
-*/
-package main
-
-import proto "github.com/golang/protobuf/proto"
-import fmt "fmt"
-import math "math"
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = proto.Marshal
-var _ = fmt.Errorf
-var _ = math.Inf
-
-// This is a compile-time assertion to ensure that this generated file
-// is compatible with the proto package it is being compiled against.
-// A compilation error at this line likely means your copy of the
-// proto package needs to be updated.
-const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
-
-type Command struct {
- SpeedR int32 `protobuf:"zigzag32,1,opt,name=SpeedR" json:"SpeedR,omitempty"`
- SpeedL int32 `protobuf:"zigzag32,2,opt,name=SpeedL" json:"SpeedL,omitempty"`
- Stop bool `protobuf:"varint,3,opt,name=Stop" json:"Stop,omitempty"`
- Direction uint32 `protobuf:"varint,4,opt,name=Direction" json:"Direction,omitempty"`
- StopAfter uint32 `protobuf:"varint,5,opt,name=StopAfter" json:"StopAfter,omitempty"`
-}
-
-func (m *Command) Reset() { *m = Command{} }
-func (m *Command) String() string { return proto.CompactTextString(m) }
-func (*Command) ProtoMessage() {}
-func (*Command) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
-
-func (m *Command) GetSpeedR() int32 {
- if m != nil {
- return m.SpeedR
- }
- return 0
-}
-
-func (m *Command) GetSpeedL() int32 {
- if m != nil {
- return m.SpeedL
- }
- return 0
-}
-
-func (m *Command) GetStop() bool {
- if m != nil {
- return m.Stop
- }
- return false
-}
-
-func (m *Command) GetDirection() uint32 {
- if m != nil {
- return m.Direction
- }
- return 0
-}
-
-func (m *Command) GetStopAfter() uint32 {
- if m != nil {
- return m.StopAfter
- }
- return 0
-}
-
-type Events struct {
- Distance uint32 `protobuf:"varint,1,opt,name=Distance" json:"Distance,omitempty"`
- Direction int32 `protobuf:"zigzag32,2,opt,name=Direction" json:"Direction,omitempty"`
- SensorR bool `protobuf:"varint,3,opt,name=SensorR" json:"SensorR,omitempty"`
- SensorC bool `protobuf:"varint,4,opt,name=SensorC" json:"SensorC,omitempty"`
- SensorL bool `protobuf:"varint,5,opt,name=SensorL" json:"SensorL,omitempty"`
- KeyPress uint32 `protobuf:"varint,6,opt,name=KeyPress" json:"KeyPress,omitempty"`
- Time uint32 `protobuf:"varint,7,opt,name=Time" json:"Time,omitempty"`
-}
-
-func (m *Events) Reset() { *m = Events{} }
-func (m *Events) String() string { return proto.CompactTextString(m) }
-func (*Events) ProtoMessage() {}
-func (*Events) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
-
-func (m *Events) GetDistance() uint32 {
- if m != nil {
- return m.Distance
- }
- return 0
-}
-
-func (m *Events) GetDirection() int32 {
- if m != nil {
- return m.Direction
- }
- return 0
-}
-
-func (m *Events) GetSensorR() bool {
- if m != nil {
- return m.SensorR
- }
- return false
-}
-
-func (m *Events) GetSensorC() bool {
- if m != nil {
- return m.SensorC
- }
- return false
-}
-
-func (m *Events) GetSensorL() bool {
- if m != nil {
- return m.SensorL
- }
- return false
-}
-
-func (m *Events) GetKeyPress() uint32 {
- if m != nil {
- return m.KeyPress
- }
- return 0
-}
-
-func (m *Events) GetTime() uint32 {
- if m != nil {
- return m.Time
- }
- return 0
-}
-
-func init() {
- proto.RegisterType((*Command)(nil), "Command")
- proto.RegisterType((*Events)(nil), "Events")
-}
-
-func init() { proto.RegisterFile("elegoo.proto", fileDescriptor0) }
-
-var fileDescriptor0 = []byte{
- // 234 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0xb1, 0x4e, 0xc3, 0x30,
- 0x10, 0x86, 0x65, 0x08, 0x4e, 0x39, 0xd1, 0x01, 0x0f, 0xe8, 0x84, 0x18, 0xa2, 0x4e, 0x99, 0x58,
- 0x78, 0x02, 0x48, 0x99, 0xc8, 0x80, 0x1c, 0x26, 0xb6, 0xd0, 0x1e, 0xc8, 0x12, 0xf1, 0x45, 0xb6,
- 0x85, 0xc4, 0x23, 0xf0, 0x56, 0x3c, 0x1a, 0xb2, 0xd3, 0x3a, 0x61, 0xbb, 0xff, 0xff, 0x2c, 0xdd,
- 0xe7, 0x83, 0x0b, 0xfa, 0xa4, 0x0f, 0xe6, 0xdb, 0xd1, 0x71, 0xe0, 0xcd, 0x8f, 0x80, 0xb2, 0xe1,
- 0x61, 0xe8, 0xed, 0x5e, 0x5d, 0x81, 0xec, 0x46, 0xa2, 0xbd, 0x46, 0x51, 0x89, 0xfa, 0x52, 0x1f,
- 0x52, 0xee, 0x5b, 0x3c, 0x59, 0xf4, 0xad, 0x52, 0x50, 0x74, 0x81, 0x47, 0x3c, 0xad, 0x44, 0xbd,
- 0xd2, 0x69, 0x56, 0x37, 0x70, 0xbe, 0x35, 0x8e, 0x76, 0xc1, 0xb0, 0xc5, 0xa2, 0x12, 0xf5, 0x5a,
- 0xcf, 0x45, 0xa4, 0xf1, 0xd5, 0xfd, 0x7b, 0x20, 0x87, 0x67, 0x13, 0xcd, 0xc5, 0xe6, 0x57, 0x80,
- 0x7c, 0xfc, 0x22, 0x1b, 0xbc, 0xba, 0x86, 0xd5, 0xd6, 0xf8, 0xd0, 0xdb, 0x1d, 0x25, 0x99, 0xb5,
- 0xce, 0xf9, 0xff, 0x8a, 0xc9, 0x68, 0xb1, 0x02, 0xa1, 0xec, 0xc8, 0x7a, 0x76, 0xfa, 0xe0, 0x75,
- 0x8c, 0x33, 0x69, 0x92, 0x58, 0x26, 0xcd, 0x4c, 0xda, 0x24, 0x95, 0x49, 0x1b, 0x3d, 0x9e, 0xe8,
- 0xfb, 0xd9, 0x91, 0xf7, 0x28, 0x27, 0x8f, 0x63, 0x8e, 0xdf, 0x7f, 0x31, 0x03, 0x61, 0x99, 0xfa,
- 0x34, 0x3f, 0xc8, 0xd7, 0x62, 0xe8, 0x8d, 0x7d, 0x93, 0xe9, 0xba, 0x77, 0x7f, 0x01, 0x00, 0x00,
- 0xff, 0xff, 0x22, 0x73, 0x73, 0x8b, 0x6d, 0x01, 0x00, 0x00,
-}
diff --git a/car/elegoo/elegoo.proto b/car/elegoo/elegoo.proto
deleted file mode 100644
index 7cfd826..0000000
--- a/car/elegoo/elegoo.proto
+++ /dev/null
@@ -1,23 +0,0 @@
-syntax = "proto3";
-
-
-
-option go_package = "main";
-
-message Command {
- sint32 SpeedR = 1; // -255 .. +255
- sint32 SpeedL = 2; // -255 .. +255
- bool Stop = 3;
- uint32 Direction = 4; // deg: 0 right .. 180 left
- uint32 StopAfter = 5; // milliseconds
-}
-
-message Events {
- uint32 Distance = 1; // cm
- sint32 Direction = 2; // deg
- bool SensorR = 3;
- bool SensorC = 4;
- bool SensorL = 5;
- uint32 KeyPress = 6;
- uint32 Time = 7; // milliseconds
-}
diff --git a/car/elegoo/main.go b/car/elegoo/main.go
deleted file mode 100644
index 7e5f6e3..0000000
--- a/car/elegoo/main.go
+++ /dev/null
@@ -1,143 +0,0 @@
-package main
-
-//go:generate sh -c "protoc --go_out=. --nanopb_out=.. *.proto"
-
-import (
- "bufio"
- "io"
- "log"
-
- "github.com/dim13/cobs"
- "github.com/golang/protobuf/proto"
- "github.com/tarm/serial"
-)
-
-func Write(w io.Writer, pb proto.Message) error {
- buf := new(proto.Buffer)
- err := buf.EncodeMessage(pb)
- if err != nil {
- return err
- }
- block := cobs.Encode(buf.Bytes())
- _, err = w.Write(block)
- return err
-}
-
-func Read(buf *bufio.Reader, pb proto.Message) error {
- block, err := buf.ReadBytes(0)
- if err != nil {
- return err
- }
- block = cobs.Decode(block)
- return proto.NewBuffer(block).DecodeMessage(pb)
-}
-
-// /dev/cu.Elegoo-DevB
-// /dev/cu.usbmodem1421
-// /dev/cu.usbmodem1411
-
-func Reader(r io.Reader) chan *Events {
- c := make(chan *Events)
- buf := bufio.NewReader(r)
- go func() {
- for {
- evt := &Events{}
- if err := Read(buf, evt); err != nil {
- if err == io.ErrUnexpectedEOF {
- continue
- }
- log.Println("ERR", err)
- return
- }
- c <- evt
- }
- }()
- return c
-}
-
-func Writer(w io.Writer) chan *Command {
- c := make(chan *Command)
- go func() {
- for cmd := range c {
- log.Println("send", cmd)
- Write(w, cmd)
- }
- }()
- return c
-}
-
-func main() {
- c := &serial.Config{
- //Name: "/dev/tty.usbmodem1421",
- //Name: "/dev/tty.usbmodem1411",
- Name: "/dev/tty.Elegoo-DevB",
- Baud: 57600,
- }
- s, err := serial.OpenPort(c)
- if err != nil {
- log.Fatal(err)
- }
- defer s.Close()
-
- w := Writer(s)
-
- w <- &Command{Direction: 80}
-
- for e := range Reader(s) {
- log.Println("event", e)
- if e.SensorC || e.Distance < 20 {
- w <- &Command{Stop: true}
- }
- }
-
- /* log.Println("send -45")
- time.Sleep(3 * time.Second)
- Write(s, &Command{Direction: 5})
-
- log.Println("send +45")
- time.Sleep(3 * time.Second)
- Write(s, &Command{Direction: 175})
-
- log.Println("send +0")
- time.Sleep(3 * time.Second)
- Write(s, &Command{Direction: 90})
- */
-
- /* log.Println("send motor")
- Write(s, &Command{SpeedL: 200, SpeedR: 200, StopAfter: 1000})
- time.Sleep(time.Second)
-
- log.Println("send motor turn")
- time.Sleep(time.Second)
- Write(s, &Command{SpeedL: -250, SpeedR: 250, StopAfter: 500})
-
- log.Println("send motor turn")
- time.Sleep(time.Second)
- Write(s, &Command{SpeedL: 250, SpeedR: -250, StopAfter: 500})
- */
-
- /* MOTOR
- cmd.SpeedL = 200
- cmd.SpeedR = 0
- cmd.Stop = false
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 0
- cmd.Stop = true
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 200
- cmd.Stop = false
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 0
- cmd.Stop = true
- Write(s, cmd)
- */
-}