Skip to content

Commit

Permalink
Clean-up and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-b authored and fifieldt committed Nov 23, 2024
1 parent 8310a2c commit 5aaf322
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion protobufs
4 changes: 2 additions & 2 deletions src/detect/ScanI2CTwoWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
break;

case CGRADSENS_ADDR:
LOG_INFO("Looking for ClimateGuard RadSense Geiger-Muller Sensor");
// Register 0x00 of the RadSens sensor contains is product identifier 0x7D
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1);
if (registerValue == 0x7D) {
type = CGRADSENS;
LOG_INFO("ClimateGuard RadSense Geiger-Muller Sensor found");
LOG_INFO("ClimateGuard RadSens Geiger-Muller Sensor found");
break;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/generated/meshtastic/telemetry.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef enum _meshtastic_TelemetrySensorType {
meshtastic_TelemetrySensorType_MLX90614 = 31,
/* SCD40/SCD41 CO2, humidity, temperature sensor */
meshtastic_TelemetrySensorType_SCD4X = 32,
/* RADSENS, radiation, geiger-muller tube */
/* ClimateGuard RadSens, radiation, Geiger-Muller Tube */
meshtastic_TelemetrySensorType_RADSENS = 33
} meshtastic_TelemetrySensorType;

Expand Down Expand Up @@ -157,7 +157,7 @@ typedef struct _meshtastic_EnvironmentMetrics {
/* Wind lull in m/s */
bool has_wind_lull;
float wind_lull;
/* Radiation in micro roentgen/hr */
/* Radiation in µR/h */
bool has_radiation;
float radiation;
} meshtastic_EnvironmentMetrics;
Expand Down
20 changes: 11 additions & 9 deletions src/modules/Telemetry/EnvironmentTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,18 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
// Display "Env. From: ..." on its own
display->drawString(x, y, "Env. From: " + String(lastSender) + "(" + String(agoSecs) + "s)");

String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C";
if (moduleConfig.telemetry.environment_display_fahrenheit) {
last_temp =
String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F";
}
if (lastMeasurement.variant.environment_metrics.has_temperature || lastMeasurement.variant.environment_metrics.has_relative_humidity) {
String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C";
if (moduleConfig.telemetry.environment_display_fahrenheit) {
last_temp =
String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F";
}

// Continue with the remaining details
display->drawString(x, y += _fontHeight(FONT_SMALL),
"Temp/Hum: " + last_temp + " / " +
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
// Continue with the remaining details
display->drawString(x, y += _fontHeight(FONT_SMALL),
"Temp/Hum: " + last_temp + " / " +
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
}

if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) {
display->drawString(x, y += _fontHeight(FONT_SMALL),
Expand Down
11 changes: 10 additions & 1 deletion src/modules/Telemetry/Sensor/CGRadSensSensor.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Support for the ClimateGuard RadSens Dosimeter
* A fun and educational sensor for Meshtastic; not for saftey critical applications.
*/
#include "configuration.h"

#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
Expand All @@ -12,6 +16,7 @@ CGRadSensSensor::CGRadSensSensor() : TelemetrySensor(meshtastic_TelemetrySensorT

int32_t CGRadSensSensor::runOnce()
{
// Initialize the sensor following the same pattern as RCWL9620Sensor
LOG_INFO("Init sensor: %s", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
Expand All @@ -27,13 +32,15 @@ void CGRadSensSensor::setup() {}

void CGRadSensSensor::begin(TwoWire *wire, uint8_t addr)
{
// Store the Wire and address to the sensor following the same pattern as RCWL9620Sensor
_wire = wire;
_addr = addr;
_wire->begin();
}

float CGRadSensSensor::getStaticRadiation()
{
// Read a register, following the same pattern as the RCWL9620Sensor
uint32_t data;
_wire->beginTransmission(_addr); // Transfer data to addr.
_wire->write(0x06); // Radiation intensity (static period T = 500 sec)
Expand All @@ -45,6 +52,8 @@ float CGRadSensSensor::getStaticRadiation()
data <<= 8;
data |= _wire->read();

// As per the data sheet for the RadSens
// Register 0x06 contains the reading in 0.1 * μR / h
float microRadPerHr = float(data) / 10.0;
return microRadPerHr;
}
Expand All @@ -54,7 +63,7 @@ float CGRadSensSensor::getStaticRadiation()

bool CGRadSensSensor::getMetrics(meshtastic_Telemetry *measurement)
{
LOG_INFO("getMetrics: ClimateGuard RadSense Geiger-Muller Sensor");
// Store the meansurement in the the appropriate fields of the protobuf
measurement->variant.environment_metrics.has_radiation = true;

LOG_DEBUG("CGRADSENS getMetrics");
Expand Down

0 comments on commit 5aaf322

Please sign in to comment.