From 3c4a131f3ae805a3c185912f4743002cb8ef1c03 Mon Sep 17 00:00:00 2001
From: ckormanyos <ckormanyos@yahoo.com>
Date: Sat, 13 Jul 2024 09:00:26 +0200
Subject: [PATCH] Update vacuum fluorescent display class

---
 ref_app/src/mcal_vfd/mcal_vfd_base.h         | 24 ++-------
 ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h | 56 ++++++++++----------
 ref_app/src/util/STL/algorithm               | 34 ++++++------
 ref_app/src/util/STL/span                    |  5 +-
 ref_app/src/util/utility/util_display.h      | 16 +++---
 5 files changed, 63 insertions(+), 72 deletions(-)

diff --git a/ref_app/src/mcal_vfd/mcal_vfd_base.h b/ref_app/src/mcal_vfd/mcal_vfd_base.h
index 84101a35b..d33bd5f11 100644
--- a/ref_app/src/mcal_vfd/mcal_vfd_base.h
+++ b/ref_app/src/mcal_vfd/mcal_vfd_base.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-//  Copyright Christopher Kormanyos 2023.
+//  Copyright Christopher Kormanyos 2023 - 2024.
 //  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)
@@ -20,26 +20,10 @@
   class vacuum_fluorescent_display_base : public ::util::display_multiline_base
   {
   public:
-    static constexpr unsigned number_of_lines   = NumberOfLines;
-    static constexpr unsigned number_of_columns = NumberOfColumns;
+    static constexpr auto number_of_rows() noexcept -> unsigned { return NumberOfLines; }
+    static constexpr auto number_of_cols() noexcept -> unsigned { return NumberOfColumns; }
 
-    vacuum_fluorescent_display_base(const vacuum_fluorescent_display_base&) = delete;
-    vacuum_fluorescent_display_base(vacuum_fluorescent_display_base&&) noexcept = delete;
-
-    virtual ~vacuum_fluorescent_display_base() = default;
-
-    auto operator=(const vacuum_fluorescent_display_base&) -> vacuum_fluorescent_display_base& = delete;
-    auto operator=(vacuum_fluorescent_display_base&&) noexcept -> vacuum_fluorescent_display_base& = delete;
-
-    virtual auto init() noexcept -> bool = 0;
-
-    virtual auto write(const char* pstr,
-                       const std::uint_fast8_t length,
-                       const std::uint_fast8_t line_index) -> bool = 0;
-
-    virtual auto clear_line(const unsigned line_number) noexcept -> bool = 0;
-
-    virtual auto set_line_index(const std::uint8_t) noexcept -> bool = 0;
+    ~vacuum_fluorescent_display_base() override = default;
 
   protected:
     vacuum_fluorescent_display_base() = default;
diff --git a/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h b/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h
index 82b4bba83..b58527886 100644
--- a/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h
+++ b/ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-//  Copyright Christopher Kormanyos 2023.
+//  Copyright Christopher Kormanyos 2023 - 2024.
 //  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)
@@ -8,11 +8,11 @@
 #ifndef MCAL_VFD_NEC_FM20X2KB_2023_06_08_H
   #define MCAL_VFD_NEC_FM20X2KB_2023_06_08_H
 
-  #include <array>
-
   #include <mcal_vfd/mcal_vfd_base.h>
   #include <util/utility/util_communication.h>
 
+  #include <array>
+
   namespace mcal { namespace vfd {
 
   class vacuum_fluorescent_display_nec_fm20x2kb
@@ -25,7 +25,7 @@
                                                    static_cast<unsigned>(UINT8_C(40))>;
 
     using cmd_line_buffer_type =
-      std::array<std::uint8_t, static_cast<std::size_t>(base_class_type::number_of_columns + static_cast<unsigned>(UINT8_C(2)))>;
+      std::array<std::uint8_t, static_cast<std::size_t>(base_class_type::number_of_cols() + static_cast<unsigned>(UINT8_C(2)))>;
 
   public:
     explicit vacuum_fluorescent_display_nec_fm20x2kb(util::communication_base& ser)
@@ -33,7 +33,7 @@
 
     ~vacuum_fluorescent_display_nec_fm20x2kb() override = default;
 
-    auto init() noexcept -> bool override
+    auto init() -> bool override
     {
       const auto clr = [this]() { return this->clear_line(static_cast<unsigned>(UINT8_C(0))); };
 
@@ -47,16 +47,16 @@
         constexpr auto cmd_id =
           cmd_id_array_type
           {
-            static_cast<std::uint8_t>(UINT8_C(0x1B)),
-            static_cast<std::uint8_t>(UINT8_C(0x5B)),
-            static_cast<std::uint8_t>(UINT8_C(0x31)),
-            static_cast<std::uint8_t>(UINT8_C(0x31)),
-            static_cast<std::uint8_t>(UINT8_C(0x48))
+            std::uint8_t { UINT8_C(0x1B) },
+            std::uint8_t { UINT8_C(0x5B) },
+            std::uint8_t { UINT8_C(0x31) },
+            std::uint8_t { UINT8_C(0x31) },
+            std::uint8_t { UINT8_C(0x48) }
           };
 
         result_init_is_ok = (my_serial.send_n(cmd_id.cbegin(), cmd_id.cend()) && result_init_is_ok);
 
-        blocking_delay(timer_type::microseconds(static_cast<unsigned>(UINT8_C(500))));
+        blocking_delay(timer_type::microseconds(unsigned { UINT8_C(500) }));
       }
 
       {
@@ -65,36 +65,36 @@
         constexpr auto cmd_tst =
           cmd_tst_array_type
           {
-            static_cast<std::uint8_t>(UINT8_C(0x1B)),
-            static_cast<std::uint8_t>(UINT8_C(0x5B)),
-            static_cast<std::uint8_t>(UINT8_C(0x30)),
-            static_cast<std::uint8_t>(UINT8_C(0x62))
+            std::uint8_t { UINT8_C(0x1B) },
+            std::uint8_t { UINT8_C(0x5B) },
+            std::uint8_t { UINT8_C(0x30) },
+            std::uint8_t { UINT8_C(0x62) }
           };
 
         result_init_is_ok = (my_serial.send_n(cmd_tst.cbegin(), cmd_tst.cend()) && result_init_is_ok);
 
-        blocking_delay(timer_type::microseconds(static_cast<unsigned>(UINT8_C(500))));
+        blocking_delay(timer_type::microseconds(unsigned { UINT8_C(500) }));
       }
 
       result_init_is_ok = (clr() && result_init_is_ok);
 
-      blocking_delay(timer_type::microseconds(static_cast<unsigned>(UINT8_C(500))));
+      blocking_delay(timer_type::microseconds(unsigned { UINT8_C(500) }));
 
       return result_init_is_ok;
     }
 
-    virtual auto write(const char* pstr,
+    auto write(const char* pstr,
                        const std::uint_fast8_t length,
-                       const std::uint_fast8_t line_index = static_cast<std::uint_fast8_t>(UINT8_C(0))) -> bool
+               const std::uint_fast8_t line_index) -> bool override
     {
       static_cast<void>(line_index);
 
       my_cmd_line_buffer.fill(static_cast<std::uint8_t>(' '));
 
-      my_cmd_line_buffer[static_cast<std::size_t>(UINT8_C(0))] = static_cast<std::uint8_t>(UINT8_C(0x1B));
-      my_cmd_line_buffer[static_cast<std::size_t>(UINT8_C(1))] = static_cast<std::uint8_t>(UINT8_C(0x5B));
+      my_cmd_line_buffer[std::size_t {  UINT8_C(0) }] = std::uint8_t { UINT8_C(0x1B) };
+      my_cmd_line_buffer[std::size_t {  UINT8_C(1) }] = std::uint8_t { UINT8_C(0x5B) };
 
-      const auto my_count = (std::min)(static_cast<unsigned>(length), base_class_type::number_of_columns);
+      const auto my_count = (std::min)(static_cast<unsigned>(length), base_class_type::number_of_cols());
 
       std::copy(pstr,
                 pstr + static_cast<std::size_t>(my_count),
@@ -105,17 +105,17 @@
       return result_write_is_ok;
     }
 
-    virtual auto clear_line(const unsigned = static_cast<unsigned>(UINT8_C(0))) noexcept -> bool
+    auto clear_line(const unsigned = static_cast<unsigned>(UINT8_C(0))) -> bool override
     {
       using cmd_clr_array_type = std::array<std::uint8_t, static_cast<std::size_t>(UINT8_C(4))>;
 
       constexpr auto cmd_clr =
         cmd_clr_array_type
         {
-          static_cast<std::uint8_t>(UINT8_C(0x1B)),
-          static_cast<std::uint8_t>(UINT8_C(0x5B)),
-          static_cast<std::uint8_t>(UINT8_C(0x0D)),
-          static_cast<std::uint8_t>(UINT8_C(0x0A))
+          std::uint8_t { UINT8_C(0x1B) },
+          std::uint8_t { UINT8_C(0x5B) },
+          std::uint8_t { UINT8_C(0x0D) },
+          std::uint8_t { UINT8_C(0x0A) }
         };
 
       const auto result_clr_is_ok = my_serial.send_n(cmd_clr.cbegin(), cmd_clr.cend());
@@ -123,7 +123,7 @@
       return result_clr_is_ok;
     }
 
-    auto set_line_index(const std::uint8_t) noexcept -> bool override { return true; }
+    auto set_line_index(const std::uint8_t) -> bool override { return true; }
 
   private:
     ::util::communication_base& my_serial;
diff --git a/ref_app/src/util/STL/algorithm b/ref_app/src/util/STL/algorithm
index ad040f993..1542a21e3 100644
--- a/ref_app/src/util/STL/algorithm
+++ b/ref_app/src/util/STL/algorithm
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-//  Copyright Christopher Kormanyos 2007 - 2018.
+//  Copyright Christopher Kormanyos 2007 - 2024.
 //  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)
@@ -233,7 +233,9 @@
     {
       for( ; first != last; ++result, ++first)
       {
-        *result = *first;
+        using result_value_type = typename std::iterator_traits<output_iterator>::value_type;
+
+        *result = result_value_type(*first);
       }
 
       return result;
@@ -247,10 +249,12 @@
     {
       while (first1 != last1)
       {
+        using out2_value_type = typename std::iterator_traits<bidirectional_output_iterator2>::value_type;
+
         --last1;
         --last2;
 
-        *last2 = *last1;
+        *last2 = out2_value_type(*last1);
       }
 
       return last2;
@@ -264,12 +268,12 @@
                             output_iterator     result,
                             unary_function_type unary_function)
     {
-      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
-
       while(first != last)
       {
         if(unary_function(*first))
         {
+          using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
+
           *result = output_value_type(*first);
 
           ++result;
@@ -287,10 +291,10 @@
                                              forward_iterator  last,
                                              const value_type& value)
     {
-      using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;
-
       for( ; first != last; ++first)
       {
+      using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;
+
         *first = forward_value_type(value);
       }
     }
@@ -315,10 +319,10 @@
                   forward_iterator last,
                   generator_type   generator)
     {
-      using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;
-
       while(first != last)
       {
+      using forward_value_type = typename std::iterator_traits<forward_iterator>::value_type;
+
         *first = forward_value_type(generator());
 
         ++first;
@@ -332,10 +336,10 @@
                                size_type       count,
                                generator_type  generator)
     {
-      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
-
       for(size_type i = size_type(0); i < count; ++i)
       {
+      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
+
         *first = output_value_type(generator());
 
         ++first;
@@ -361,10 +365,10 @@
                               output_iterator     result,
                               unary_function_type unary_function)
     {
-      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
-
       for( ; first != last; ++first, ++result)
       {
+      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
+
         *result = output_value_type(unary_function(*first));
       }
 
@@ -381,10 +385,10 @@
                               output_iterator      result,
                               binary_function_type binary_function)
     {
-      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
-
       for( ; first1 != last1; ++first1, ++first2, ++result)
       {
+      using output_value_type = typename std::iterator_traits<output_iterator>::value_type;
+
         *result = output_value_type(binary_function(*first1, *first2));
       }
 
diff --git a/ref_app/src/util/STL/span b/ref_app/src/util/STL/span
index ae2213c0e..62fcd2bfd 100644
--- a/ref_app/src/util/STL/span
+++ b/ref_app/src/util/STL/span
@@ -1,11 +1,12 @@
-// This is significant simplification of an existing work:
+// This is a significant simplification of an existing work:
+// Comments from the original work follow.
 
 // This is an implementation of std::span from P0122R7
 // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0122r7.pdf
 
 ///////////////////////////////////////////////////////////////////////////////
 // Copyright Tristan Brindle 2018.
-// Copyright Christopher Kormanyos 2019.
+// Copyright Christopher Kormanyos 2019 - 2024.
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file ../../LICENSE_1_0.txt or copy at
 // https://www.boost.org/LICENSE_1_0.txt)
diff --git a/ref_app/src/util/utility/util_display.h b/ref_app/src/util/utility/util_display.h
index 9355bad00..f5b2df40c 100644
--- a/ref_app/src/util/utility/util_display.h
+++ b/ref_app/src/util/utility/util_display.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-//  Copyright Christopher Kormanyos 2019 - 2023.
+//  Copyright Christopher Kormanyos 2019 - 2024.
 //  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)
@@ -8,11 +8,11 @@
 #ifndef UTIL_DISPLAY_2023_06_09_H
   #define UTIL_DISPLAY_2023_06_09_H
 
-  #include <cstdint>
-
   #include <util/utility/util_noncopyable.h>
   #include <util/utility/util_time.h>
 
+  #include <cstdint>
+
   namespace util {
 
   class display_multiline_base : private util::noncopyable
@@ -20,16 +20,18 @@
   public:
     virtual ~display_multiline_base() = default;
 
-    virtual auto init() noexcept -> bool = 0;
+    virtual auto init() -> bool = 0;
 
     virtual auto write(const char* pstr,
                        const std::uint_fast8_t length,
                        const std::uint_fast8_t line_index) -> bool = 0;
 
-  protected:
-    display_multiline_base() noexcept = default;
+    virtual auto clear_line(const unsigned = static_cast<unsigned>(UINT8_C(0))) -> bool = 0;
+
+    virtual auto set_line_index(const std::uint8_t) -> bool = 0;
 
-    virtual auto set_line_index(const std::uint8_t) noexcept -> bool { return true; }
+  protected:
+    display_multiline_base() = default;
 
     using timer_type = util::timer<std::uint32_t>;