debugging
This commit is contained in:
parent
604bf9cbb4
commit
e39aac0769
@ -6,15 +6,15 @@
|
||||
|
||||
//Ethernet
|
||||
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
|
||||
ATEM AtemSwitcher(IPAddress(192, 168, 0, 50), 56417);
|
||||
ATEM AtemSwitcher(IPAddress(192, 168, 178, 20), 56417);
|
||||
|
||||
//tally LEDs
|
||||
const int tallyLED[] = {2,3};
|
||||
const int tallyLEDlength = 2;
|
||||
boolean tallyLEDstat[2];
|
||||
const int tallyLED[] = {2,3,4,5};
|
||||
const int tallyLEDlength = 4;
|
||||
boolean tallyLEDstat[4];
|
||||
|
||||
//init NRF
|
||||
RF24 radio (7, 8);
|
||||
@ -36,13 +36,16 @@ void setup(){
|
||||
Ethernet.begin(mac,ip);
|
||||
|
||||
//start Serial
|
||||
Serial.begin(9600);
|
||||
Serial.begin(9600);
|
||||
Serial.println("start serial");
|
||||
|
||||
//connect to the switcher
|
||||
Serial.println("connect to ATEM");
|
||||
AtemSwitcher.serialOutput(true);
|
||||
AtemSwitcher.connect();
|
||||
|
||||
//start NRF
|
||||
Serial.println("start NRF");
|
||||
radio.begin();
|
||||
radio.openWritingPipe(address);
|
||||
radio.setPALevel(RF24_PA_MIN);
|
||||
@ -59,11 +62,11 @@ void loop(){
|
||||
//check for new packages
|
||||
AtemSwitcher.runLoop();
|
||||
|
||||
previousTime = currentTime;
|
||||
currentTime = millis();
|
||||
|
||||
if (dataChanged() || currentTime - previousTime >= intervalTime)
|
||||
if (dataChanged() || currentTime - previousTime >= intervalTime){
|
||||
sendNRF();
|
||||
previousTime = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
void sendNRF(){
|
||||
@ -72,24 +75,27 @@ void sendNRF(){
|
||||
}
|
||||
datasend = datasend << (8 - tallyLEDlength);
|
||||
datasend = (datasend << 8) + getChecksum(datasend & 0xFF);
|
||||
Serial.print(" datasend: ");
|
||||
Serial.println(datasend, BIN);
|
||||
|
||||
radio.writeFast(&datasend, sizeof(datasend));
|
||||
}
|
||||
|
||||
boolean dataChanged(){
|
||||
boolean changed = false;
|
||||
//Serial.println("tally: ");
|
||||
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);
|
||||
digitalWrite(tallyLED[i], !AtemSwitcher.getProgramTally(i+1));
|
||||
digitalWrite(tallyLED[i], tallyLEDstat[i]);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
uint8_t getChecksum(uint8_t data){
|
||||
uint8_t checksum = 0;
|
||||
for (int i=8; i<8; i++) checksum += (data >> i) & 1;
|
||||
byte getChecksum(byte data){
|
||||
byte checksum = 0;
|
||||
for (int i=8; i<8; i++) checksum += (data >> i) & B1;
|
||||
return checksum;
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
#include <nRF24L01.h>
|
||||
|
||||
//tally LEDs
|
||||
const int tallyLED[] = {2,3};
|
||||
const int tallyLEDlength = 2;
|
||||
boolean tallyLEDstat[2];
|
||||
const int tallyLED[] = {2,3,4,5};
|
||||
const int tallyLEDlength = 4;
|
||||
boolean tallyLEDstat[4];
|
||||
|
||||
# define errorLED 4
|
||||
# define errorLED 6
|
||||
|
||||
//init NRF
|
||||
RF24 radio (7, 8);
|
||||
@ -27,12 +27,14 @@ void setup(){
|
||||
digitalWrite(errorLED, HIGH);
|
||||
|
||||
//start Serial
|
||||
Serial.begin(9600);
|
||||
Serial.begin(9600);
|
||||
Serial.println("start serial");
|
||||
|
||||
//start NRF
|
||||
Serial.println("start NRF");
|
||||
radio.begin();
|
||||
radio.openReadingPipe(0, address);
|
||||
radio.setPALevel(RF24_PA_MAX);
|
||||
radio.setPALevel(RF24_PA_LOW);
|
||||
radio.setDataRate(RF24_1MBPS);
|
||||
radio.setAutoAck(false);
|
||||
radio.disableCRC();
|
||||
@ -44,30 +46,33 @@ void setup(){
|
||||
void loop(){
|
||||
while (!updateLoop());
|
||||
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);
|
||||
}else{
|
||||
digitalWrite(errorLED, LOW);
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
digitalWrite(tallyLED[i], (datareceive >> 15 - i) & 1);
|
||||
}
|
||||
}else digitalWrite(errorLED, LOW);
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
digitalWrite(tallyLED[i], (datareceive >> 15 - i) & 1);
|
||||
}
|
||||
}
|
||||
|
||||
boolean updateLoop(){
|
||||
currentTime = millis();
|
||||
if (radio.available()){
|
||||
Serial.println("new package");
|
||||
previousTime = currentTime;
|
||||
return true;
|
||||
}
|
||||
else if (currentTime - previousTime >= errorTime){
|
||||
Serial.println("timeout");
|
||||
digitalWrite(errorLED, HIGH);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t getChecksum(uint8_t data){
|
||||
uint8_t checksum = 0;
|
||||
byte getChecksum(byte data){
|
||||
byte checksum = 0;
|
||||
for (int i=8; i<8; i++) checksum += (data >> i) & 1;
|
||||
return checksum;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user