diff --git a/CMakeLists.txt b/CMakeLists.txt index 310545b..f8cdb41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required( VERSION 2.6 ) # Set the version of the library set( RPI_HW_VERSION_MAJOR 0 ) set( RPI_HW_VERSION_MINOR 7 ) -set( RPI_HW_VERSION_PATCH 1 ) +set( RPI_HW_VERSION_PATCH 2 ) set( RPI_HW_VERSION "${RPI_HW_VERSION_MAJOR}.${RPI_HW_VERSION_MINOR}.${RPI_HW_VERSION_PATCH}" ) # Project directories diff --git a/ChangeLog b/ChangeLog index 793204f..3db3b4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ ChangeLog of Rpi-hw - A free C++ library designed to manage the Raspberry Pi's GPIO connector and its other buses. +============ Rpi-hw 0.7.2 - urgency=low =========== + +2013-12-26 Wicker25 < wicker25@gmail.com > + + * hd44780.hpp: Added support for `std::wstring`. + ============ Rpi-hw 0.7.1 - urgency=low =========== 2013-12-24 Wicker25 < wicker25@gmail.com > diff --git a/README.md b/README.md index 794d74f..2b20c5a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Rpi-hw v0.7.1 +Rpi-hw v0.7.2 ============= [Rpi-hw](http://hackyourmind.org/projects/rpi-hw) (short for "Raspberry Pi Hardware") is a free C++ library diff --git a/VERSION b/VERSION index 39e898a..7486fdb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.1 +0.7.2 diff --git a/include/rpi-hw/display/hd44780-inl.hpp b/include/rpi-hw/display/hd44780-inl.hpp index 55eeb43..5188108 100644 --- a/include/rpi-hw/display/hd44780-inl.hpp +++ b/include/rpi-hw/display/hd44780-inl.hpp @@ -121,6 +121,33 @@ hd44780::write( uint8_t x, uint8_t y, const std::u32string &text, uint8_t flags write( text, flags ); } +inline void +hd44780::write( const std::wstring &text, uint8_t flags ) { + + // Align the text and write it on the display + write( utils::align( text, m_width, flags ) ); +} + +inline void +hd44780::write( uint8_t x, uint8_t y, const std::wstring &text ) { + + // Set the position of the cursor on the display + move( x, y ); + + // Write the unicode string on the display + write( text ); +} + +inline void +hd44780::write( uint8_t x, uint8_t y, const std::wstring &text, uint8_t flags ) { + + // Set the position of the cursor on the display + move( x, y ); + + // Write the unicode string on the display + write( text, flags ); +} + inline void hd44780::setTypingDelay( size_t delay ) { diff --git a/include/rpi-hw/display/hd44780.hpp b/include/rpi-hw/display/hd44780.hpp index 29ecad0..b50ff8a 100644 --- a/include/rpi-hw/display/hd44780.hpp +++ b/include/rpi-hw/display/hd44780.hpp @@ -18,7 +18,6 @@ along with Rpi-hw. If not, see . */ - #ifndef _RPI_HW_DISPLAY_HD44780_HPP_ #define _RPI_HW_DISPLAY_HD44780_HPP_ @@ -272,6 +271,36 @@ class hd44780 { */ void write( uint8_t x, uint8_t y, const std::u32string &text, uint8_t flags ); + /*! + @brief Writes a unicode string on the display. + @param[in] text The unicode string to be written. + */ + void write( const std::wstring &text ); + + /*! + @brief Writes a unicode string on the display. + @param[in] text The string to be written. + @param[in] flags The parameters of the text. + */ + void write( const std::wstring &text, uint8_t flags ); + + /*! + @brief Moves the cursor position and writes a unicode string on the display. + @param[in] x The new horizontal position of the cursor. + @param[in] y The new vertical position of the cursor. + @param[in] text The unicode string to be written. + */ + void write( uint8_t x, uint8_t y, const std::wstring &text ); + + /*! + @brief Moves the cursor position and writes a unicode string on the display. + @param[in] x The new horizontal position of the cursor. + @param[in] y The new vertical position of the cursor. + @param[in] text The unicode string to be written. + @param[in] flags The parameters of the text. + */ + void write( uint8_t x, uint8_t y, const std::wstring &text, uint8_t flags ); + /*! @brief Scrolls the contents of the display to the left. @param[in] cursor If \c true, will also moves the cursor. @@ -403,19 +432,26 @@ class hd44780 { */ void putChar( uint8_t c ); + /*! + @brief Maps a unicode character to the corresponding code. + @param[in] code The unicode character. + @return The character code. + */ + uint8_t encodeChar( char32_t code ); + /*! @brief Maps a unicode character to the corresponding code (ROM A00, Japanese version). @param[in] code The unicode character. @return The character code. */ - uint8_t encode_char_a00( char32_t code ); + uint8_t encodeCharA00( char32_t code ); /*! @brief Maps a unicode character to the corresponding code (ROM A02, European version). @param[in] code The unicode character. @return The character code. */ - uint8_t encode_char_a02( char32_t code ); + uint8_t encodeCharA02( char32_t code ); }; } // End of displays namespace diff --git a/src/display/hd44780.cpp b/src/display/hd44780.cpp index fcff1a4..2421aa3 100644 --- a/src/display/hd44780.cpp +++ b/src/display/hd44780.cpp @@ -268,13 +268,18 @@ hd44780::write( const std::u32string &text ) { for ( auto &c : text ) { // Encode the character and put it on the display - switch ( m_rom_code ) { + write( encodeChar( c ) ); + } +} - case ROM_A00: { write( encode_char_a00( c ) ); break; } - case ROM_A02: { write( encode_char_a02( c ) ); break; } +void +hd44780::write( const std::wstring &text ) { - default: { write( encode_char_a00( c ) ); break; } - } + // Write the string on the display + for ( auto &c : text ) { + + // Encode the character and put it on the display + write( encodeChar( (char32_t) c ) ); } } @@ -496,7 +501,20 @@ hd44780::clear() { } uint8_t -hd44780::encode_char_a00( char32_t code ) { +hd44780::encodeChar( char32_t code ) { + + // Map a unicode character to the corresponding code + switch ( m_rom_code ) { + + case ROM_A00: return encodeCharA00( code ); + case ROM_A02: return encodeCharA02( code ); + + default: return encodeCharA00( code ); + } +} + +uint8_t +hd44780::encodeCharA00( char32_t code ) { // Standard ASCII characters if ( code <= 0x7d && code != 0x5c ) @@ -609,7 +627,7 @@ hd44780::encode_char_a00( char32_t code ) { } uint8_t -hd44780::encode_char_a02( char32_t code ) { +hd44780::encodeCharA02( char32_t code ) { // Standard ASCII characters if (