xxxxxxxxxx
281
// Hilfsklassen
class Buffer {
constructor() {
this.buchstaben = "";
this.debug = 0;
}
add(b) {
//print("I am adding: "+b);
this.buchstaben = this.buchstaben + b;
}
getBuffer() {
return this.buchstaben;
}
getMode() {
this.i = this.buchstaben.indexOf("!");
if (this.debug === 1) {
print("parsing: " + this.buchstaben);
print("start: " + this.buchstaben[0]);
print("load: " + this.buchstaben.substring(1,this.i));
}
return(this.buchstaben[0]);
}
getLoad() {
this.i = this.buchstaben.indexOf("!");
if (this.debug === 1) {
print("parsing: " + this.buchstaben);
print("start: " + this.buchstaben[0]);
print("load: " + this.buchstaben.substring(1,this.i));
}
return int(this.buchstaben.substring(1,this.i));
}
flushBuffer() {
this.buchstaben = "";
}
setDebug(b) {
this.debug = b;
}
getDebug() {
return this.debug;
}
}
class Sensoren {
constructor() {
this.buffer = new Buffer();
this.debug = 0;
this.LDR = -1; //b
this.RFID = -1; //f
this.potentiometer1 = -1; // a
this.potentiometer2 = -1; //x
this.touch = -1;
this.released = -1;
this.button1 = -1; // e12
this.push = - 1;
this.analog2 = -1; //c
this.analog3 = -1; //d
this.digital4 = -1; //g
this.digital5 = -1; //h
this.button = -1; // i
this.temperature = -1; //j
this.selfMade = -1; //y
this.button2 = -1; // w
}
nachrichtHinzufuegen(n) {
// Ende der Nachricht
if (key == '!') {
this.buffer.add(key);
this.m = this.buffer.getMode();
if (this.m==="a") {
this.potentiometer1 = this.buffer.getLoad();
if (this.debug === 2)
print("Potentiometer: " + this.potentiometer1);
}
if (this.m==="b") {
this.LDR = this.buffer.getLoad();
if (this.debug === 2)
print("LDR: " + this.LDR);
}
if (this.m==="c") {
this.analog2 = this.buffer.getLoad();
if (this.debug === 2)
print("Analog2: " + this.analog2);
}
if (this.m==="d") {
this.analog3 = this.buffer.getLoad();
if (this.debug === 2)
print("Analog3: " + this.analog3);
}
if (this.m==="e") {
this.touch = this.buffer.getLoad();
if (this.debug === 2)
print("Touch-Eingabe: " + this.touch);
}
if (this.m==="f") {
this.released = this.buffer.getLoad();
if (this.debug === 2)
print("Touch-Released: " + this.released);
}
if (this.m==="r") {
this.RFID = this.buffer.getLoad();
if (this.debug === 2)
print("RFID: " + this.RFID);
}
if (this.m==="g") {
this.digital4= this.buffer.getLoad();
if (this.debug === 2)
print("Digital5: " + this.digital4);
}
if (this.m==="h") {
this.digital5 = this.buffer.getLoad();
if (this.debug === 2)
print("Digital5: " + this.digital5);
}
if (this.m==="i") {
this.button = this.buffer.getLoad();
if (this.debug === 2)
print("Button: " + this.button);
}
if (this.m==="w") {
this.button2 = this.buffer.getLoad();
if (this.debug === 2)
print("Button2: " + this.button2);
}
if (this.m==="j") {
this.temperature = this.buffer.getLoad();
if (this.debug === 2)
print("Temperature: " + this.temperature);
}
if (this.m==="x") {
this.potentiometer2 = this.buffer.getLoad();
if (this.debug === 2)
print("Potentiometer2: " + this.potentiometer2);
}
if (this.m==="v") {
this.selfMade = this.buffer.getLoad();
if (this.debug === 2)
print("Selfmade: " + this.selfMade);
}
this.buffer.flushBuffer();
} else {
if(key!=='Shift') {
this.buffer.add(key);
}
}
}
getPotentiometer() {
return this.potentiometer1;
}
restPotentiometer() {
this.potentiometer1 = -1;
}
getPotentiometer2() {
return this.potentiometer2;
}
restPotentiometer2() {
this.potentiometer2 = -1;
}
getSelfMade() {
return this.selfMade;
}
restSelfMade() {
this.selfMade = -1;
}
getLDR() {
return this.LDR;
}
restLDR() {
this.LDR = -1;
}
getRFID() {
return this.RFID;
}
resetRFID() {
this.RFID = -1;
}
getAnalog2() {
return this.analog2;
}
resetAnalog2() {
this.analog2 = -1;
}
getAnalog3() {
return this.analog3;
}
resetAnalog3() {
this.analog3 = -1;
}
getDigital4() {
return this.digital4;
}
resetDigital4() {
this.digital4 = -1;
}
getDigital5() {
return this.digital5;
}
resetDigital5() {
this.digital5 = -1;
}
getTouch() {
return this.touch;
}
resetTouch() {
this.touch = -1;
}
getReleased() {
return this.released;
}
resetReleased() {
this.released = -1;
}
getButton() {
return this.button;
}
resetButton() {
this.button = -1;
}
getButton2() {
return this.button2;
}
resetButton2() {
this.button2 = -1;
}
getTemperature() {
if (this.temperature === -1)
return this.temperature;
else
return this.temperature/100;
}
resetTemperature() {
this.temperature = -1;
}
setDebug(b) {
this.debug = b;
this.buffer.setDebug(this.debug);
}
}