Skip to content

Commit

Permalink
🚧 Rework spike
Browse files Browse the repository at this point in the history
Co-Authored-By: YannL <[email protected]>
  • Loading branch information
YannLocatelli committed Jan 13, 2023
1 parent 5c32048 commit 17b02d9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
14 changes: 8 additions & 6 deletions spikes/lk_touch_sensor_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ 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
main.cpp
)

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

Expand Down
90 changes: 48 additions & 42 deletions spikes/lk_touch_sensor_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
#include "CoreQDAC.h"
#include "CoreTouchSensor.h"
#include "DigitalOut.h"
#include "EventLoopKit.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;
using namespace std::chrono_literals;

namespace touch {

Expand Down Expand Up @@ -81,53 +80,64 @@ namespace sensor {
dac::right, dac::channel::belt_right_front};
} // namespace sensor

namespace sensitivity {

inline constexpr auto low = float {0.5F};
inline constexpr auto medium = float {0.7F};
inline constexpr auto high = float {1.0F};

} // namespace sensitivity

auto event_loop = EventLoopKit {};

} // namespace touch

auto hello = HelloWorld {};

auto touch_sensor_kit = TouchSensorKit {touch::event_loop,
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};
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\n");
log_info("Ear left is touched");
break;
case Position::ear_right:
log_info("Ear right is touched\n");
log_info("Ear right is touched");
break;
case Position::belt_left_front:
log_info("Belt left front is touched\n");
log_info("Belt left front is touched");
break;
case Position::belt_left_back:
log_info("Belt left back is touched\n");
log_info("Belt left back is touched");
break;
case Position::belt_right_front:
log_info("Belt right front is touched\n");
log_info("Belt right front is touched");
break;
case Position::belt_right_back:
log_info("Belt right back is touched\n");
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;
}
rtos::ThisThread::sleep_for(100ms);
}

auto main() -> int
Expand All @@ -139,28 +149,24 @@ auto main() -> int

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

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

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

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));

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

touch_sensor_kit.init();

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

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

auto sleep = [&]() {
rtos::ThisThread::sleep_for(3s);
log_free("\n\n");
};
touch_sensor_kit.registerOnEndRead(sleep);
log_info("Enable touch for 10s");
touch_sensor_kit.enable();
rtos::ThisThread::sleep_for(10s);

touch_sensor_kit.start();
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);
Expand Down

0 comments on commit 17b02d9

Please sign in to comment.