Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <random>
#include <sstream>

template<typename EngineType>
auto do_something() -> void;

template<typename EngineType>
auto do_something() -> void
{
Expand Down Expand Up @@ -61,6 +64,8 @@ auto do_something() -> void
std::cout << strm.str() << std::endl;
}

auto main() -> int;

auto main() -> int
{
// Generate 8 sequences of 3 pseudo-random numbers.
Expand All @@ -77,8 +82,8 @@ auto main() -> int
// Generate 8 sequences of 3 pseudo-random numbers.
for(std::uint_fast8_t i = { UINT8_C(0) }; i < std::uint_fast8_t { UINT8_C(8) }; ++i)
{
// For std::mt19937_64.
using eng64_type = std::mt19937_64;
// For std::mt19937_64.
using eng64_type = std::mt19937_64;

do_something<eng64_type>();
}
Expand Down
14 changes: 7 additions & 7 deletions examples/chapter09_08/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
@rem build.bat directory_of_gcc_bin prefix_of_avr_gcc

@rem Usage example A,
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr

@rem Usage example A1 (use a relative tool path),
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat ".\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat ".\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr

@rem Usage example B,
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat "C:\Program Files (x86)\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08"
@rem build.bat "C:\Program Files (x86)\gcc-15.1.0-avr\bin" avr


@set TOOL_PATH=%1
@set TOOL_PREFIX=%2

@set CFLAGS=-Wall -Wextra -Wpedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions
@set CFLAGS=-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -fno-exceptions
@set CPPFLAGS=-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs
@set CINCLUDES=-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr

Expand Down
12 changes: 6 additions & 6 deletions examples/chapter09_08/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# If command
# /usr/bin/avr-g++
# installed, e.g. via command apt-get install gcc-avr avr-libc
# installed, e.g. via command sudo apt-get install gcc-avr avr-libc
# then:
# ./build.sh
#
Expand All @@ -23,11 +23,11 @@
#
# Usage example A (from *nix shell)
# cd /usr/local/real-time-cpp/examples/chapter09_08
# ./build.sh /usr/local/real-time-cpp/examples/chapter09_08/tools/Util/MinGW/msys/1.0/local/gcc-9.2.0-avr/bin avr
# ./build.sh /usr/local/real-time-cpp/examples/chapter09_08a/tools/Util/msys64/usr/local/gcc-15.1.0-avr/bin avr

# Usage example B (from Win* shell such as in Git for Win*)
# cd C:/Users/User/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08
# ./build.sh C:/Users/User/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08/tools/Util/MinGW/msys/1.0/local/gcc-9.2.0-avr/bin avr
# cd C:/Users/ckorm/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08
# ./build.sh C:/Users/ckorm/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08/tools/Util/msys64/usr/local/gcc-15.1.0-avr/bin avr

if [[ $# == 0 ]]; then ## $# is the number of arguments
if [[ -n "$(which avr-g++)" ]]; then ## -n tests if string is not empty
Expand All @@ -47,9 +47,9 @@ else
TOOL_PREFIX="$2"
fi

CFLAGS="-Wall -Wextra -pedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions -gdwarf-2 -ffunction-sections -fdata-sections"
CFLAGS="-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -finline-functions -finline-limit=64 -fno-exceptions -gdwarf-2 -ffunction-sections -fdata-sections"
CPPFLAGS="-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs"
CINCLUDES="-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr"
CINCLUDES="-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc/mcal/avr -Isrc"

echo
echo "Building with : build.sh"
Expand Down
2 changes: 2 additions & 0 deletions examples/chapter09_08/chapter09_08.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@
<ClInclude Include="src\util\utility\util_utype_helper.h" />
</ItemGroup>
<ItemGroup>
<None Include="build.bat" />
<None Include="build.sh" />
<None Include="src\util\STL\algorithm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
Expand Down
2 changes: 2 additions & 0 deletions examples/chapter09_08/chapter09_08.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@
<None Include="src\util\STL\ctime">
<Filter>src\util\STL</Filter>
</None>
<None Include="build.bat" />
<None Include="build.sh" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\chapter09_08.rc">
Expand Down
127 changes: 79 additions & 48 deletions examples/chapter09_08/src/app/led/app_led.cpp
Original file line number Diff line number Diff line change
@@ -1,97 +1,128 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2018.
// Copyright Christopher Kormanyos 2007 - 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <cstdint>

#include <mcal/mcal_led_monochrome.h>
#include <mcal/mcal_led_rgb.h>
#include <util/utility/util_time.h>

#include <cstdint>
#include <cstdlib>

namespace app
{
namespace led
{
void task_init();
void task_func();
auto task_init() -> void;
auto task_func() -> void;
}
}

namespace
auto app::led::task_init() -> void
{
using app_led_monochrome_timer_type = util::timer<std::uint32_t>;
using app_led_rgb_timer_type = util::timer<std::uint16_t>;

app_led_monochrome_timer_type app_led_monochrome_timer(app_led_monochrome_timer_type::seconds(1U));
app_led_rgb_timer_type app_led_rgb_timer (app_led_rgb_timer_type::milliseconds(20U));
mcal::led::led_monochrome0().on();

std::uint_fast8_t app_led_hue_r = UINT8_C(255);
std::uint_fast8_t app_led_hue_g;
std::uint_fast8_t app_led_hue_b;
mcal::led::led_rgb0().set_color(UINT8_C(255), UINT8_C(0), UINT8_C(0));
}

void app::led::task_init()
auto app::led::task_func() -> void
{
mcal::led::led_monochrome0().on();
using app_led_monochrome_timer_type = util::timer<std::uint32_t>;

mcal::led::led_rgb0().set_color(app_led_hue_r,
app_led_hue_g,
app_led_hue_b);
}
static app_led_monochrome_timer_type app_led_monochrome_timer { app_led_monochrome_timer_type::seconds(UINT8_C(1)) };

void app::led::task_func()
{
if(app_led_monochrome_timer.timeout())
{
// Toggle the monochrome user LED at 1/2 Hz.
mcal::led::led_monochrome0().toggle();

// Start the next timer interval for the monochrome user LED.
// Start the next 1s timer interval for the monochrome user LED.
app_led_monochrome_timer.start_interval(app_led_monochrome_timer_type::seconds(1U));
}

// Define the color transition states.
enum class color_transition_type
{
red_to_yellow,
yellow_to_green,
green_to_cyan,
cyan_to_blue,
blue_to_magenta,
magenta_to_red
};

using app_led_rgb_timer_type = util::timer<std::uint16_t>;

static app_led_rgb_timer_type app_led_rgb_timer { app_led_rgb_timer_type::milliseconds(UINT8_C(30)) };

if(app_led_rgb_timer.timeout())
{
// Animate the RGB LED with the colors of the spectrum at 50 Hz.
// Initialize the color hues.
static std::uint_fast8_t app_led_hue_r { UINT8_C(255) };
static std::uint_fast8_t app_led_hue_g { UINT8_C(0) };
static std::uint_fast8_t app_led_hue_b { UINT8_C(0) };

// Initialize the color transition state.
static color_transition_type color_transition_state { color_transition_type::red_to_yellow };

// Animate the RGB LED with the colors of the spectrum.

const auto rgb_hue_sum =
static_cast<std::uint_fast16_t>
(
static_cast<std::uint_fast16_t>(app_led_hue_r)
+ static_cast<std::uint_fast16_t>(app_led_hue_g)
+ static_cast<std::uint_fast16_t>(app_led_hue_b)
);

// Define the color transition states.
typedef enum color_transition_enum
const bool rgb_hue_sum_is_in_bump_range
{
red_to_yellow,
yellow_to_green,
green_to_cyan,
cyan_to_blue,
blue_to_magenta,
magenta_to_red
(rgb_hue_sum >= std::uint_fast16_t { UINT16_C(250) })
&& (rgb_hue_sum <= std::uint_fast16_t { UINT16_C(260) })
};

const bool rgb_hue_is_near_bump_point
{
((app_led_hue_r > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range)
|| ((app_led_hue_g > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range)
|| ((app_led_hue_b > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range)
};

unsigned color_persist_time { UINT8_C(30) };

if(rgb_hue_is_near_bump_point)
{
const auto delta_bump_point = std::abs(static_cast<int>(rgb_hue_sum) - static_cast<int>(INT16_C(255)));

if (delta_bump_point == int { INT8_C(0) }) { color_persist_time = unsigned { UINT16_C(600) }; }
else if(delta_bump_point == int { INT8_C(1) }) { color_persist_time = unsigned { UINT16_C(500) }; }
else if(delta_bump_point == int { INT8_C(2) }) { color_persist_time = unsigned { UINT16_C(400) }; }
else if(delta_bump_point == int { INT8_C(3) }) { color_persist_time = unsigned { UINT16_C(300) }; }
else if(delta_bump_point == int { INT8_C(4) }) { color_persist_time = unsigned { UINT16_C(200) }; }
else { color_persist_time = unsigned { UINT16_C(100) }; }
}
color_transition_type;

// Initialize the color transition state.
static color_transition_type color_transition_state = red_to_yellow;
// Make a smooth color transition and increment the color
// transition state if necessary.

// Make a smooth color transition and
// increment the color transition state
// if necessary.
switch(color_transition_state)
{
case red_to_yellow: { if(++app_led_hue_g == UINT8_C(255)) { color_transition_state = yellow_to_green; } } break;
case yellow_to_green: { if(--app_led_hue_r == UINT8_C( 0)) { color_transition_state = green_to_cyan; } } break;
case green_to_cyan: { if(++app_led_hue_b == UINT8_C(255)) { color_transition_state = cyan_to_blue; } } break;
case cyan_to_blue: { if(--app_led_hue_g == UINT8_C( 0)) { color_transition_state = blue_to_magenta; } } break;
case blue_to_magenta: { if(++app_led_hue_r == UINT8_C(255)) { color_transition_state = magenta_to_red; } } break;
case color_transition_type::red_to_yellow: { if(++app_led_hue_g == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::yellow_to_green; } } break;
case color_transition_type::yellow_to_green: { if(--app_led_hue_r == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::green_to_cyan; } } break;
case color_transition_type::green_to_cyan: { if(++app_led_hue_b == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::cyan_to_blue; } } break;
case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::blue_to_magenta; } } break;
case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::magenta_to_red; } } break;
default:
case magenta_to_red: { if(--app_led_hue_b == UINT8_C( 0)) { color_transition_state = red_to_yellow; } } break;
case color_transition_type::magenta_to_red: { if(--app_led_hue_b == static_cast<std::uint_fast8_t>(UINT8_C( 0))) { color_transition_state = color_transition_type::red_to_yellow; } } break;
}

// Write the next color to the RGB LED.
mcal::led::led_rgb0().set_color(app_led_hue_r,
app_led_hue_g,
app_led_hue_b);
mcal::led::led_rgb0().set_color(app_led_hue_r, app_led_hue_g, app_led_hue_b);

// Start the next timer interval for the RGB LED.
app_led_rgb_timer.start_interval(app_led_rgb_timer_type::milliseconds(20U));
app_led_rgb_timer.start_interval(app_led_rgb_timer_type::milliseconds(color_persist_time));
}
}
14 changes: 7 additions & 7 deletions examples/chapter09_08a/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
@rem build.bat directory_of_gcc_bin prefix_of_avr_gcc

@rem Usage example A,
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr

@rem Usage example A1 (use a relative tool path),
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat ".\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat ".\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr

@rem Usage example B,
@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat "C:\Program Files (x86)\gcc-11.2.0-avr\bin" avr
@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a"
@rem build.bat "C:\Program Files (x86)\gcc-15.1.0-avr\bin" avr


@set TOOL_PATH=%1
@set TOOL_PREFIX=%2

@set CFLAGS=-Wall -Wextra -Wpedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions
@set CFLAGS=-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -fno-exceptions
@set CPPFLAGS=-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs
@set CINCLUDES=-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr

Expand Down
Loading
Loading