2024-11-14 18:41:47 +01:00
|
|
|
/*
|
|
|
|
This is part of RadiationMapping
|
2024-11-14 20:37:18 +01:00
|
|
|
Copyright (C) 2024 Václav Šmejkal
|
2024-11-14 18:41:47 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-11-14 18:36:04 +01:00
|
|
|
#include <list>
|
|
|
|
|
2024-11-15 21:29:11 +01:00
|
|
|
#include "display.hpp"
|
2024-11-15 19:54:43 +01:00
|
|
|
|
|
|
|
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
|
2024-11-13 22:50:22 +01:00
|
|
|
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
2024-11-15 19:56:08 +01:00
|
|
|
#define CALIBRATION_FACTOR 0.00332 //CONSTANT FOR CONVERTING J305 CPM TO uSv/h
|
2024-11-13 22:50:22 +01:00
|
|
|
|
2024-11-14 18:36:04 +01:00
|
|
|
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
|
2024-11-13 22:50:22 +01:00
|
|
|
|
|
|
|
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
2024-11-15 20:16:31 +01:00
|
|
|
void IRAM_ATTR increment_counts() //TODO: Possible noise
|
2024-11-13 22:50:22 +01:00
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
|
2024-11-13 22:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2024-11-15 21:29:11 +01:00
|
|
|
//INIT LCD
|
|
|
|
display::begin();
|
2024-11-13 22:50:22 +01:00
|
|
|
|
|
|
|
//INIT PINS
|
|
|
|
pinMode(INPUT_PIN, INPUT);
|
2024-11-14 17:58:16 +01:00
|
|
|
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
|
2024-11-13 22:50:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int last_counts = -1;
|
|
|
|
void loop()
|
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
unsigned long current_millis = millis(); //CURRENT TIME
|
2024-11-13 22:50:22 +01:00
|
|
|
int current_counts = 0;
|
|
|
|
|
2024-11-14 18:36:04 +01:00
|
|
|
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
|
|
|
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
|
2024-11-13 22:50:22 +01:00
|
|
|
{
|
2024-11-14 18:36:04 +01:00
|
|
|
return (current_millis - particle >= MEASUREMENT_TIME_MS);
|
|
|
|
});
|
|
|
|
|
|
|
|
//COUNT RECENT
|
|
|
|
current_counts = counts.size();
|
2024-11-13 22:50:22 +01:00
|
|
|
|
|
|
|
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
|
|
|
{
|
|
|
|
last_counts = current_counts;
|
2024-11-15 21:29:11 +01:00
|
|
|
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED
|
2024-11-13 22:50:22 +01:00
|
|
|
}
|
|
|
|
}
|