re-implemented LCD in main

This commit is contained in:
Václav Šmejkal 2025-01-20 19:59:19 +01:00
parent 253ed59793
commit 186f090bc9
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -28,7 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
#define MEASUREMENT_TIME_MS 60000 //MINUTE
#define SEND_TIME_MS 1000 //HOW OFTEN TO SEND DATA
//#define CALIBRATION_FACTOR 0.00332 //CONSTANT FOR CONVERTING J305 CPM TO uSv/h
#define CALIBRATION_FACTOR 0.00332 //CONSTANT FOR CONVERTING J305 CPM TO uSv/h
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
unsigned long last_send_time = 0;
@ -39,7 +39,10 @@ void IRAM_ATTR increment_counts() //TODO: Possible noise
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
}
//DHT11 STUFF
DHT_Unified dht(9, DHT11);
JsonDocument doc;
sensors_event_t event;
void setup()
{
@ -51,8 +54,8 @@ void setup()
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
/*//INIT LCD
display::begin();*/
//INIT LCD
display::begin();
//INIT PINS
pinMode(INPUT_PIN, INPUT);
@ -63,7 +66,7 @@ int last_counts = -1;
void loop()
{
unsigned long current_millis = millis(); //CURRENT TIME
//int current_counts = 0;
int current_counts = 0;
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
@ -71,21 +74,24 @@ void loop()
return (current_millis - particle >= MEASUREMENT_TIME_MS);
});
/*//COUNT RECENT
//COUNT RECENT
current_counts = counts.size();
if (last_counts != current_counts) //PRINT CPM IF CHANGED
{
last_counts = current_counts;
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED
}*/
dht.temperature().getEvent(&event);
display::print(String((int) event.temperature) + "C", "", true);
dht.humidity().getEvent(&event);
display::print("", String((int) event.relative_humidity) + "%", true);
}
//SEND CURRENT STATE IN JSON
if (current_millis - last_send_time >= SEND_TIME_MS)
{
JsonDocument doc;
sensors_event_t event;
//SERIALIZE
doc["cpm"] = counts.size();