Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ (spikes): Add lk_led_ #473

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ladislas marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}