75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
//
|
|
// Created by rhetenor on 10.10.18.
|
|
//
|
|
|
|
#include "utility/config.h"
|
|
|
|
#include <string>
|
|
#include <algorithm>
|
|
|
|
namespace flippR_driver
|
|
{
|
|
namespace output
|
|
{
|
|
namespace items
|
|
{
|
|
namespace detail
|
|
{
|
|
|
|
template<int DigitCount>
|
|
Display<DigitCount>::Display(uint8_t address, uint8_t id) :
|
|
address(address),
|
|
id(id)
|
|
{
|
|
CLOG(INFO, OUTPUT_LOGGER) << "Created display with id " << id << " and address " << address << ".";
|
|
}
|
|
|
|
template<int DigitCount>
|
|
uint8_t Display<DigitCount>::get_id() const
|
|
{
|
|
return this->id;
|
|
}
|
|
|
|
template<int DigitCount>
|
|
void Display<DigitCount>::write_score(uint score)
|
|
{
|
|
auto score_string = std::to_string(score);
|
|
|
|
std::copy(score_string.begin(), score_string.end(), std::begin(this->content));
|
|
}
|
|
|
|
template<int DigitCount>
|
|
std::string Display<DigitCount>::fit_string(std::string& score_string)
|
|
{
|
|
auto score_length = score_string.length();
|
|
|
|
if (score_length > DigitCount)
|
|
{
|
|
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
|
std::string full_display;
|
|
// TODO mach mal schöner hier wird 9999 angezeigt wenn die zahl zu groß is
|
|
return full_display.insert(0, DigitCount, '9');
|
|
}
|
|
|
|
score_string.insert(0, DigitCount-score_length, '\0');
|
|
return score_string;
|
|
}
|
|
|
|
template<int DigitCount>
|
|
void Display<DigitCount>::write_content( std::array<char, DigitCount> content)
|
|
{
|
|
this->content = content;
|
|
}
|
|
|
|
template <int DigitCount>
|
|
std::vector<uint8_t> Display<DigitCount>::get_content() const
|
|
{
|
|
// todo: expensive?
|
|
return std::vector<uint8_t>(content.begin(), content.end());
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|