Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added fixes
  • Loading branch information
nihal-sahu committed Apr 4, 2022
commit 514b07b95c77dc951df31222321ed1e91f356d80
10 changes: 10 additions & 0 deletions libs/sensors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ target_link_libraries(CurrentSensor
Sensor
mbed-os
)

add_library(ProximitySwitch STATIC)
target_sources(ProximitySwitch PRIVATE src/ProximitySwitch.cpp)
target_include_directories(ProximitySwitch PUBLIC include)
target_link_libraries(ProximitySwitch
PRIVATE
Sensor
mbed-os
Logger
)
12 changes: 6 additions & 6 deletions libs/sensors/include/ProximitySwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ProximitySwitch final : Sensor {
public:
ProximitySwitch(PinName proximity_in);

// read returns 1 for HIGH, and 0 for LOW
float read() override{};
float alternateRead() override{};
bool getStatus() const override{};
[[nodiscard]] bool reset() override;
[[nodiscard]] bool update() override;
// read() returns 1 for HIGH, 0 for LOW, and 2 for ERROR
float read() override
float alternateRead() override{}
bool getStatus() const override{}
[[nodiscard]] bool reset() override{}
[[nodiscard]] bool update() override{}

private:
AnalogIn m_proximity_in_adc;
Expand Down
11 changes: 8 additions & 3 deletions libs/sensors/src/ProximitySwitch.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include "ProximitySwitch.h"

#include "Logger.h"

using namespace Sensor;

ProximitySwitch::ProximitySwitch(PinName proximity_in) : m_proximity_in_adc(proximity_in) {}

/*https://www.dfrobot.com/product-2025.html*/
float ProximitySwitch::read() {
float proximity_reading = m_proximity_in_adc.read();

return proximity_reading;
if (m_proximity_in_adc.is_connected()) {
return m_proximity_in_adc.read()
} else {
Utility::logger << "ERROR: Sensor pin not connected";
return 2;
}
}