From d26ea7eede4871e5ad3a80431a7b4090cc71fc22 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Fri, 28 Jan 2022 17:36:24 +0100 Subject: [PATCH] :sparkles: (spikes): Add lk_coreled spike Test the CoreLED library as a replacement of FastLED. --- spikes/CMakeLists.txt | 1 + spikes/lk_coreled/CMakeLists.txt | 21 ++++++++++ spikes/lk_coreled/main.cpp | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 spikes/lk_coreled/CMakeLists.txt create mode 100644 spikes/lk_coreled/main.cpp diff --git a/spikes/CMakeLists.txt b/spikes/CMakeLists.txt index 0a1221ff62..1150a00833 100644 --- a/spikes/CMakeLists.txt +++ b/spikes/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(${SPIKES_DIR}/lk_ble) add_subdirectory(${SPIKES_DIR}/lk_cg_animations) add_subdirectory(${SPIKES_DIR}/lk_lcd) add_subdirectory(${SPIKES_DIR}/lk_led) +add_subdirectory(${SPIKES_DIR}/lk_coreled) add_subdirectory(${SPIKES_DIR}/lk_rfid) add_subdirectory(${SPIKES_DIR}/lk_ticker_timeout) add_subdirectory(${SPIKES_DIR}/lk_wifi) diff --git a/spikes/lk_coreled/CMakeLists.txt b/spikes/lk_coreled/CMakeLists.txt new file mode 100644 index 0000000000..95ea519f44 --- /dev/null +++ b/spikes/lk_coreled/CMakeLists.txt @@ -0,0 +1,21 @@ +# Leka - LekaOS +# Copyright 2022 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +add_mbed_executable(spike_lk_coreled) + +target_include_directories(spike_lk_coreled + PRIVATE + . +) + +target_sources(spike_lk_coreled + PRIVATE + main.cpp +) + +target_link_libraries(spike_lk_coreled + CoreLED +) + +target_link_custom_leka_targets(spike_lk_coreled) diff --git a/spikes/lk_coreled/main.cpp b/spikes/lk_coreled/main.cpp new file mode 100644 index 0000000000..5009d9098d --- /dev/null +++ b/spikes/lk_coreled/main.cpp @@ -0,0 +1,70 @@ +// Leka - LekaOS +// Copyright 2022 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +// #include + +#include "PinNames.h" + +#include "rtos/ThisThread.h" + +#include "CoreLED.h" +#include "CoreSPI.h" +#include "HelloWorld.h" +#include "LogKit.h" + +using namespace leka; +using namespace std::chrono; + +auto constexpr NUM_BELT_LEDS = 20; +auto constexpr NUM_EAR_LEDS = 2; + +constexpr std::array colors_available = { + RGB::pure_green, RGB::pure_red, RGB::pure_blue, RGB::yellow, RGB::cyan, RGB::magenta, +}; + +mbed::SPI spi_belt(LED_BELT_SPI_MOSI, NC, LED_BELT_SPI_SCK); +mbed::SPI spi_ear(LED_EARS_SPI_MOSI, NC, LED_EARS_SPI_SCK); + +CoreSPI corespi_belt(spi_belt); +CoreSPI corespi_ear(spi_ear); + +CoreLED belt(corespi_belt, NUM_BELT_LEDS); +CoreLED ears(corespi_ear, NUM_EAR_LEDS); + +void changeColor(interface::LED &ears, interface::LED &belt) +{ + static auto index = uint8_t {0}; + + if (index < colors_available.size()) { + ears.setColor(colors_available.at(index)); + ears.showColor(); + + belt.setColor(colors_available.at(index)); + belt.showColor(); + + index++; + } else { + ears.hideColor(); + belt.hideColor(); + + index = 0; + } +} + +auto main() -> int +{ + logger::init(); + + HelloWorld hello; + hello.start(); + + log_info("Hello, World!\n\n"); + + rtos::ThisThread::sleep_for(2s); + + while (true) { + changeColor(belt, ears); + rtos::ThisThread::sleep_for(1s); + } +}