-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.pde
More file actions
60 lines (58 loc) · 1.72 KB
/
Command.pde
File metadata and controls
60 lines (58 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import processing.serial.*;
class Command{//bytes represented in refrence to ascii chars for readability
byte type; //'m'for move 'l' for lift 'r' for reset
byte direction; //'u' or 'd' for up or down
short x, y;
private String commandStr = "";
public Command(){
type = 'l'; //default is lift
direction = 'u'; // default is up
}
public Command(byte type){
this.type = type;
}
public Command(byte type, byte direction){
this.type = type;
this.direction = direction;
}
public Command(byte type, short x, short y){
this.type = type;
this.x = x;
this.y = y;
}
public void print(){
println(""+(char)type+' '+x+' '+y+'\n');
}
public boolean sendCommand(Serial port){
if(type=='l'){
if(direction=='u')port.write("lu");
if(direction=='d')port.write("ld");
}else if(type == 'r'){
port.write(""+type);
}else if(type == 'm'){
commandStr = "";
commandStr = commandStr+"m "+int(x)+' '+int(y)+'\n';
port.write(commandStr);
}
return true;
}
/*public boolean sendCommand(Serial port){ //bitwise doesnt work yet
if(type=='l'){
port.write(type+direction);
}else if(type == 'r'){
port.write(type);
}else if(type == 'm'){
port.write(type);
byte most, least;
short number = x;
for(int i = 0; i<2; i++){
if(i>0){number=y;}//ater x is sent set number to y and send it
least = byte(number & 0x00FF); // bitmask to get the least significant byte
most = byte((number >> 8) & 0x00FF); //rightshift by a byte and bitmask it
port.write(most);
port.write(least);
}
}
return true;
}*/
}