Skip to content

Commit

Permalink
🚀 (spikes): Add stl_cxxsupport spike
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Jun 3, 2021
1 parent c7235dc commit 1360e03
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_subdirectory(${SPIKES_DIR}/lk_file_manager)
add_subdirectory(${SPIKES_DIR}/lk_sensors_touch)
add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity)

add_subdirectory(${SPIKES_DIR}/stl_cxxsupport)

add_custom_target(spikes_leka)
add_dependencies( spikes_leka
spike_lk_ble
Expand All @@ -48,8 +50,14 @@ add_dependencies( spikes_mbed
spike_mbed_watchdog_ticker_vs_thread
)

add_custom_target(spikes_stl)
add_dependencies( spikes_stl
spike_stl_cxxsupport
)

add_custom_target(spikes)
add_dependencies(spikes
spikes_leka
spikes_mbed
spikes_stl
)
17 changes: 17 additions & 0 deletions spikes/stl_cxxsupport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Leka - LekaOS
# Copyright 2021 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_stl_cxxsupport)

target_include_directories(spike_stl_cxxsupport
PRIVATE
.
)

target_sources(spike_stl_cxxsupport
PRIVATE
main.cpp
)

target_link_custom_leka_targets(spike_stl_cxxsupport)
88 changes: 88 additions & 0 deletions spikes/stl_cxxsupport/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Leka - LekaOS
// Copyright 2021 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include <lstd_array>
#include <lstd_span>

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

#include "HelloWorld.h"
#include "LogKit.h"

using namespace leka;
using namespace std::chrono;

void foo(lstd::span<int> span)
{
log_info("from foo! span size: %i", span.size());
for (const auto &v: span) {
log_info("v: %i", v);
}
}

int main(void)
{
static auto serial = mbed::BufferedSerial(USBTX, USBRX, 115200);
leka::logger::set_print_function([](const char *str, size_t size) { serial.write(str, size); });

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

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

auto hello = HelloWorld();
hello.start();

//
// MARK: - lstd::to_array
//

log_info("Create array with lstd::to_array");

auto arr = lstd::to_array({1, 2, 3, 4});

for (const auto &v: arr) {
log_info("v: %i", v);
}

//
// MARK: - lstd::span
//

log_info("Pass std::array to lstd::span");

foo(arr);

log_info("Create span from array, auto deduce size");

auto span0 = lstd::span {arr};

for (const auto &v: span0) {
log_info("v: %i", v);
}

foo(span0);

log_info("Create span from begin pointer and size");

auto span1 = lstd::span {arr.begin(), 3};

for (const auto &v: span1) {
log_info("v: %i", v);
}

foo(span1);

log_info("Create span from specific i-th element and size - i");

auto span2 = lstd::span {arr.begin() + 2, arr.size() - 2};

for (const auto &v: span2) {
log_info("v: %i", v);
}

foo(span2);

return 1;
}

0 comments on commit 1360e03

Please sign in to comment.