EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
Display Class Reference

Class Display. API for working with text on display. More...

#include <ev3cxx_display.h>

Public Member Functions

 Display (lcdfont_t font=EV3_FONT_MEDIUM)
 Constructor of class Display. More...
 
 ~Display ()
 Destructor of class Display.
 
detail::format_impl< Display, detail::string_literal_rangeformat (char const *pattern)
 Write formated text to LCD. More...
 
detail::format_impl< Display, detail::string_literal_rangeformat (int8_t line, char const *pattern)
 Write formated text to LCD. More...
 
virtual void write (char ch)
 Write one character on screen of class Display. More...
 
void write_raw (char ch, bool clear=false)
 Write one character on screen of class Display.
 
int32_t getTextLine () const
 Get actual text line index. More...
 
void setTextLine (uint8_t line, int32_t x_offset=0, bool clear=true)
 Set actual text line index of cursor for next write. More...
 
void clearTextLine (uint8_t line, bool_t color=white, int32_t x_offset=0, int32_t line_length=0)
 Clear a line. More...
 
void resetScreen (bool_t color=white)
 Clear whole LCD. More...
 
void setFont (lcdfont_t font)
 Set font type. More...
 
lcdfont_t getFont () const
 Get actual font type.
 
int32_t getFontWidth () const
 Get actual font width.
 
int32_t getFontHeight () const
 Get actual font height.
 
int32_t getX () const
 Get actual X coordinates.
 
int32_t getY () const
 Get actual Y coordinates.
 

Static Public Attributes

static const uint8_t width = EV3_LCD_WIDTH
 Width of LCD in pixels.
 
static const uint8_t height = EV3_LCD_HEIGHT
 Height of LCD in pixels.
 
static const bool_t white = EV3_LCD_WHITE
 White color of write to LCD.
 
static const bool_t black = EV3_LCD_BLACK
 Black color of write to LCD.
 

Private Attributes

lcdfont_t m_font
 actual font
 
int32_t m_font_width
 width of actual font
 
int32_t m_font_height
 height of actual font
 
int32_t m_max_char_on_line
 max number of character on one line
 
int32_t m_max_line_on_height
 max number of line on screen
 
int32_t m_x
 actual horizontal coordinate from upper left corner
 
int32_t m_y
 actual vertical coordinate from upper left corner
 

Detailed Description

Class Display. API for working with text on display.

Definition at line 20 of file ev3cxx_display.h.

Constructor & Destructor Documentation

◆ Display()

Display ( lcdfont_t  font = EV3_FONT_MEDIUM)
inline

Constructor of class Display.

Parameters
fontType of font lcdfont_t (EV3_FONT_SMALL / EV3_FONT_MEDIUM). Default is EV3_FONT_MEDIUM.

Definition at line 34 of file ev3cxx_display.h.

References Display::setFont().

35  :m_x(0), m_y(0)
36  {
37  setFont(font);
38  }
int32_t m_x
actual horizontal coordinate from upper left corner
void setFont(lcdfont_t font)
Set font type.
int32_t m_y
actual vertical coordinate from upper left corner

Member Function Documentation

◆ clearTextLine()

void clearTextLine ( uint8_t  line,
bool_t  color = white,
int32_t  x_offset = 0,
int32_t  line_length = 0 
)
inline

Clear a line.

Parameters
lineLine index. Range depend on actual font type (EV3_FONT_MEDIUM => 0 - 7). If out of range, then result is "line % m_max_line_on_height".
colorColor the cleared with. You can set white or black.
x_offsetOffset for clearing the line in x coordinate. When you want clear just part of display, then you set this offset. If you want to set offset depend on character, use function getFontWidth() and multiple by require number of char.

Definition at line 140 of file ev3cxx_display.h.

References Display::getFontHeight(), and Display::getFontWidth().

Referenced by Display::setTextLine(), and Display::write_raw().

140  {
141  if (line_length == 0)
142  line_length = width - x_offset;
143  else
144  line_length *= getFontWidth();
145  ev3_lcd_fill_rect(x_offset,
146  (line * getFontHeight()) % height,
147  line_length,
148  getFontHeight(),
149  static_cast<lcdcolor_t>(color));
150  }
int32_t getFontWidth() const
Get actual font width.
static const uint8_t height
Height of LCD in pixels.
int32_t getFontHeight() const
Get actual font height.
static const uint8_t width
Width of LCD in pixels.

◆ format() [1/2]

detail::format_impl<Display, detail::string_literal_range> format ( char const *  pattern)
inline

Write formated text to LCD.

Parameters
patternString with pattern for final output text.

Definition at line 51 of file ev3cxx_display.h.

51  {
52  return detail::format_impl<Display, detail::string_literal_range>(
53  *this, detail::string_literal_range(pattern));
54  }

◆ format() [2/2]

detail::format_impl<Display, detail::string_literal_range> format ( int8_t  line,
char const *  pattern 
)
inline

Write formated text to LCD.

Parameters
lineLine index to write text on LCD.
patternString with pattern for final output text.

Definition at line 62 of file ev3cxx_display.h.

References Display::setTextLine().

63  {
64  setTextLine(line);
65  return detail::format_impl<Display, detail::string_literal_range>(
66  *this, detail::string_literal_range(pattern));
67  }
void setTextLine(uint8_t line, int32_t x_offset=0, bool clear=true)
Set actual text line index of cursor for next write.

◆ getTextLine()

int32_t getTextLine ( ) const
inline

Get actual text line index.

Range depend on actual font type (EV3_FONT_MEDIUM => 0 - 7).

Definition at line 112 of file ev3cxx_display.h.

References Display::getFontHeight(), and Display::m_y.

Referenced by Display::write(), and Display::write_raw().

112 { return m_y / getFontHeight(); }
int32_t m_y
actual vertical coordinate from upper left corner
int32_t getFontHeight() const
Get actual font height.

◆ resetScreen()

void resetScreen ( bool_t  color = white)
inline

Clear whole LCD.

Parameters
colorColor of screen after reset. You can set white or black.

Definition at line 157 of file ev3cxx_display.h.

References Display::setTextLine().

157  {
158  ev3_lcd_fill_rect(0, 0, width, height, static_cast<lcdcolor_t>(color));
159  setTextLine(0);
160  }
void setTextLine(uint8_t line, int32_t x_offset=0, bool clear=true)
Set actual text line index of cursor for next write.
static const uint8_t height
Height of LCD in pixels.
static const uint8_t width
Width of LCD in pixels.

◆ setFont()

void setFont ( lcdfont_t  font)
inline

Set font type.

After changing font set variables m_font_width => getFontWidth() and m_font_height -> getFontHeight().

Parameters
fontType of font lcdfont_t (EV3_FONT_SMALL / EV3_FONT_MEDIUM).

Definition at line 168 of file ev3cxx_display.h.

References Display::m_font, Display::m_font_height, Display::m_font_width, Display::m_max_char_on_line, and Display::m_max_line_on_height.

Referenced by Display::Display().

168  {
169  m_font = font;
170  ev3_lcd_set_font(font);
171  ev3_font_get_size(font, &m_font_width, &m_font_height);
174  }
lcdfont_t m_font
actual font
int32_t m_max_line_on_height
max number of line on screen
int32_t m_font_width
width of actual font
int32_t m_font_height
height of actual font
int32_t m_max_char_on_line
max number of character on one line
static const uint8_t height
Height of LCD in pixels.
static const uint8_t width
Width of LCD in pixels.

◆ setTextLine()

void setTextLine ( uint8_t  line,
int32_t  x_offset = 0,
bool  clear = true 
)
inline

Set actual text line index of cursor for next write.

Also clear all line (clearTextLine()).

Parameters
lineLine index. Range depend on actual font type (EV3_FONT_MEDIUM => 0 - 7). If out of range, then result is "line % m_max_line_on_height".
x_offsetOffset for clearing the line in x coordinate. When you want clear just part of display, then you set this offset. If you want to set offset depend on character, use function getFontWidth() and multiple by require number of char.

Definition at line 123 of file ev3cxx_display.h.

References Display::clearTextLine(), Display::getFontHeight(), Display::m_x, and Display::m_y.

Referenced by Display::format(), Display::resetScreen(), and Display::write().

123  {
124  if(clear && (line * getFontHeight()) < height) {
125  clearTextLine(line, white, x_offset);
126  }
127  m_y = (line * getFontHeight()) % height;
128  m_x = x_offset;
129  }
static const bool_t white
White color of write to LCD.
void clearTextLine(uint8_t line, bool_t color=white, int32_t x_offset=0, int32_t line_length=0)
Clear a line.
int32_t m_x
actual horizontal coordinate from upper left corner
int32_t m_y
actual vertical coordinate from upper left corner
static const uint8_t height
Height of LCD in pixels.
int32_t getFontHeight() const
Get actual font height.

◆ write()

virtual void write ( char  ch)
inlinevirtual

Write one character on screen of class Display.

Char "\n" set next text line.

Definition at line 74 of file ev3cxx_display.h.

References Display::getTextLine(), Display::setTextLine(), and Display::write_raw().

74  {
75  if(ch == '\n') {
76  setTextLine(getTextLine() + 1);
77  } else if(ch == '\t') {
78  write_raw(' ');
79  write_raw(' ');
80  write(' ');
81  } else if(ch == '\r') {
82  setTextLine(getTextLine(), 0);
83  }
84  else {
85  write_raw(ch);
86  }
87  }
void write_raw(char ch, bool clear=false)
Write one character on screen of class Display.
void setTextLine(uint8_t line, int32_t x_offset=0, bool clear=true)
Set actual text line index of cursor for next write.
int32_t getTextLine() const
Get actual text line index.
virtual void write(char ch)
Write one character on screen of class Display.