re-implemented LCD in main
This commit is contained in:
parent
253ed59793
commit
186f090bc9
@ -1,103 +1,109 @@
|
|||||||
/*
|
/*
|
||||||
This is part of RadiationMapping
|
This is part of RadiationMapping
|
||||||
Copyright (C) 2024 Václav Šmejkal
|
Copyright (C) 2024 Václav Šmejkal
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include <DHT_U.h>
|
#include <DHT_U.h>
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
|
|
||||||
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
|
#define INPUT_PIN 10 //VIN PIN FOR GEIGER COUNTER
|
||||||
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
#define MEASUREMENT_TIME_MS 60000 //MINUTE
|
||||||
#define SEND_TIME_MS 1000 //HOW OFTEN TO SEND DATA
|
#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)
|
std::list<unsigned long> counts; //COUNTS IN LAST MINUTE (OR MEASUREMENT_TIME_MS IF MODIFIED)
|
||||||
unsigned long last_send_time = 0;
|
unsigned long last_send_time = 0;
|
||||||
|
|
||||||
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
//CALLBACK WHEN RADIATION PARTICLE IS DETECTED
|
||||||
void IRAM_ATTR increment_counts() //TODO: Possible noise
|
void IRAM_ATTR increment_counts() //TODO: Possible noise
|
||||||
{
|
{
|
||||||
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
|
counts.push_back(millis()); //APPEND CURRENT TIME TO LIST counts
|
||||||
}
|
}
|
||||||
|
|
||||||
DHT_Unified dht(9, DHT11);
|
//DHT11 STUFF
|
||||||
|
DHT_Unified dht(9, DHT11);
|
||||||
void setup()
|
JsonDocument doc;
|
||||||
{
|
sensors_event_t event;
|
||||||
Serial.begin(9600);
|
|
||||||
|
void setup()
|
||||||
//INIT DHT11
|
{
|
||||||
dht.begin();
|
Serial.begin(9600);
|
||||||
sensor_t sensor;
|
|
||||||
dht.temperature().getSensor(&sensor);
|
//INIT DHT11
|
||||||
dht.humidity().getSensor(&sensor);
|
dht.begin();
|
||||||
|
sensor_t sensor;
|
||||||
/*//INIT LCD
|
dht.temperature().getSensor(&sensor);
|
||||||
display::begin();*/
|
dht.humidity().getSensor(&sensor);
|
||||||
|
|
||||||
//INIT PINS
|
//INIT LCD
|
||||||
pinMode(INPUT_PIN, INPUT);
|
display::begin();
|
||||||
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
|
|
||||||
}
|
//INIT PINS
|
||||||
|
pinMode(INPUT_PIN, INPUT);
|
||||||
int last_counts = -1;
|
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), increment_counts, FALLING);
|
||||||
void loop()
|
}
|
||||||
{
|
|
||||||
unsigned long current_millis = millis(); //CURRENT TIME
|
int last_counts = -1;
|
||||||
//int current_counts = 0;
|
void loop()
|
||||||
|
{
|
||||||
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
unsigned long current_millis = millis(); //CURRENT TIME
|
||||||
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
|
int current_counts = 0;
|
||||||
{
|
|
||||||
return (current_millis - particle >= MEASUREMENT_TIME_MS);
|
//REMOVE COUNTS OLDER THAN MEASUREMENT_TIME_MS
|
||||||
});
|
counts.remove_if([current_millis](unsigned long particle) //haha, *lambda* (cries in pure-C)
|
||||||
|
{
|
||||||
/*//COUNT RECENT
|
return (current_millis - particle >= MEASUREMENT_TIME_MS);
|
||||||
current_counts = counts.size();
|
});
|
||||||
|
|
||||||
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
//COUNT RECENT
|
||||||
{
|
current_counts = counts.size();
|
||||||
last_counts = current_counts;
|
|
||||||
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED
|
if (last_counts != current_counts) //PRINT CPM IF CHANGED
|
||||||
}*/
|
{
|
||||||
|
last_counts = current_counts;
|
||||||
//SEND CURRENT STATE IN JSON
|
display::print(String(current_counts) + " CPM", String(current_counts * CALIBRATION_FACTOR) + " uSv/h"); //TODO: Replace with OLED
|
||||||
if (current_millis - last_send_time >= SEND_TIME_MS)
|
|
||||||
{
|
dht.temperature().getEvent(&event);
|
||||||
JsonDocument doc;
|
display::print(String((int) event.temperature) + "C", "", true);
|
||||||
sensors_event_t event;
|
|
||||||
|
dht.humidity().getEvent(&event);
|
||||||
//SERIALIZE
|
display::print("", String((int) event.relative_humidity) + "%", true);
|
||||||
doc["cpm"] = counts.size();
|
}
|
||||||
|
|
||||||
dht.temperature().getEvent(&event);
|
//SEND CURRENT STATE IN JSON
|
||||||
doc["temperature"] = event.temperature;
|
if (current_millis - last_send_time >= SEND_TIME_MS)
|
||||||
|
{
|
||||||
dht.humidity().getEvent(&event);
|
//SERIALIZE
|
||||||
doc["humidity"] = event.relative_humidity;
|
doc["cpm"] = counts.size();
|
||||||
|
|
||||||
serializeJson(doc, Serial); //SEND
|
dht.temperature().getEvent(&event);
|
||||||
Serial.println(); //TODO: Implement WiFi
|
doc["temperature"] = event.temperature;
|
||||||
|
|
||||||
last_send_time = current_millis;
|
dht.humidity().getEvent(&event);
|
||||||
}
|
doc["humidity"] = event.relative_humidity;
|
||||||
}
|
|
||||||
|
serializeJson(doc, Serial); //SEND
|
||||||
|
Serial.println(); //TODO: Implement WiFi
|
||||||
|
|
||||||
|
last_send_time = current_millis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user