Skip to content

Commit

Permalink
[example] Add ETL examples with assertion
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael Lehmann <raphael@rleh.de>
  • Loading branch information
salkinium and rleh committed Oct 12, 2021
1 parent 1f58472 commit 2ef7a29
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/generic/etl/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <etl/unordered_map.h>
#include <numbers>

using namespace std::chrono_literals;

int main()
{
Board::initialize();

while (true)
{
// Create an unordered_map of three strings (that map to strings)
etl::unordered_map<uint8_t, double, 3> u = {
{15, std::numbers::pi},
{42, std::numbers::e},
{87, std::numbers::sqrt2}
};

if (Board::Button::read()) {
// Access non-existant element causing an assertion
MODM_LOG_INFO << u[12];
}

MODM_LOG_INFO << "Iterate and print keys and values using structured binding (since C++17):\n";
for( const auto& [key, value] : u ) {
MODM_LOG_INFO << "Key:[" << key << "] Value:[" << value << "]\n";
}

modm::delay(5000ms);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/generic/etl/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-f439zi</extends>
<options>
<option name="modm:build:build.path">../../../build/generic/etl</option>
</options>
<modules>
<module>modm:etl</module>
<module>modm:build:scons</module>
</modules>
</library>
36 changes: 36 additions & 0 deletions examples/linux/etl/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, Raphael Lehmann
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <etl/unordered_map.h>
#include <numbers>
#include <chrono>
#include <modm/debug/logger.hpp>

using namespace std::chrono_literals;

int main()
{
// Create an unordered_map of three strings (that map to strings)
etl::unordered_map<uint8_t, double, 3> u = {
{15, std::numbers::pi},
{42, std::numbers::e},
{87, std::numbers::sqrt2}
};

MODM_LOG_INFO << "Iterate and print keys and values using structured binding (since C++17):\n";
for( const auto& [key, value] : u ) {
MODM_LOG_INFO << "Key:[" << key << "] Value:[" << value << "]\n";
}

// Access non-existant element causing an assertion
MODM_LOG_INFO << u[12];

return 0;
}
13 changes: 13 additions & 0 deletions examples/linux/etl/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<library>
<!-- CI: run fail -->
<options>
<option name="modm:target">hosted-linux</option>
<option name="modm:build:build.path">../../../build/linux/etl</option>
</options>
<modules>
<module>modm:etl</module>
<module>modm:debug</module>
<module>modm:platform:core</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit 2ef7a29

Please sign in to comment.