-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Leka - LekaOS | ||
# Copyright 2022 APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_library(CoreTouchSensor STATIC) | ||
|
||
target_include_directories(CoreTouchSensor | ||
PUBLIC | ||
include | ||
) | ||
|
||
target_sources(CoreTouchSensor | ||
PRIVATE | ||
source/CoreTouchSensor.cpp | ||
) | ||
|
||
target_link_libraries(CoreTouchSensor | ||
PRIVATE | ||
mbed-os | ||
CoreI2C | ||
CoreIOExpander | ||
CoreQDAC | ||
IOKit | ||
) | ||
|
||
if (${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests") | ||
|
||
leka_unit_tests_sources( | ||
tests/CoreTouchSensor_test.cpp | ||
) | ||
|
||
endif() |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "drivers/interfaces/InterfaceDigitalIn.h" | ||
#include "drivers/interfaces/InterfaceDigitalOut.h" | ||
|
||
#include "interface/drivers/QDAC.h" | ||
#include "interface/drivers/TouchSensor.h" | ||
|
||
namespace leka { | ||
|
||
class CoreTouchSensor : public interface::TouchSensor | ||
{ | ||
public: | ||
explicit CoreTouchSensor(mbed::interface::DigitalIn &detect_pin, mbed::interface::DigitalOut &power_mode_pin, | ||
interface::QDAC &dac, Channel channel) | ||
: _detect_pin(detect_pin), _power_mode_pin(power_mode_pin), _sensitivity_pin({dac, channel}) | ||
{ | ||
_detect_pin.mode(PinMode::PullUp); | ||
_sensitivity_pin.dac.init(); | ||
} | ||
auto read() -> int final; | ||
void setPowerMode(PowerMode power_mode) final; | ||
void setSensitivity(uint16_t value, bool saved = false) final; | ||
|
||
private: | ||
mbed::interface::DigitalIn &_detect_pin; | ||
mbed::interface::DigitalOut &_power_mode_pin; | ||
struct AnalogOut { | ||
interface::QDAC &dac; | ||
Channel channel; | ||
}; | ||
AnalogOut _sensitivity_pin; | ||
}; | ||
} // namespace leka |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreTouchSensor.h" | ||
|
||
using namespace leka; | ||
|
||
auto CoreTouchSensor::read() -> int | ||
{ | ||
return _detect_pin.read(); | ||
} | ||
|
||
void CoreTouchSensor::setPowerMode(PowerMode power_mode) | ||
{ | ||
auto pm = static_cast<uint8_t>(power_mode); | ||
_power_mode_pin.write(pm); | ||
} | ||
|
||
void CoreTouchSensor::setSensitivity(uint16_t value, bool saved) | ||
{ | ||
_sensitivity_pin.dac.write(_sensitivity_pin.channel, value, saved); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreTouchSensor.h" | ||
|
||
#include "IOKit/DigitalIn.h" | ||
#include "IOKit/DigitalOut.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "mocks/leka/CoreI2C.h" | ||
#include "mocks/leka/CoreQDAC.h" | ||
#include "mocks/leka/IOExpander.h" | ||
|
||
using namespace leka; | ||
|
||
using ::testing::Args; | ||
using ::testing::DoAll; | ||
using ::testing::ElementsAre; | ||
using ::testing::Return; | ||
using ::testing::SetArrayArgument; | ||
|
||
class CoreTouchSensorTest : public ::testing::Test | ||
{ | ||
protected: | ||
// void SetUp() override {} | ||
// void TearDown() override {} | ||
|
||
mock::IOExpander<uint16_t> mockIOExpander {}; | ||
uint8_t pin_number {0x0001}; | ||
|
||
leka::io::expanded::DigitalIn<> in {mockIOExpander, pin_number}; | ||
leka::io::expanded::DigitalOut<> out {mockIOExpander, pin_number}; | ||
mock::CoreQDAC dac {}; | ||
Channel channel {Channel::B}; | ||
|
||
CoreTouchSensor sensor {in, out, dac, channel}; | ||
}; | ||
|
||
TEST_F(CoreTouchSensorTest, initializationDefault) | ||
{ | ||
EXPECT_CALL(dac, init).Times(1); | ||
auto new_sensor = CoreTouchSensor {in, out, dac, channel}; | ||
ASSERT_NE(&new_sensor, nullptr); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, read) | ||
{ | ||
auto expected_read = 0x01; | ||
EXPECT_CALL(mockIOExpander, readPin(pin_number)).Times(1).WillOnce(Return(expected_read)); | ||
auto actual_read = sensor.read(); | ||
|
||
EXPECT_EQ(actual_read, expected_read); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, setPowerMode) | ||
{ | ||
auto power_mode = PowerMode::low; | ||
auto expected_value = static_cast<uint8_t>(power_mode); | ||
EXPECT_CALL(mockIOExpander, writePin(pin_number, expected_value)).Times(1); | ||
sensor.setPowerMode(power_mode); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, setSensitivity) | ||
{ | ||
EXPECT_CALL(dac, write(channel, 0x0ABC, false)).Times(1); | ||
auto value = 0x0ABC; | ||
sensor.setSensitivity(value); | ||
} |
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