implemented list instead of array for counts
yeah, I am C developer, I didn't know C++ had such bullshit as list
This commit is contained in:
parent
db89f7229d
commit
3bdd4fa291
@ -1,21 +1,19 @@
|
|||||||
|
#include <list>
|
||||||
|
|
||||||
#define INPUT_PIN D6 //VIN PIN FOR GEIGER COUNTER
|
#define INPUT_PIN D6 //VIN PIN FOR GEIGER COUNTER
|
||||||
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
||||||
#define MAX_CPM 5000 //HOW MANY COUNTS TO STORE
|
|
||||||
|
|
||||||
unsigned long counts[MAX_CPM];
|
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
|
||||||
int last_index = -1;
|
|
||||||
|
|
||||||
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
||||||
void IRAM_ATTR increment_counts()
|
void IRAM_ATTR increment_counts()
|
||||||
{
|
{
|
||||||
counts[(++last_index) % MAX_CPM] = millis();
|
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
//INIT counts
|
//SERIAL COMMUNICATION INIT
|
||||||
for (int i = 0; i < MAX_CPM; i++) counts[i] = 0;
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
//INIT PINS
|
//INIT PINS
|
||||||
@ -26,21 +24,17 @@ void setup()
|
|||||||
int last_counts = -1;
|
int last_counts = -1;
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
unsigned long current_millis = millis();
|
unsigned long current_millis = millis(); //CURRENT TIME
|
||||||
int current_counts = 0;
|
int current_counts = 0;
|
||||||
|
|
||||||
//COUNT
|
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
||||||
for (int i = 0; i < MAX_CPM; i++)
|
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
|
||||||
{
|
{
|
||||||
if (counts[i] == 0) continue;
|
return (current_millis - particle >= MEASUREMENT_TIME_MS);
|
||||||
if (current_millis - counts[i] >= MEASUREMENT_TIME_MS) //REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
});
|
||||||
{
|
|
||||||
counts[i] = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_counts++; //COUNT RECENT
|
//COUNT RECENT
|
||||||
}
|
current_counts = counts.size();
|
||||||
|
|
||||||
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user