-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Resolved merge conflicts - take one million
- Loading branch information
Miles Burton
committed
Jan 4, 2025
1 parent
2576a3d
commit 21c469e
Showing
3 changed files
with
127 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,63 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <Arduino.h> | ||
#ifdef __STM32F1__ | ||
#include <OneWireSTM.h> | ||
#else | ||
#include <OneWire.h> | ||
#endif | ||
|
||
namespace Dallas { | ||
|
||
class DallasTemperature { | ||
public: | ||
static constexpr const char* LIB_VERSION = "4.0.0"; | ||
|
||
using DeviceAddress = uint8_t[8]; | ||
using ScratchPad = uint8_t[9]; | ||
|
||
struct Request { | ||
bool result; | ||
unsigned long timestamp; | ||
operator bool() const { return result; } | ||
}; | ||
|
||
// Constructors | ||
DallasTemperature(); | ||
explicit DallasTemperature(OneWire* oneWire); | ||
DallasTemperature(OneWire* oneWire, uint8_t pullupPin); | ||
|
||
// Configuration | ||
void begin(); | ||
void setOneWire(OneWire* oneWire); | ||
void setPullupPin(uint8_t pullupPin); | ||
|
||
// Device Management | ||
uint8_t getDeviceCount() const; | ||
uint8_t getDS18Count() const; | ||
bool isConnected(const DeviceAddress& address) const; | ||
bool isConnected(const DeviceAddress& address, ScratchPad& scratchPad) const; | ||
|
||
// Temperature Reading | ||
Request requestTemperatures(); | ||
Request requestTemperaturesByAddress(const DeviceAddress& address); | ||
Request requestTemperaturesByIndex(uint8_t index); | ||
float getTempC(const DeviceAddress& address, uint8_t retryCount = 0) const; | ||
float getTempF(const DeviceAddress& address, uint8_t retryCount = 0) const; | ||
|
||
// Utility Methods | ||
static float toFahrenheit(float celsius); | ||
static float toCelsius(float fahrenheit); | ||
static float rawToCelsius(int32_t raw); | ||
static float rawToFahrenheit(int32_t raw); | ||
|
||
private: | ||
bool parasitePowerMode = false; | ||
uint8_t bitResolution = 9; | ||
OneWire* oneWire = nullptr; | ||
uint8_t pullupPin = 0; | ||
|
||
bool readScratchPad(const DeviceAddress& address, ScratchPad& scratchPad) const; | ||
bool readPowerSupply(const DeviceAddress& address) const; | ||
void activateExternalPullup() const; | ||
void deactivateExternalPullup() const; | ||
|
||
int32_t calculateTemperature(const DeviceAddress& address, const ScratchPad& scratchPad) const; | ||
}; | ||
|
||
} // namespace Dallas | ||
#include "DallasTemperature.h" | ||
|
||
// Constructors | ||
DallasTemperature::DallasTemperature(OneWire* oneWire) : oneWire(oneWire) {} | ||
|
||
// Initialization | ||
void DallasTemperature::begin() { | ||
if (!oneWire) return; | ||
oneWire->reset_search(); | ||
parasitePowerMode = false; | ||
deviceCount = 0; | ||
|
||
DeviceAddress address; | ||
while (oneWire->search(address)) { | ||
deviceCount++; | ||
if (readPowerSupply(address)) { | ||
parasitePowerMode = true; | ||
} | ||
} | ||
oneWire->reset_search(); | ||
} | ||
|
||
// Get the total number of devices | ||
uint8_t DallasTemperature::getDeviceCount() const { | ||
return deviceCount; | ||
} | ||
|
||
// Get the address of a device by index | ||
bool DallasTemperature::getAddress(DeviceAddress deviceAddress, uint8_t index) const { | ||
if (!oneWire) return false; | ||
|
||
uint8_t count = 0; | ||
oneWire->reset_search(); | ||
while (count <= index && oneWire->search(deviceAddress)) { | ||
if (count == index) return true; | ||
count++; | ||
} | ||
return false; | ||
} | ||
|
||
// Check if the bus is using parasite power | ||
bool DallasTemperature::isParasitePowerMode() const { | ||
return parasitePowerMode; | ||
} | ||
|
||
// Read the power supply mode of a specific device or all devices | ||
bool DallasTemperature::readPowerSupply(const DeviceAddress deviceAddress) const { | ||
if (!oneWire) return false; | ||
|
||
oneWire->reset(); | ||
if (deviceAddress) { | ||
oneWire->select(deviceAddress); | ||
} else { | ||
oneWire->skip(); // Skip ROM command for all devices | ||
} | ||
oneWire->write(0xB4); // READ POWER SUPPLY command | ||
return (oneWire->read_bit() == 0); | ||
} | ||
|
||
// Reset search to start looking for devices again | ||
void DallasTemperature::resetSearch() const { | ||
if (oneWire) oneWire->reset_search(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,41 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <cstdint> | ||
#include <Arduino.h> | ||
#ifdef __STM32F1__ | ||
#include <OneWireSTM.h> | ||
|
||
// Platform-specific OneWire include | ||
#if defined(STM32) | ||
#include <OneWireSTM.h> // STM32-specific OneWire implementation | ||
#else | ||
#include <OneWire.h> | ||
#include <OneWire.h> // Default OneWire implementation | ||
#endif | ||
|
||
namespace Dallas { | ||
// Define DeviceAddress globally for compatibility | ||
typedef uint8_t DeviceAddress[8]; | ||
|
||
class DallasTemperature { | ||
public: | ||
static constexpr const char* LIB_VERSION = "4.0.0"; | ||
|
||
using DeviceAddress = std::array<uint8_t, 8>; | ||
using ScratchPad = std::array<uint8_t, 9>; | ||
|
||
struct Request { | ||
bool result; | ||
unsigned long timestamp; | ||
operator bool() const { return result; } | ||
}; | ||
// Library version | ||
static constexpr const char* LIB_VERSION = "4.0.1"; | ||
|
||
// Constructors | ||
DallasTemperature(); | ||
explicit DallasTemperature(OneWire* oneWire); | ||
DallasTemperature(OneWire* oneWire, uint8_t pullupPin); | ||
|
||
// Configuration | ||
// Initialization | ||
void begin(); | ||
void setOneWire(OneWire* oneWire); | ||
void setPullupPin(uint8_t pullupPin); | ||
|
||
// Device Management | ||
uint8_t getDeviceCount() const; | ||
uint8_t getDS18Count() const; | ||
bool isConnected(const DeviceAddress& address) const; | ||
bool isConnected(const DeviceAddress& address, ScratchPad& scratchPad) const; | ||
|
||
// Temperature Reading | ||
Request requestTemperatures(); | ||
Request requestTemperaturesByAddress(const DeviceAddress& address); | ||
Request requestTemperaturesByIndex(uint8_t index); | ||
float getTempC(const DeviceAddress& address, uint8_t retryCount = 0) const; | ||
float getTempF(const DeviceAddress& address, uint8_t retryCount = 0) const; | ||
bool getAddress(DeviceAddress deviceAddress, uint8_t index) const; | ||
bool isParasitePowerMode() const; | ||
|
||
// Utility Methods | ||
static float toFahrenheit(float celsius); | ||
static float toCelsius(float fahrenheit); | ||
static float rawToCelsius(int32_t raw); | ||
static float rawToFahrenheit(int32_t raw); | ||
// Scratchpad Operations | ||
bool readPowerSupply(const DeviceAddress deviceAddress = nullptr) const; | ||
|
||
private: | ||
bool parasitePowerMode = false; | ||
uint8_t bitResolution = 9; | ||
OneWire* oneWire = nullptr; | ||
uint8_t pullupPin = 0; | ||
|
||
bool readScratchPad(const DeviceAddress& address, ScratchPad& scratchPad) const; | ||
bool readPowerSupply(const DeviceAddress& address) const; | ||
void activateExternalPullup() const; | ||
void deactivateExternalPullup() const; | ||
bool parasitePowerMode = false; | ||
uint8_t deviceCount = 0; | ||
|
||
int32_t calculateTemperature(const DeviceAddress& address, const ScratchPad& scratchPad) const; | ||
// Helper Methods | ||
void resetSearch() const; | ||
}; | ||
|
||
} // namespace Dallas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters