Skip to content

Commit 9471811

Browse files
committed
Implementing HITS message output.
1 parent b62801c commit 9471811

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

fw/AIRDOS04/AIRDOS04.ino

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,65 @@ void BattOut()
339339
delay(1);
340340
}
341341

342+
void logHits() { // Hits out
343+
344+
digitalWrite(SDpower, HIGH); // SD card power on
345+
digitalWrite(SPI_MUX_SEL, LOW); // SDcard
346+
347+
// make a string for assembling the data to log:
348+
String dataString = "$HITS,";
349+
350+
dataString += String(hit_count);
351+
352+
if (hit_count > EVENTS) hit_count = EVENTS;
353+
354+
for(uint16_t n=0; n<hit_count; n++)
355+
{
356+
dataString += ",";
357+
dataString += String(hit_time[n]);
358+
dataString += ".";
359+
dataString += String(hit_time_s100[n]);
360+
dataString += ",";
361+
dataString += String(hit_channel[n]);
362+
}
363+
364+
if (SDinserted)
365+
{
366+
// make sure that the default chip select pin is set to output
367+
// see if the card is present and can be initialized:
368+
if (!SD.begin(SS))//, SPI_HALF_SPEED))
369+
{
370+
Serial1.println("#SD init false");
371+
SDinserted = false;
372+
// don't do anything more:
373+
}
374+
else
375+
{
376+
// open the file. note that only one file can be open at a time,
377+
// so you have to close this one before opening another.
378+
File dataFile = SD.open(filename, FILE_WRITE);
379+
380+
// if the file is available, write to it:
381+
if (dataFile)
382+
{
383+
dataFile.println(dataString); // write to SDcard (800 ms)
384+
dataFile.close();
385+
}
386+
// if the file isn't open, pop up an error:
387+
else
388+
{
389+
Serial.println("#SD false");
390+
SDinserted = false;
391+
}
392+
}
393+
digitalWrite(SS, HIGH); // Disable SD card
394+
}
395+
digitalWrite(SPI_MUX_SEL, HIGH); // ADC
396+
digitalWrite(SDpower, LOW); // SD card power off
397+
delay(1);
398+
hits_interval = 0;
399+
}
400+
342401
// Data out
343402
void DataOut()
344403
{
@@ -949,6 +1008,7 @@ void loop()
9491008
store = 0;
9501009
batt++;
9511010
env++;
1011+
hits_interval++;
9521012

9531013
digitalWrite(LED2, digitalRead(ACONNECT));
9541014
if (digitalRead(ACONNECT)) // Analog part is disconnected?
@@ -1022,6 +1082,13 @@ void loop()
10221082
BattOut();
10231083
};
10241084

1085+
if (hits_interval >= 30*6) // Hits output at the least every 30 minutes
1086+
{
1087+
hits_interval = 0;
1088+
logHits();
1089+
};
1090+
1091+
10251092
// dummy conversion
10261093
digitalWrite(DSET, HIGH);
10271094
digitalWrite(DRESET, LOW); // L on CONV
@@ -1047,6 +1114,24 @@ void loop()
10471114
if (histogram[adcVal]<255) histogram[adcVal]++;
10481115
digitalWrite(DRESET, HIGH);
10491116

1117+
if (adcVal > RANGE)
1118+
{
1119+
buffer[adcVal]++;
1120+
}
1121+
else
1122+
{
1123+
if (hit_count < EVENTS)
1124+
{
1125+
readRTC();
1126+
1127+
hit_time[hit_count] = tm;
1128+
hit_time_s100[hit_count]=tm_s100;
1129+
hit_channel[hit_count] = adcVal;
1130+
}
1131+
hit_count++;
1132+
logHits();
1133+
}
1134+
10501135
#ifdef RADIATION_CLICK
10511136
digitalWrite(BUZZER, LOW);
10521137
#endif

0 commit comments

Comments
 (0)