Skip to content

Commit

Permalink
✨ (spikes): Add lk_touch_sensor_kit
Browse files Browse the repository at this point in the history
Co-Authored-By: YannL <yann.locatelli2@gmail.com>
  • Loading branch information
2 people authored and ladislas committed Jan 13, 2023
1 parent 3ad9a78 commit dc05206
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity)
add_subdirectory(${SPIKES_DIR}/lk_sensors_touch)
add_subdirectory(${SPIKES_DIR}/lk_serial_number)
add_subdirectory(${SPIKES_DIR}/lk_ticker_timeout)
add_subdirectory(${SPIKES_DIR}/lk_touch_sensor_kit)
add_subdirectory(${SPIKES_DIR}/lk_watchdog_isr)
add_subdirectory(${SPIKES_DIR}/lk_wifi)

Expand Down Expand Up @@ -75,6 +76,7 @@ add_dependencies(spikes_leka
spike_lk_sensors_touch
spike_lk_serial_number
spike_lk_ticker_timeout
spike_lk_touch_sensor_kit
spike_lk_wifi

spike_lk_update_process_app_base
Expand Down
29 changes: 29 additions & 0 deletions spikes/lk_touch_sensor_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_touch_sensor_kit)

target_include_directories(spike_lk_touch_sensor_kit
PRIVATE
.
)

target_sources(spike_lk_touch_sensor_kit
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_touch_sensor_kit
CoreI2C
CoreSPI
CoreIOExpander
IOKit
CoreQDAC
CoreTouchSensor
TouchSensorKit
CoreLED
LedKit
)

target_link_custom_leka_targets(spike_lk_touch_sensor_kit)
174 changes: 174 additions & 0 deletions spikes/lk_touch_sensor_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "drivers/BufferedSerial.h"
#include "rtos/ThisThread.h"

#include "CoreI2C.h"
#include "CoreIOExpander.h"
#include "CoreQDAC.h"
#include "CoreTouchSensor.h"
#include "DigitalOut.h"
#include "HelloWorld.h"
#include "IOKit/DigitalIn.h"
#include "IOKit/DigitalOut.h"
#include "LogKit.h"
#include "TouchSensorKit.h"

using namespace leka;
using namespace std::chrono_literals;

namespace touch {

inline auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
inline auto io_expander_reset = mbed::DigitalOut {PinName::SENSOR_PROXIMITY_MUX_RESET, 0};
inline auto io_expander = CoreIOExpanderMCP23017 {corei2c, io_expander_reset};

namespace detect_pin {

inline auto ear_left = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB5};
inline auto ear_right = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB4};
inline auto belt_left_front = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB3};
inline auto belt_left_back = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB2};
inline auto belt_right_back = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB1};
inline auto belt_right_front = io::expanded::DigitalIn<> {io_expander, mcp23017::pin::PB0};

} // namespace detect_pin

namespace power_mode_pin {

inline auto ear_left = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA5};
inline auto ear_right = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA4};
inline auto belt_left_front = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA3};
inline auto belt_left_back = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA2};
inline auto belt_right_back = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA1};
inline auto belt_right_front = io::expanded::DigitalOut<> {io_expander, mcp23017::pin::PA0};

} // namespace power_mode_pin

namespace dac {

inline auto left = CoreQDACMCP4728 {corei2c, 0xC2};
inline auto right = CoreQDACMCP4728 {corei2c, 0xC0};

namespace channel {

inline auto ear_left = mcp4728::channel::C;
inline auto ear_right = mcp4728::channel::C;
inline auto belt_left_back = mcp4728::channel::A;
inline auto belt_left_front = mcp4728::channel::B;
inline auto belt_right_back = mcp4728::channel::B;
inline auto belt_right_front = mcp4728::channel::A;

} // namespace channel
} // namespace dac

namespace sensor {

inline auto ear_left =
CoreTouchSensor {detect_pin::ear_left, power_mode_pin::ear_left, dac::left, dac::channel::ear_left};
inline auto ear_right =
CoreTouchSensor {detect_pin::ear_right, power_mode_pin::ear_right, dac::right, dac::channel::ear_right};
inline auto belt_left_back = CoreTouchSensor {detect_pin::belt_left_back, power_mode_pin::belt_left_back, dac::left,
dac::channel::belt_left_back};
inline auto belt_left_front = CoreTouchSensor {detect_pin::belt_left_front, power_mode_pin::belt_left_front,
dac::left, dac::channel::belt_left_front};
inline auto belt_right_back = CoreTouchSensor {detect_pin::belt_right_back, power_mode_pin::belt_right_back,
dac::right, dac::channel::belt_right_back};
inline auto belt_right_front = CoreTouchSensor {detect_pin::belt_right_front, power_mode_pin::belt_right_front,
dac::right, dac::channel::belt_right_front};
} // namespace sensor

} // namespace touch

auto hello = HelloWorld {};

auto touch_sensor_kit =
TouchSensorKit {touch::sensor::ear_left, touch::sensor::ear_right, touch::sensor::belt_left_back,
touch::sensor::belt_left_front, touch::sensor::belt_right_back, touch::sensor::belt_right_front};

void printSensorTouched(Position position)
{
switch (position) {
case Position::ear_left:
log_info("Ear left is touched");
break;
case Position::ear_right:
log_info("Ear right is touched");
break;
case Position::belt_left_front:
log_info("Belt left front is touched");
break;
case Position::belt_left_back:
log_info("Belt left back is touched");
break;
case Position::belt_right_front:
log_info("Belt right front is touched");
break;
case Position::belt_right_back:
log_info("Belt right back is touched");
break;
default:
break;
}
}

void printSensorReleased(Position position)
{
switch (position) {
case Position::ear_left:
log_info("Ear left is released");
break;
case Position::ear_right:
log_info("Ear right is released");
break;
case Position::belt_left_front:
log_info("Belt left front is released");
break;
case Position::belt_left_back:
log_info("Belt left back is released");
break;
case Position::belt_right_front:
log_info("Belt right front is released");
break;
case Position::belt_right_back:
log_info("Belt right back is released");
break;
default:
break;
}
}

auto main() -> int
{
logger::init();

HelloWorld hello {};
hello.start();

log_info("Hello, World!\n\n");

rtos::ThisThread::sleep_for(2s);

touch_sensor_kit.registerOnSensorTouched(printSensorTouched);
touch_sensor_kit.registerOnSensorReleased(printSensorReleased);

touch_sensor_kit.initialize();
touch_sensor_kit.setRefreshDelay(20ms);

log_info("Enable touch for 10s");
touch_sensor_kit.enable();
rtos::ThisThread::sleep_for(10s);

log_info("Disable touch for 10s");
touch_sensor_kit.disable();
rtos::ThisThread::sleep_for(10s);

log_info("Enable Touch");
touch_sensor_kit.enable();
while (true) {
log_info("Still alive");
rtos::ThisThread::sleep_for(5s);
}
}

0 comments on commit dc05206

Please sign in to comment.