-
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
140 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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 | ||
mbed-os | ||
CoreI2C | ||
CoreIOExpander | ||
CoreDACTouch | ||
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,36 @@ | ||
// 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/DACTouch.h" | ||
|
||
namespace leka { | ||
|
||
class CoreTouchSensor | ||
{ | ||
public: | ||
explicit CoreTouchSensor(mbed::interface::DigitalIn &detect_pin, mbed::interface::DigitalOut &power_mode_pin, | ||
interface::DACTouch &sensitivity_dac, uint8_t channel) | ||
: _detect_pin(detect_pin), | ||
_power_mode_pin(power_mode_pin), | ||
_sensitivity_dac(sensitivity_dac), | ||
_channel(channel) {}; | ||
auto read() -> int { return _detect_pin.read(); } | ||
void setPowerMode(int power_mode) { _power_mode_pin.write(power_mode); } | ||
void adjustSensitivity(std::array<uint8_t, 2> value) | ||
{ | ||
_sensitivity_dac.writeToSpecificInputRegister(_channel, value); | ||
} | ||
|
||
private: | ||
mbed::interface::DigitalIn &_detect_pin; | ||
mbed::interface::DigitalOut &_power_mode_pin; | ||
interface::DACTouch &_sensitivity_dac; | ||
uint8_t _channel; | ||
}; | ||
} // 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,7 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "CoreTouchSensor.h" |
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,65 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreTouchSensor.h" | ||
|
||
#include "CoreDACTouch.h" | ||
#include "CoreIOExpander.h" | ||
#include "DigitalOut.h" | ||
#include "IOKit/DigitalIn.h" | ||
#include "IOKit/DigitalOut.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "mocks/leka/CoreI2C.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 {} | ||
|
||
const uint8_t i2c_address {0xC0}; | ||
mock::CoreI2C mocki2c; | ||
CoreDACTouchMCP4728 dac {mocki2c, i2c_address}; | ||
uint8_t channel {1}; | ||
|
||
mbed::DigitalOut io_expander_reset {PinName::SENSOR_PROXIMITY_MUX_RESET, 0}; | ||
CoreIOExpanderMCP23017 io_expander {mocki2c, io_expander_reset}; | ||
uint8_t pin_number {0x0001}; | ||
|
||
leka::io::expanded::DigitalIn<> input {io_expander, pin_number}; | ||
leka::io::expanded::DigitalOut<> power_mode {io_expander, pin_number}; | ||
|
||
CoreTouchSensor sensor {input, power_mode, dac, channel}; | ||
}; | ||
|
||
TEST_F(CoreTouchSensorTest, initializationDefault) | ||
{ | ||
auto new_sensor = CoreTouchSensor {input, power_mode, dac, channel}; | ||
ASSERT_NE(&new_sensor, nullptr); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, read) | ||
{ | ||
sensor.read(); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, setPowerMode) | ||
{ | ||
sensor.setPowerMode(0x01); | ||
} | ||
|
||
TEST_F(CoreTouchSensorTest, adjustSensitivity) | ||
{ | ||
auto value = std::array<uint8_t, 2> {0x0A, 0xBC}; | ||
sensor.adjust_sensitivity(channel, value); | ||
} |