Skip to content
Browse files

setup procedure done

  • Loading branch information...
1 parent 1367510 commit 1dac88392727a98272c3bf5a47c9a230b0f9bfad @technocake technocake committed Mar 25, 2013
Showing with 57 additions and 40 deletions.
  1. +2 −0 pizzanetmap_firmware/Makefile
  2. +55 −40 pizzanetmap_firmware/pizzanetmap_firmware.ino
View
2 pizzanetmap_firmware/Makefile
@@ -0,0 +1,2 @@
+build:
+ open -a "Arduino" *.ino
View
95 pizzanetmap_firmware/pizzanetmap_firmware.ino
@@ -24,20 +24,40 @@ int MR_Pin = 7; // Master Reset
#define RE_PULSE 8 // Repulse - timeslots between retransmitting pulse.
#define MAX_NODE_COUNT 512 // if no BKTRK is connected.
#define number_of_cores 2 // Core switches in use
+#define n_74hc595_per_distro 2 // Shift registers per distro
+#define n_shiftregister_pins 8 // Number of output pins on shiftreg.
+
/*____________________________________________________________
* END OF CONFIGURATION
*/
+typedef struct
+{
+ int n_distros;
+ int n_pins;
+ boolean active;
+} _core;
+
+
+ _core * core_stat;
+
+
+
+
/* helper arrays */
int CLK[number_of_cores] = {CLK1_Pin, CLK2_Pin};
int RX[number_of_cores] = {RX1_Pin, RX2_Pin};
int TX[number_of_cores] = {TX1_Pin, TX2_Pin};
-uint cores, bits_shifted, tot_nodes = 0;
+int active_cores, bits_shifted, tot_nodes = 0;
int nodes = 0;
-
+/*###################################################################################
+ *
+ * SETUP
+ *
+ *##################################################################################*/
void setup(){
//Core #1
@@ -48,38 +68,53 @@ void setup(){
pinMode(TX2_Pin, OUTPUT);
pinMode(CLK2_Pin, OUTPUT);
pinMode(RX2_Pin, INPUT);
-
+ //Reset
pinMode(MR_Pin, OUTPUT);
-
-
+
+ // For the API to work :).
Serial.begin(9600);
-
+
+ // Keeping track of core-statistics. i.e numbers.
+ core_stat = (_core *) malloc(number_of_cores * sizeof(_core));
+
//Determine how many nodes connected to each core:
tot_nodes = 0;
- for (uint core = number_of_cores-1; core-- >0;;) {
+ active_cores = 0;
+
+ // 1, 2,3,4,5,6,7,8,9,10,11,12
+ for (int c=0; c < number_of_cores; c++) {
nodes=0;
- countNodes( core, &nodes);
+ countNodes( c, &nodes);
- if (nodes > 0)
- tot_nodes += nodes;
+ if (nodes > 0) {
+ core_stat[c].n_distros = nodes / (n_shiftregister_pins * n_74hc595_per_distro);
+ core_stat[c].n_pins = nodes;
+ core_stat[c].active = true;
+ tot_nodes += nodes;
+ active_cores += 1;
+ }
+ else { // Error occured
+ core_stat[c].n_distros = 0;
+ core_stat[c].n_pins = 0;
+ core_stat[c].active = false;
+ }
}
-
- Serial.print(tot_nodes)
+
+ Serial.print(core_stat[0].n_distros);
+ Serial.print(active_cores);
}
-
-
void reset(int dt) {
digitalWrite(MR_Pin, LOW);
delay(dt);
digitalWrite(MR_Pin, HIGH);
}
-// Dynamically count the number of nodes on one line.
-void countNodes (uint line, int * nodes) {
+// Dynamically count the number of nodes on a core (one ser-line).
+void countNodes (int line, int * nodes) {
*nodes = 0;
int bkval = 0;
//reset
@@ -93,38 +128,18 @@ void countNodes (uint line, int * nodes) {
digitalWrite(CLK[line], HIGH);
//Counting
- } while ( int(bkval = digitalRead(RX[line])) == 0 && ((*nodes)++) < MAX_NODE_COUNT );
+ } while ( ((*nodes)++) < MAX_NODE_COUNT && int(bkval = digitalRead(RX[line])) == 0 );
+
if (*nodes >= MAX_NODE_COUNT) {
*nodes = -1;
}
-
-}
+
+}//end countNodes
void loop(){
- while (1) {
- if (Serial.available() > 0) {
-
- }
- }
-
-
- //CORE 1
- countNodes(0, &nodes);
- if (Serial.available() > 0) {
-
- Serial.write("Core 1::\t %i nodes counted\n", nodes);
- }
-
- delay(1000);
- // CORE 2
- countNodes(1, &nodes);
- if (Serial.available() > 0) {
-
- printf("Core 2::\t %i nodes counted\n", nodes);
- }
}

0 comments on commit 1dac883

Please sign in to comment.
Something went wrong with that request. Please try again.