debugging

master
adb 4 years ago
parent 604bf9cbb4
commit e39aac0769

@ -6,15 +6,15 @@
//Ethernet //Ethernet
byte mac[] = {0xAA, 0xDD, 0xBB, 0x10, 0x01, 0x01}; byte mac[] = {0xAA, 0xDD, 0xBB, 0x10, 0x01, 0x01};
IPAddress ip(192, 168, 0, 20); IPAddress ip(192, 168, 178, 30);
//IP of the ATEM switcher //IP of the ATEM switcher
ATEM AtemSwitcher(IPAddress(192, 168, 0, 50), 56417); ATEM AtemSwitcher(IPAddress(192, 168, 178, 20), 56417);
//tally LEDs //tally LEDs
const int tallyLED[] = {2,3}; const int tallyLED[] = {2,3,4,5};
const int tallyLEDlength = 2; const int tallyLEDlength = 4;
boolean tallyLEDstat[2]; boolean tallyLEDstat[4];
//init NRF //init NRF
RF24 radio (7, 8); RF24 radio (7, 8);
@ -36,13 +36,16 @@ void setup(){
Ethernet.begin(mac,ip); Ethernet.begin(mac,ip);
//start Serial //start Serial
Serial.begin(9600); Serial.begin(9600);
Serial.println("start serial");
//connect to the switcher //connect to the switcher
Serial.println("connect to ATEM");
AtemSwitcher.serialOutput(true); AtemSwitcher.serialOutput(true);
AtemSwitcher.connect(); AtemSwitcher.connect();
//start NRF //start NRF
Serial.println("start NRF");
radio.begin(); radio.begin();
radio.openWritingPipe(address); radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN); radio.setPALevel(RF24_PA_MIN);
@ -59,11 +62,11 @@ void loop(){
//check for new packages //check for new packages
AtemSwitcher.runLoop(); AtemSwitcher.runLoop();
previousTime = currentTime;
currentTime = millis(); currentTime = millis();
if (dataChanged() || currentTime - previousTime >= intervalTime){
if (dataChanged() || currentTime - previousTime >= intervalTime)
sendNRF(); sendNRF();
previousTime = currentTime;
}
} }
void sendNRF(){ void sendNRF(){
@ -72,24 +75,27 @@ void sendNRF(){
} }
datasend = datasend << (8 - tallyLEDlength); datasend = datasend << (8 - tallyLEDlength);
datasend = (datasend << 8) + getChecksum(datasend & 0xFF); datasend = (datasend << 8) + getChecksum(datasend & 0xFF);
Serial.print(" datasend: ");
Serial.println(datasend, BIN);
radio.writeFast(&datasend, sizeof(datasend)); radio.writeFast(&datasend, sizeof(datasend));
} }
boolean dataChanged(){ boolean dataChanged(){
boolean changed = false; boolean changed = false;
//Serial.println("tally: ");
for (int i=0; i < tallyLEDlength; i++){ for (int i=0; i < tallyLEDlength; i++){
if (AtemSwitcher.getProgramTally(i+1) == tallyLEDstat[i]){ if (AtemSwitcher.getProgramTally(i+1) != tallyLEDstat[i]){
tallyLEDstat[i] = AtemSwitcher.getProgramTally(i+1); tallyLEDstat[i] = AtemSwitcher.getProgramTally(i+1);
digitalWrite(tallyLED[i], !AtemSwitcher.getProgramTally(i+1)); digitalWrite(tallyLED[i], tallyLEDstat[i]);
changed = true; changed = true;
} }
} }
return changed; return changed;
} }
uint8_t getChecksum(uint8_t data){ byte getChecksum(byte data){
uint8_t checksum = 0; byte checksum = 0;
for (int i=8; i<8; i++) checksum += (data >> i) & 1; for (int i=8; i<8; i++) checksum += (data >> i) & B1;
return checksum; return checksum;
} }

@ -2,11 +2,11 @@
#include <nRF24L01.h> #include <nRF24L01.h>
//tally LEDs //tally LEDs
const int tallyLED[] = {2,3}; const int tallyLED[] = {2,3,4,5};
const int tallyLEDlength = 2; const int tallyLEDlength = 4;
boolean tallyLEDstat[2]; boolean tallyLEDstat[4];
# define errorLED 4 # define errorLED 6
//init NRF //init NRF
RF24 radio (7, 8); RF24 radio (7, 8);
@ -27,12 +27,14 @@ void setup(){
digitalWrite(errorLED, HIGH); digitalWrite(errorLED, HIGH);
//start Serial //start Serial
Serial.begin(9600); Serial.begin(9600);
Serial.println("start serial");
//start NRF //start NRF
Serial.println("start NRF");
radio.begin(); radio.begin();
radio.openReadingPipe(0, address); radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_1MBPS); radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(false); radio.setAutoAck(false);
radio.disableCRC(); radio.disableCRC();
@ -44,30 +46,33 @@ void setup(){
void loop(){ void loop(){
while (!updateLoop()); while (!updateLoop());
radio.read(&datareceive, sizeof(datareceive)); radio.read(&datareceive, sizeof(datareceive));
if (getChecksum((datareceive >> 8) & 0xFF) != datareceive & 0xFF){ Serial.print("data: ");
Serial.println(datareceive, BIN);
if (getChecksum((datareceive >> 8) & 0xFF) != (datareceive & 0xFF)){
Serial.println("corrupted data");
digitalWrite(errorLED, HIGH); digitalWrite(errorLED, HIGH);
}else{ }else digitalWrite(errorLED, LOW);
digitalWrite(errorLED, LOW); for (int i=0; i < tallyLEDlength; i++){
for (int i=0; i < tallyLEDlength; i++){ digitalWrite(tallyLED[i], (datareceive >> 15 - i) & 1);
digitalWrite(tallyLED[i], (datareceive >> 15 - i) & 1);
}
} }
} }
boolean updateLoop(){ boolean updateLoop(){
currentTime = millis(); currentTime = millis();
if (radio.available()){ if (radio.available()){
Serial.println("new package");
previousTime = currentTime; previousTime = currentTime;
return true; return true;
} }
else if (currentTime - previousTime >= errorTime){ else if (currentTime - previousTime >= errorTime){
Serial.println("timeout");
digitalWrite(errorLED, HIGH); digitalWrite(errorLED, HIGH);
} }
return false; return false;
} }
uint8_t getChecksum(uint8_t data){ byte getChecksum(byte data){
uint8_t checksum = 0; byte checksum = 0;
for (int i=8; i<8; i++) checksum += (data >> i) & 1; for (int i=8; i<8; i++) checksum += (data >> i) & 1;
return checksum; return checksum;
} }

Loading…
Cancel
Save