Skip to content

Commit

Permalink
✨ (spikes): Add lk_coreled spike
Browse files Browse the repository at this point in the history
Test the CoreLED library as a replacement of FastLED.
  • Loading branch information
HPezz authored and ladislas committed Jan 31, 2022
1 parent a95edef commit d26ea7e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions spikes/lk_coreled/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
70 changes: 70 additions & 0 deletions spikes/lk_coreled/main.cpp
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

// #include <cstddef>

#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<RGB, 6> 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);
}
}

0 comments on commit d26ea7e

Please sign in to comment.