Skip to content

Commit

Permalink
Merge pull request #519 from ckormanyos/update_vf_display
Browse files Browse the repository at this point in the history
Update vacuum fluorescent display class
  • Loading branch information
ckormanyos authored Jul 13, 2024
2 parents cc0733a + 3c4a131 commit b92ea72
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 72 deletions.
24 changes: 4 additions & 20 deletions ref_app/src/mcal_vfd/mcal_vfd_base.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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;
Expand Down
56 changes: 28 additions & 28 deletions ref_app/src/mcal_vfd/mcal_vfd_nec_fm20x2kb.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -25,15 +25,15 @@
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)
: my_serial(ser) { }

~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))); };

Expand All @@ -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) }));
}

{
Expand All @@ -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),
Expand All @@ -105,25 +105,25 @@
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());

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;
Expand Down
34 changes: 19 additions & 15 deletions ref_app/src/util/STL/algorithm
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
5 changes: 3 additions & 2 deletions ref_app/src/util/STL/span
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 9 additions & 7 deletions ref_app/src/util/utility/util_display.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -8,28 +8,30 @@
#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
{
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>;

Expand Down

0 comments on commit b92ea72

Please sign in to comment.