src/Walrus_I2C.h
Classes
| Name | |
|---|---|
| class | Walrus Class to interface with the Walrus submersible temperature and pressure sensor. |
Defines
| Name | |
|---|---|
| WALRUS_FW_MIN_PATCH | |
| WALRUS_LIBRARY_VERSION | |
| WALRUS_LIBRARY_COMMIT | |
| WALRUS_PRESSURE_CAPACITY | |
| WALRUS_TEMPERATURE_CAPACITY | |
| PRES_REG | |
| TEMP_MS5803 | |
| TEMP_EXT | |
| ADR_DEFAULT |
Macros Documentation
define WALRUS_FW_MIN_PATCH
#define WALRUS_FW_MIN_PATCH 1
Lowest firmware patch (Page 0 byte 0x0A) this library accepts: patch 1 brought the Block 0 handshake (trigger, reading counter, faults).
define WALRUS_LIBRARY_VERSION
#define WALRUS_LIBRARY_VERSION "0.2.0"
define WALRUS_LIBRARY_COMMIT
#define WALRUS_LIBRARY_COMMIT ""
define WALRUS_PRESSURE_CAPACITY
#define WALRUS_PRESSURE_CAPACITY 16
define WALRUS_TEMPERATURE_CAPACITY
#define WALRUS_TEMPERATURE_CAPACITY 16
define PRES_REG
#define PRES_REG 0x48
define TEMP_MS5803
#define TEMP_MS5803 0x4C
define TEMP_EXT
#define TEMP_EXT 0x50
define ADR_DEFAULT
#define ADR_DEFAULT Walrus::DEFAULT_ADDRESS
Deprecated:
Use Walrus::DEFAULT_ADDRESS. Every NW library defined this same macro with a different value, so a sketch including two of them got the last one. Removed at the next major version.
Source code
/******************************************************************************
Walrus.cpp
Library for Walrus pressure and temperature sensor, made by Northern Widget LLC.
Based off of the TP-Downhole
Bobby Schulz @ Northern Widget LLC
5/9/2018
Hardware info located at:
https://github.com/NorthernWidget-Skunkworks/Project-Walrus
Distributed as-is; no warranty is given.
******************************************************************************/
#ifndef Walrus_I2C_h
#define Walrus_I2C_h
#include <Arduino.h>
#include <NW_Core.h> // NW_Core: NW_Device (Schema 1 protocol), NW_Report
#define WALRUS_FW_MIN_PATCH 1
// Build identity: this library's version (held equal to library.properties by
// NW-Tests/version_check.py) and its build commit, set by the NW-Build wrapper from
// git and blank in an Arduino IDE build. Both go into a logger's status file.
#define WALRUS_LIBRARY_VERSION "0.2.0"
#ifndef WALRUS_LIBRARY_COMMIT
#define WALRUS_LIBRARY_COMMIT ""
#endif
// Readings per updateMeasurements() are kept in static arrays of this
// capacity (one per chip group; no heap); set<Field>Readings(n) clamps to it.
// Override before the include to trade RAM for a longer batch.
#ifndef WALRUS_PRESSURE_CAPACITY
#define WALRUS_PRESSURE_CAPACITY 16 // MS5803: pressure and its temperature
#endif
#ifndef WALRUS_TEMPERATURE_CAPACITY
#define WALRUS_TEMPERATURE_CAPACITY 16 // MCP9808: external temperature
#endif
#define PRES_REG 0x48 // Schema 1 Page 2 Block 1: pressure, int32, µBar
#define TEMP_MS5803 0x4C // Schema 1 Page 2 Block 1: MS5803 temperature, int16, 0.01 °C
#define TEMP_EXT 0x50 // Schema 1 Page 2 Block 2: external temperature (MCP9808), int16, 0.01 °C
class Walrus : public NW_Sensor
{
public:
static constexpr uint8_t DEFAULT_ADDRESS = 0x57;
enum Component : uint8_t {
MS5803 = 0x01,
MCP9808 = 0x02,
ALL = 0x03
};
Walrus(); // Constructor
bool begin(uint8_t Address_ = DEFAULT_ADDRESS);
bool updateMeasurements(uint8_t component = ALL);
bool updatePressure();
bool updateTemperature();
uint16_t setPressureReadings(uint16_t n);
uint16_t setTemperatureReadings(uint16_t n);
void setPressureStats(bool enable);
void setTemperatureStats(bool enable);
uint16_t getPressureCount();
uint16_t getTemperatureCount();
float getTemperature(uint8_t Location);
float getTemperature();
float getPressure();
// --- Statistics getters ---
// Computed two-pass in 32-bit float over the readings stored by the last
// updateMeasurements() (NW_Readings). Adequate for N up to the array
// capacities; at N in the thousands the sum of squared deviations would
// want double precision, which the AVR lacks.
float getPressureMean();
float getPressureStd();
float getPressureSterr();
float getPressureMedian();
float getTemperatureMean(uint8_t Location);
float getTemperatureStd(uint8_t Location);
float getTemperatureSterr(uint8_t Location);
float getTemperatureMedian(uint8_t Location);
String getHeader();
String getString();
// --- Reading interface (NW standard) ---
size_t printHeader(Print& out);
size_t printReading(Print& out);
size_t logReading(Print& out);
void beginReadings(uint8_t component = ALL, uint16_t n = 0);
void endReadings();
bool newData();
// --- Handshake (NW-Device-Specification Block 0) ---
bool ready();
bool newReading();
bool requestReading();
// --- Faults (status byte, live; Report register, latched) ---
bool faulted(uint8_t chip);
bool anyFault();
uint8_t reportChip();
uint8_t reportKind();
size_t printReport(Print& out);
String reportNote();
size_t printStatus(Print& out, bool boot = false) override;
// --- NW_Sensor: the logger's view (Margay::watch) ---
const char* name() const override { return "Walrus"; }
bool reportIsFault() override;
uint8_t bootReportKind() override;
void clearBootReport() override;
String beginFailure();
uint8_t getHardwareMajor();
uint8_t getHardwareMinor();
uint8_t getFirmwareVersion();
private:
NW_Device _dev;
float _pressure = NW_ERROR; //Mean of the last updateMeasurements() [mBar]
float _tempExt = NW_ERROR; //MCP9808 [C]
float _tempMS5803 = NW_ERROR; //MS5803 [C]
// Readings as the device serves them (raw register units), one array per
// field; statistics come from these and are scaled on the way out.
NW_Readings<int32_t, WALRUS_PRESSURE_CAPACITY> _pressureReadings; //uBar
NW_Readings<int16_t, WALRUS_PRESSURE_CAPACITY> _tempMS5803Readings; //0.01 C
NW_Readings<int16_t, WALRUS_TEMPERATURE_CAPACITY> _tempExtReadings; //0.01 C
NW_ReadingsConfig _pressureCfg; //Readings per updateMeasurements() and stats columns, MS5803 group
NW_ReadingsConfig _temperatureCfg; //MCP9808 group
uint8_t _component = ALL; //Selection of the current beginReadings() run
bool readMS5803(uint8_t* d); //Append one served MS5803 reading (6 bytes from 0x48) unless faulted
bool readMCP9808(uint8_t* d); //Append one served MCP9808 reading (2 bytes from 0x50) unless faulted
void summarise(uint8_t component); //Means into the single-value fields, NW_ERROR when no reading
};
#define ADR_DEFAULT Walrus::DEFAULT_ADDRESS
#endif
Updated on 2026-09-23 at 22:42:33 +0000