mirror of
https://github.com/sigmasternchen/dosimeter-arduino
synced 2025-03-15 01:28:54 +00:00
added actual dosimeter functionality
This commit is contained in:
parent
93c194834e
commit
69c50f75fe
2 changed files with 39 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
|||
#include "dosimeter.h"
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266TimerInterrupt.h>
|
||||
|
||||
DosimeterType Dosimeter;
|
||||
|
||||
|
@ -19,13 +21,17 @@ int type;
|
|||
volatile int buckets[BUCKETS_PER_MINUTE] = {0};
|
||||
int last = 0;
|
||||
bool valid = false;
|
||||
bool measureDose = false;
|
||||
volatile float dose = 0;
|
||||
|
||||
ESP8266Timer timer;
|
||||
|
||||
static inline void clearISR() {
|
||||
unsigned long gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
|
||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
|
||||
}
|
||||
|
||||
static void ICACHE_RAM_ATTR isr() {
|
||||
static void ICACHE_RAM_ATTR geigerISR() {
|
||||
int next = (millis() / BUCKET_WIDTH_IN_MS) % BUCKETS_PER_MINUTE;
|
||||
|
||||
if (last != next) {
|
||||
|
@ -42,11 +48,20 @@ static void ICACHE_RAM_ATTR isr() {
|
|||
clearISR();
|
||||
}
|
||||
|
||||
// timerISR gets called every minute
|
||||
static void ICACHE_RAM_ATTR timerISR() {
|
||||
if (measureDose && valid) {
|
||||
dose += Dosimeter.getEquivalentDoseRate() / 60;
|
||||
}
|
||||
}
|
||||
|
||||
void DosimeterType::begin(int pin, int _type) {
|
||||
type = _type;
|
||||
|
||||
pinMode(pin, INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(pin), isr, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(pin), geigerISR, RISING);
|
||||
|
||||
timer.attachInterruptInterval(60l * 1000 * 1000, timerISR);
|
||||
}
|
||||
|
||||
int DosimeterType::getCPM() {
|
||||
|
@ -61,6 +76,14 @@ float DosimeterType::getEquivalentDoseRate() {
|
|||
return getCPM() * getCalibrationFactor(type);
|
||||
}
|
||||
|
||||
float DosimeterType::getEquivalentDose() {
|
||||
if (measureDose) {
|
||||
return dose;
|
||||
} else {
|
||||
return NAN;
|
||||
}
|
||||
}
|
||||
|
||||
bool DosimeterType::isValid() {
|
||||
if (valid) {
|
||||
return true;
|
||||
|
@ -69,3 +92,12 @@ bool DosimeterType::isValid() {
|
|||
return valid;
|
||||
}
|
||||
}
|
||||
|
||||
void DosimeterType::startRecording() {
|
||||
dose = 0;
|
||||
measureDose = true;
|
||||
}
|
||||
|
||||
void DosimeterType::stopRecording() {
|
||||
measureDose = false;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,14 @@
|
|||
class DosimeterType {
|
||||
public:
|
||||
void begin(int pin, int type);
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
|
||||
bool isValid();
|
||||
|
||||
float getEquivalentDoseRate();
|
||||
float getEquivalentDose();
|
||||
|
||||
int getCPM();
|
||||
private:
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue