Skip to content

Commit

Permalink
✨ (drivers): Add CoreTouchSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
MMyster committed Jun 28, 2022
1 parent 32a9d3e commit e37fa96
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
1 change: 1 addition & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ add_subdirectory(${DRIVERS_DIR}/FastLED)
# Touch drivers
add_subdirectory(${DRIVERS_DIR}/CoreIOExpander)
add_subdirectory(${DRIVERS_DIR}/CoreDACTouch)
add_subdirectory(${DRIVERS_DIR}/CoreTouchSensor)


1 change: 0 additions & 1 deletion drivers/CoreDACTouch/tests/CoreDACTouch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ using ::testing::Return;
using ::testing::SetArrayArgument;

class CoreDACTouchTest : public ::testing::Test

{
protected:
// void SetUp() override {}
Expand Down
31 changes: 31 additions & 0 deletions drivers/CoreTouchSensor/CMakeLists.txt
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()
36 changes: 36 additions & 0 deletions drivers/CoreTouchSensor/include/CoreTouchSensor.h
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
7 changes: 7 additions & 0 deletions drivers/CoreTouchSensor/source/CoreTouchSensor.cpp
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"
65 changes: 65 additions & 0 deletions drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp
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);
}

0 comments on commit e37fa96

Please sign in to comment.