Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
esp8266-oled-ssd1306
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3pb
esp8266-oled-ssd1306
Commits
f5265e4c
Commit
f5265e4c
authored
9 years ago
by
Fabrice Weinberg
Browse files
Options
Downloads
Patches
Plain Diff
Support line breaks in string fix #15
parent
ee946033
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SSD1306.cpp
+20
-13
20 additions, 13 deletions
SSD1306.cpp
SSD1306.h
+1
-0
1 addition, 0 deletions
SSD1306.h
with
21 additions
and
13 deletions
SSD1306.cpp
+
20
−
13
View file @
f5265e4c
...
@@ -234,17 +234,13 @@ void SSD1306::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t heigh
...
@@ -234,17 +234,13 @@ void SSD1306::drawXbm(int16_t xMove, int16_t yMove, int16_t width, int16_t heigh
}
}
}
}
void
SSD1306
::
drawString
(
int16_t
xMove
,
int16_t
yMove
,
String
t
)
{
void
SSD1306
::
drawStringInternal
(
int16_t
xMove
,
int16_t
yMove
,
char
*
text
,
uint16_t
textLength
,
uint16_t
textWidth
)
{
// char* text must be freed!
char
*
text
=
utf8ascii
(
t
);
uint8_t
textHeight
=
pgm_read_byte
(
fontData
+
HEIGHT_POS
);
uint8_t
textHeight
=
pgm_read_byte
(
fontData
+
HEIGHT_POS
);
uint8_t
firstChar
=
pgm_read_byte
(
fontData
+
FIRST_CHAR_POS
);
uint8_t
firstChar
=
pgm_read_byte
(
fontData
+
FIRST_CHAR_POS
);
uint16_t
sizeOfJumpTable
=
pgm_read_byte
(
fontData
+
CHAR_NUM_POS
)
*
JUMPTABLE_BYTES
;
uint16_t
sizeOfJumpTable
=
pgm_read_byte
(
fontData
+
CHAR_NUM_POS
)
*
JUMPTABLE_BYTES
;
uint8_t
textWidth
=
getStringWidth
(
text
);
uint8_t
cursorX
=
0
;
uint8_t
cursorX
=
0
;
uint8_t
cursorY
=
0
;
switch
(
textAlignment
)
{
switch
(
textAlignment
)
{
case
TEXT_ALIGN_CENTER_BOTH
:
case
TEXT_ALIGN_CENTER_BOTH
:
...
@@ -259,12 +255,13 @@ void SSD1306::drawString(int16_t xMove, int16_t yMove, String t) {
...
@@ -259,12 +255,13 @@ void SSD1306::drawString(int16_t xMove, int16_t yMove, String t) {
}
}
// Don't draw anything if it is not on the screen.
// Don't draw anything if it is not on the screen.
if
(
xMove
+
textWidth
<
0
||
xMove
>
DISPLAY_WIDTH
)
{
free
(
text
);
return
;}
if
(
xMove
+
textWidth
<
0
||
xMove
>
DISPLAY_WIDTH
)
{
return
;}
if
(
yMove
+
textHeight
<
0
||
yMove
>
DISPLAY_HEIGHT
)
{
free
(
text
);
return
;}
if
(
yMove
+
textHeight
<
0
||
yMove
>
DISPLAY_HEIGHT
)
{
return
;}
uint16_t
length
=
strlen
(
text
);
for
(
uint16_t
j
=
0
;
j
<
textLength
;
j
++
)
{
int16_t
xPos
=
xMove
+
cursorX
;
int16_t
yPos
=
yMove
+
cursorY
;
for
(
uint16_t
j
=
0
;
j
<
length
;
j
++
)
{
byte
code
=
text
[
j
];
byte
code
=
text
[
j
];
if
(
code
>=
firstChar
)
{
if
(
code
>=
firstChar
)
{
byte
charCode
=
code
-
firstChar
;
byte
charCode
=
code
-
firstChar
;
...
@@ -279,13 +276,24 @@ void SSD1306::drawString(int16_t xMove, int16_t yMove, String t) {
...
@@ -279,13 +276,24 @@ void SSD1306::drawString(int16_t xMove, int16_t yMove, String t) {
if
(
msbJumpToChar
!=
255
&&
lsbJumpToChar
!=
255
)
{
if
(
msbJumpToChar
!=
255
&&
lsbJumpToChar
!=
255
)
{
// Get the position of the char data
// Get the position of the char data
uint16_t
charDataPosition
=
JUMPTABLE_START
+
sizeOfJumpTable
+
((
msbJumpToChar
<<
8
)
+
lsbJumpToChar
);
uint16_t
charDataPosition
=
JUMPTABLE_START
+
sizeOfJumpTable
+
((
msbJumpToChar
<<
8
)
+
lsbJumpToChar
);
drawInternal
(
x
Move
+
cursorX
,
yMove
,
currentCharWidth
,
textHeight
,
fontData
,
charDataPosition
,
charByteSize
);
drawInternal
(
x
Pos
,
yPos
,
currentCharWidth
,
textHeight
,
fontData
,
charDataPosition
,
charByteSize
);
}
}
cursorX
+=
currentCharWidth
;
cursorX
+=
currentCharWidth
;
}
else
if
(
code
==
10
)
{
// Support line breaks (\n) in String
cursorY
+=
pgm_read_byte
(
fontData
+
HEIGHT_POS
);
cursorX
=
0
;
}
}
}
}
}
void
SSD1306
::
drawString
(
int16_t
xMove
,
int16_t
yMove
,
String
strUser
)
{
// char* text must be freed!
char
*
text
=
utf8ascii
(
strUser
);
uint16_t
length
=
strlen
(
text
);
drawStringInternal
(
xMove
,
yMove
,
text
,
length
,
getStringWidth
(
text
,
length
));
free
(
text
);
free
(
text
);
}
}
...
@@ -314,10 +322,9 @@ void SSD1306::drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, Str
...
@@ -314,10 +322,9 @@ void SSD1306::drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, Str
drawString
(
x
,
y
+
lineNumber
*
lineHeight
,
text
.
substring
(
startsAt
));
drawString
(
x
,
y
+
lineNumber
*
lineHeight
,
text
.
substring
(
startsAt
));
}
}
uint16_t
SSD1306
::
getStringWidth
(
const
char
*
text
)
{
uint16_t
SSD1306
::
getStringWidth
(
const
char
*
text
,
uint16_t
length
)
{
uint16_t
stringWidth
=
0
;
uint16_t
stringWidth
=
0
;
uint16_t
firstChar
=
pgm_read_byte
(
fontData
+
FIRST_CHAR_POS
);
uint16_t
firstChar
=
pgm_read_byte
(
fontData
+
FIRST_CHAR_POS
);
uint16_t
length
=
strlen
(
text
);
while
(
length
--
)
{
while
(
length
--
)
{
stringWidth
+=
pgm_read_byte
(
fontData
+
JUMPTABLE_START
+
(
text
[
length
]
-
firstChar
)
*
JUMPTABLE_BYTES
+
JUMPTABLE_WIDTH
);
stringWidth
+=
pgm_read_byte
(
fontData
+
JUMPTABLE_START
+
(
text
[
length
]
-
firstChar
)
*
JUMPTABLE_BYTES
+
JUMPTABLE_WIDTH
);
}
}
...
...
This diff is collapsed.
Click to expand it.
SSD1306.h
+
1
−
0
View file @
f5265e4c
...
@@ -134,6 +134,7 @@ class SSD1306 {
...
@@ -134,6 +134,7 @@ class SSD1306 {
void
drawInternal
(
int16_t
xMove
,
int16_t
yMove
,
int16_t
width
,
int16_t
height
,
const
char
*
data
,
uint16_t
offset
,
uint16_t
bytesInData
);
void
drawInternal
(
int16_t
xMove
,
int16_t
yMove
,
int16_t
width
,
int16_t
height
,
const
char
*
data
,
uint16_t
offset
,
uint16_t
bytesInData
);
void
drawStringInternal
(
int16_t
xMove
,
int16_t
yMove
,
char
*
text
,
uint16_t
textLength
,
uint16_t
textWidth
);
public:
public:
// Create the display object connected to pin sda and sdc
// Create the display object connected to pin sda and sdc
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment