// serial commands for loop-back test
#define TEST 1
-// pins, 2 recorders 4 inputs each
+// pins, 2 receivers 4 satelites signals from Diseqc for each
int receiver[2][4] = {
{ A0, A1, A2, A3 },
{ A4, A5, A6, A7 },
};
+// pin for master disable if shorted to ground (GND is next to D2, so jumpers nicely)
#define REC_MASTER 2
+// normal arduino LED on D13
#define LED 13
// rec1 rec2 master
+// keys in serial: 1 2 3 4 5 6 7 8 9
int test_pins[] = { 12,11,10,9, 8,7,6,5, 4 };
int test_out[] = { 0, 0, 0,0, 0,0,0,0, 1};
int nr_test_pins = sizeof(test_pins)/sizeof(int);
+// loop test pins to receiver pins above for testing
+
+int master_enabled() {
+ return digitalRead(REC_MASTER) == HIGH ? 1 : 0;
+}
void setup(){
Serial.begin(9600); // FIXME check speed
#if DEBUG
Serial.print("boot master=");
- Serial.println(digitalRead(REC_MASTER) == HIGH );
+ Serial.println(master_enabled());
#endif
#if TEST
#endif
}
-int receiver_selection( int nr ) {
+char restore[10] = "";
+char len = 0;
+
+int receiver_satelite( int nr ) {
#ifdef DEBUG
- Serial.print("<");
+ Serial.print("|<");
#endif
+ if ( nr == 0 ) {
+ len = 0;
+ if ( ! master_enabled() ) restore[len++] = '9';
+ }
+
int active = 0;
int selected = -1;
+
for(int i=0; i<4; i++) {
int a = analogRead( receiver[nr][i] );
int on_off = a > 512 ? 1 : 0;
active += on_off;
- if ( on_off ) selected = i+1;
+ if ( on_off ) {
+ selected = i+1;
+ restore[len++] = char('1' + (nr * 4) + i);
+ }
//Serial.print(a);
//Serial.print("~");
Serial.print(on_off);
//Serial.print(" ");
}
+ restore[len] = 0;
Serial.print(">");
- Serial.print(selected);
if ( active == 0 ) { // no inputs active
return 0;
return -1; // error
}
+ Serial.print(" selected=");
+ Serial.print(selected);
+
return selected;
}
int current_sat = 0;
int blink_interval = LED_NO_ACTIVE_INPUTS; // 2 sec on/off no receivers turned on
int last_changed_nr = -1;
-int last_receiver_selection[2] = { -1, -1 };
+int last_receiver_satelite[2] = { -1, -1 };
void loop(){
int current_nr = nr;
- int sat = receiver_selection(i);
- int last_sat = last_receiver_selection[i];
- last_receiver_selection[i] = sat;
+ int sat = receiver_satelite(i);
+ int last_sat = last_receiver_satelite[i];
+ last_receiver_satelite[i] = sat;
#if DEBUG
Serial.print(" nr:");
Serial.print(sat);
Serial.print(" last:");
Serial.print(last_sat);
- Serial.print("|");
#endif
- int prefer_master = 0;
- if ( digitalRead(REC_MASTER) == HIGH ) {
- prefer_master = 1;
- } else {
- if ( last_sat != sat ) {
- Serial.print("C");
- last_changed_nr = current_nr;
- nr=0; // stop
- } else {
- Serial.print("=");
- nr++; // next
- continue;
- }
+ int prefer_master = master_enabled();
+ if ( ! prefer_master ) {
- if ( last_changed_nr != current_nr ) {
- sat = current_sat; // ignore, last not changed
- Serial.print("I");
+ if ( last_sat != sat ) {
+
+ Serial.print("C");
+ last_changed_nr = current_nr;
+ if ( sat == 0 ) {
+ Serial.print("off");
+ sat = receiver_satelite( (i+1)%2 ); // check other receiver
}
+ nr=0; // stop
+
+ } else {
+
+ Serial.print("=");
+ nr++; // next
+ continue;
+
+ }
+ if ( last_changed_nr != current_nr ) {
+ sat = current_sat; // ignore, last not changed
+ Serial.print("I");
+ }
}
#if DEBUG
Serial.print("[M]");
#endif
- if ( nr == 1 ) { // need to check 2nd recorder error
- int error = receiver_selection(i + 1);
+ if ( nr == 1 ) { // need to check 2nd receiver error and report it
+ int error = receiver_satelite(i + 1);
+ Serial.print(" E?");
Serial.print(error);
if ( error == -1 ) blink_interval = LED_MULTIPLE_INPUTS;
}
if ( current_sat != sat ) {
- last_changed_nr = current_nr;
+ last_changed_nr = current_nr;
current_sat = sat;
nr = 0; // stop
#if DEBUG
- Serial.print(" sat=");
+ Serial.print("| sat=");
Serial.print(current_sat);
Serial.print(" from:");
Serial.print(last_changed_nr);
+ Serial.print(" restore>");
+ Serial.print(restore);
Serial.print(" blink=");
Serial.println(blink_interval);
#endif
#endif
}
-
+// vim: tabstop=2 shiftwidth=2 expandtab