-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Battery): use analog float sensor
- Loading branch information
Showing
18 changed files
with
55 additions
and
84 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
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
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,33 +1,35 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#include <senseshift/input/sensor.hpp> | ||
|
||
#include <Arduino.h> | ||
|
||
namespace SenseShift::Arduino::Input { | ||
using IAnalogSensor = ::SenseShift::Input::ISimpleSensor<uint16_t>; | ||
|
||
template<bool Invert = false> | ||
class AnalogSensor : public IAnalogSensor { | ||
uint8_t pin_; | ||
class AnalogSensor : public ::SenseShift::Input::IFloatSensor { | ||
std::uint8_t pin_; | ||
|
||
public: | ||
AnalogSensor(const uint8_t pin) : pin_(pin) {} | ||
AnalogSensor(const std::uint8_t pin) : pin_(pin) {} | ||
|
||
void init() override { pinMode(this->pin_, INPUT); }; | ||
|
||
[[nodiscard]] auto getValue() -> uint16_t override; | ||
[[nodiscard]] auto getValue() -> float override; | ||
}; | ||
|
||
template<> | ||
[[nodiscard]] inline auto AnalogSensor<false>::getValue() -> uint16_t | ||
[[nodiscard]] inline auto AnalogSensor<false>::getValue() -> float | ||
{ | ||
return analogRead(this->pin_); | ||
const auto raw = analogRead(this->pin_); | ||
return static_cast<float>(raw) / ANALOG_MAX; | ||
} | ||
|
||
template<> | ||
[[nodiscard]] inline auto AnalogSensor<true>::getValue() -> uint16_t | ||
[[nodiscard]] inline auto AnalogSensor<true>::getValue() -> float | ||
{ | ||
return ANALOG_MAX - analogRead(this->pin_); | ||
const auto raw = ANALOG_MAX - analogRead(this->pin_); | ||
return static_cast<float>(raw) / ANALOG_MAX; | ||
} | ||
} // namespace SenseShift::Arduino::Input |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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