Initial design of protocol to allow setup of display and control of LEDs
This commit is contained in:
52
src/main/java/test/TM1638.java
Normal file
52
src/main/java/test/TM1638.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import tm1638.Tm1638.Color;
|
||||||
|
import tm1638.Tm1638.Command;
|
||||||
|
import tm1638.Tm1638.Construct;
|
||||||
|
import tm1638.Tm1638.Command.Type;
|
||||||
|
import tm1638.Tm1638.Ping;
|
||||||
|
import tm1638.Tm1638.SetLed;
|
||||||
|
|
||||||
|
public class TM1638 {
|
||||||
|
protected Arduino arduino;
|
||||||
|
protected Command command;
|
||||||
|
protected OutputStream outputStream;
|
||||||
|
|
||||||
|
public TM1638(Arduino arduino) throws IOException {
|
||||||
|
this.arduino = arduino;
|
||||||
|
outputStream = arduino.getOutputStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ping(int id) throws IOException {
|
||||||
|
command = Command.newBuilder()
|
||||||
|
.setType(Type.PING)
|
||||||
|
.setPing(Ping.newBuilder()
|
||||||
|
.setId(id)).build();
|
||||||
|
command.writeDelimitedTo(outputStream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLed(Color color, int pos) throws IOException {
|
||||||
|
command = Command.newBuilder()
|
||||||
|
.setType(Type.SET_LED)
|
||||||
|
.setSetLed(
|
||||||
|
SetLed.newBuilder()
|
||||||
|
.setColor(color)
|
||||||
|
.setPos(pos).build()).build();
|
||||||
|
command.writeDelimitedTo(outputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void construct(int dataPin, int clockPin, int strobePin) throws IOException {
|
||||||
|
command = Command.newBuilder()
|
||||||
|
.setType(Type.CONSTRUCT)
|
||||||
|
.setConstruct(
|
||||||
|
Construct.newBuilder()
|
||||||
|
.setDataPin(dataPin)
|
||||||
|
.setClockPin(clockPin)
|
||||||
|
.setStrobePin(strobePin).build()).build();
|
||||||
|
command.writeDelimitedTo(outputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import tm1638.Tm1638.Color;
|
||||||
|
|
||||||
import beerduino.Beerduino.Echo;
|
import beerduino.Beerduino.Echo;
|
||||||
import beerduino.Beerduino.Ping;
|
|
||||||
|
|
||||||
public class Test implements EchoListener {
|
public class Test implements EchoListener {
|
||||||
public static void main(String[] argv) {
|
public static void main(String[] argv) {
|
||||||
@@ -18,12 +16,12 @@ public class Test implements EchoListener {
|
|||||||
Arduino arduino = new Arduino();
|
Arduino arduino = new Arduino();
|
||||||
arduino.connect();
|
arduino.connect();
|
||||||
arduino.addListener(this);
|
arduino.addListener(this);
|
||||||
OutputStream outputStream = arduino.getOutputStream();
|
|
||||||
int i = 123;
|
int i = 123;
|
||||||
|
TM1638 TM1638 = new TM1638(arduino);
|
||||||
|
TM1638.construct(8, 9, 7);
|
||||||
while (i < 10000) {
|
while (i < 10000) {
|
||||||
Ping ping = Ping.newBuilder().setId(i++).build();
|
TM1638.ping(i++);
|
||||||
System.out.println("writing!");
|
TM1638.setLed(i % 3 == 0 ? Color.GREEN : Color.RED, i % 7);
|
||||||
ping.writeDelimitedTo(outputStream);
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
arduino.close();
|
arduino.close();
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package beerduino;
|
|
||||||
|
|
||||||
message Ping {
|
|
||||||
required int32 id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Echo {
|
|
||||||
required int32 id = 1;
|
|
||||||
optional string message = 2;
|
|
||||||
}
|
|
||||||
52
src/main/proto/tm1638.proto
Normal file
52
src/main/proto/tm1638.proto
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package tm1638;
|
||||||
|
|
||||||
|
enum Color {
|
||||||
|
GREEN = 1;
|
||||||
|
RED = 2;
|
||||||
|
BOTH = 3;
|
||||||
|
NONE = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Module {
|
||||||
|
TM1638 = 1;
|
||||||
|
InvertedTM1638 = 2;
|
||||||
|
TM1640 = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Command {
|
||||||
|
enum Type {
|
||||||
|
PING = 1;
|
||||||
|
CONSTRUCT = 2;
|
||||||
|
SET_LED = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
required Type type = 1;
|
||||||
|
optional Ping ping = 2;
|
||||||
|
optional Construct construct = 3;
|
||||||
|
optional SetLed setLed = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Ping {
|
||||||
|
required int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Echo {
|
||||||
|
required int32 id = 1;
|
||||||
|
optional string message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Construct {
|
||||||
|
required int32 dataPin = 1;
|
||||||
|
required int32 clockPin = 2;
|
||||||
|
optional int32 strobePin = 3;
|
||||||
|
optional bool activateDisplay = 4 [default = true];
|
||||||
|
optional int32 intensity = 5 [default = 7];
|
||||||
|
optional Module module = 6 [default = TM1638];
|
||||||
|
optional int32 id = 7 [default = 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetLed {
|
||||||
|
required Color color = 1;
|
||||||
|
required int32 pos = 2;
|
||||||
|
optional int32 id = 3 [default = 1];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user