Skip to content

Commit

Permalink
🎨 (spike): Update lk_touch_sensor_kit
Browse files Browse the repository at this point in the history
  • Loading branch information
MMyster committed Jul 22, 2022
1 parent 7d10ef4 commit d98bdf7
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 7 deletions.
8 changes: 8 additions & 0 deletions drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

#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;
Expand Down
2 changes: 1 addition & 1 deletion libs/TouchSensorKit/include/TouchSensorKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "CoreTouchSensor.h"
#include "LogKit.h"
#include "external/TouchSensorSystem.h"
#include "internal/TouchSensorSystem.h"

namespace leka {

Expand Down
5 changes: 5 additions & 0 deletions spikes/lk_touch_sensor_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ target_sources(spike_lk_touch_sensor_kit

target_link_libraries(spike_lk_touch_sensor_kit
TouchSensorKit
CoreEventFlags
CoreLED
CoreSPI
EventLoopKit
LedKit
)

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

#pragma once

#include "PinNames.h"

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

#include "CoreEventFlags.h"
#include "CoreLED.h"
#include "CoreSPI.h"
#include "EventLoopKit.h"
#include "HelloWorld.h"
#include "LedKit.h"
#include "LogKit.h"

using namespace leka;
using namespace std::chrono;

namespace leds {

namespace internal {

namespace ears {

auto spi = CoreSPI {LED_EARS_SPI_MOSI, NC, LED_EARS_SPI_SCK};
constexpr auto size = 2;

} // namespace ears

namespace belt {

auto spi = CoreSPI {LED_BELT_SPI_MOSI, NC, LED_BELT_SPI_SCK};
constexpr auto size = 20;

} // namespace belt

namespace animations {

auto event_loop = EventLoopKit {};

} // namespace animations

} // namespace internal

auto ears = CoreLED<internal::ears::size> {internal::ears::spi};
auto belt = CoreLED<internal::belt::size> {internal::belt::spi};

void turnOn()
{
ears.setColor(RGB::pure_blue);
belt.setColor(RGB::pure_blue);
ears.show();
belt.show();
}
void turnOff()
{
ears.setColor(RGB::black);
belt.setColor(RGB::black);
ears.show();
belt.show();
}

auto ledkit = LedKit {leds::internal::animations::event_loop, leds::ears, leds::belt};

} // namespace leds
75 changes: 69 additions & 6 deletions spikes/lk_touch_sensor_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,68 @@
#include "rtos/ThisThread.h"

#include "HelloWorld.h"
#include "Leds.h"
#include "LogKit.h"
#include "TouchSensorKit.h"

using namespace leka;
using namespace std::chrono;

namespace TouchLed {
struct Ear {
Position position;
uint8_t index;
};

auto ears = std::array<Ear, 2> {Ear {Position::ear_left, 1}, Ear {Position::ear_right, 0}};

struct Belt {
Position position;
uint8_t start_index;
uint8_t end_index;
};

auto belt = std::array<Belt, 4> {Belt {Position::belt_left_back, 16, 18}, Belt {Position::belt_left_front, 10, 13},
Belt {Position::belt_right_back, 6, 9}, Belt {Position::belt_right_front, 1, 3}};

void setColorEar(Ear ear, RGB color)
{
leds::ears.setColorAtIndex(ear.index, color);
leds::ears.show();
}

void setColorBelt(Belt belt, RGB color)
{
leds::belt.setColorRange(belt.start_index, belt.end_index, color);
leds::belt.show();
}
} // namespace TouchLed

auto touch_sensor_kit = TouchSensorKit();

void printState()
{
log_info("Ear left touched: %s", touch_sensor_kit.isTouched(Position::ear_left) ? "true" : "false");
log_info("Ear right touched: %s", touch_sensor_kit.isTouched(Position::ear_right) ? "true" : "false");
log_info("Belt left front touched: %s", touch_sensor_kit.isTouched(Position::belt_left_front) ? "true" : "false");
log_info("Belt left back touched: %s", touch_sensor_kit.isTouched(Position::belt_left_back) ? "true" : "false");
log_info("Belt right front touched: %s", touch_sensor_kit.isTouched(Position::belt_right_front) ? "true" : "false");
log_info("Belt right back touched: %s", touch_sensor_kit.isTouched(Position::belt_left_back) ? "true" : "false");
log_info("\n\n");
}

void updateLeds()
{
for (TouchLed::Ear touchled: TouchLed::ears) {
touch_sensor_kit.isTouched(touchled.position) ? TouchLed::setColorEar(touchled, RGB::pure_blue)
: TouchLed::setColorEar(touchled, RGB::black);
}
for (TouchLed::Belt touchled: TouchLed::belt) {
touch_sensor_kit.isTouched(touchled.position) ? TouchLed::setColorBelt(touchled, RGB::pure_blue)
: TouchLed::setColorBelt(touchled, RGB::black);
}
}

auto main() -> int
{
logger::init();
Expand All @@ -21,8 +77,7 @@ auto main() -> int

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

auto touch_sensor_kit = TouchSensorKit();
touch_sensor_kit.setup();
touch_sensor_kit.init();

auto start = rtos::Kernel::Clock::now();

Expand All @@ -31,14 +86,22 @@ auto main() -> int
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
touch_sensor_kit.adjustSensitivity(0, true);
for (Position position: positions) {
touch_sensor_kit.setSensitivity(position, 0x000F, true);
}
rtos::ThisThread::sleep_for(2s);

auto updateLeds_func = [&]() { updateLeds(); };
auto printState_func = [&]() { printState(); };

touch_sensor_kit.resetByPowerMode();
// touch_sensor_kit.registerOnSensorTouched(printState_func);

rtos::ThisThread::sleep_for(500ms);

while (true) {
touch_sensor_kit.updateState();
touch_sensor_kit.printState();
updateLeds();
touch_sensor_kit.resetByPowerMode();
log_info("\n\n");
rtos::ThisThread::sleep_for(1s);
}
}

0 comments on commit d98bdf7

Please sign in to comment.