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
cc47fdcb
Commit
cc47fdcb
authored
9 years ago
by
Fabrice Weinberg
Browse files
Options
Downloads
Patches
Plain Diff
Merge with update stream
parent
5554319b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ssd1306_i2c.cpp
+36
-2
36 additions, 2 deletions
ssd1306_i2c.cpp
ssd1306_i2c.h
+10
-1
10 additions, 1 deletion
ssd1306_i2c.h
with
46 additions
and
3 deletions
ssd1306_i2c.cpp
+
36
−
2
View file @
cc47fdcb
...
...
@@ -119,7 +119,40 @@ void SSD1306::setChar(int x, int y, unsigned char data) {
}
}
// Code form http://playground.arduino.cc/Main/Utf8ascii
byte
SSD1306
::
utf8ascii
(
byte
ascii
)
{
if
(
ascii
<
128
)
{
// Standard ASCII-set 0..0x7F handling
lastChar
=
0
;
return
(
ascii
);
}
// get previous input
byte
last
=
lastChar
;
// get last char
lastChar
=
ascii
;
// remember actual character
switch
(
last
)
// conversion depnding on first UTF8-character
{
case
0xC2
:
return
(
ascii
);
break
;
case
0xC3
:
return
(
ascii
|
0xC0
);
break
;
case
0x82
:
if
(
ascii
==
0xAC
)
return
(
0x80
);
// special case Euro-symbol
}
return
(
0
);
// otherwise: return zero, if character has to be ignored
}
// Code form http://playground.arduino.cc/Main/Utf8ascii
String
SSD1306
::
utf8ascii
(
String
s
)
{
String
r
=
""
;
char
c
;
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++
)
{
c
=
utf8ascii
(
s
.
charAt
(
i
));
if
(
c
!=
0
)
r
+=
c
;
}
return
r
;
}
void
SSD1306
::
drawString
(
int
x
,
int
y
,
String
text
)
{
text
=
utf8ascii
(
text
);
unsigned
char
currentByte
;
int
charX
,
charY
;
int
currentBitCount
;
...
...
@@ -212,6 +245,7 @@ void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) {
}
int
SSD1306
::
getStringWidth
(
String
text
)
{
text
=
utf8ascii
(
text
);
int
stringWidth
=
0
;
char
charCode
;
for
(
int
j
=
0
;
j
<
text
.
length
();
j
++
)
{
...
...
@@ -259,7 +293,7 @@ void SSD1306::drawRect(int x, int y, int width, int height) {
void
SSD1306
::
fillRect
(
int
x
,
int
y
,
int
width
,
int
height
)
{
for
(
int
i
=
x
;
i
<
x
+
width
;
i
++
)
{
for
(
int
j
=
0
;
j
<
y
+
height
;
j
++
)
{
for
(
int
j
=
y
;
j
<
y
+
height
;
j
++
)
{
setPixel
(
i
,
j
);
}
}
...
...
@@ -316,4 +350,4 @@ void SSD1306::sendInitCommands(void) {
sendCommand
(
NORMALDISPLAY
);
sendCommand
(
0x2e
);
// stop scroll
sendCommand
(
DISPLAYON
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ssd1306_i2c.h
+
10
−
1
View file @
cc47fdcb
...
...
@@ -79,6 +79,7 @@ private:
uint8_t
buffer
[
128
*
64
/
8
];
int
myTextAlignment
=
TEXT_ALIGN_LEFT
;
int
myColor
=
WHITE
;
byte
lastChar
;
const
char
*
myFontData
=
ArialMT_Plain_10
;
public:
...
...
@@ -139,6 +140,14 @@ public:
// Sets the color of all pixel operations
void
setColor
(
int
color
);
// converts utf8 characters to extended ascii
// taken from http://playground.arduino.cc/Main/Utf8ascii
byte
utf8ascii
(
byte
ascii
);
// converts utf8 string to extended ascii
// taken from http://playground.arduino.cc/Main/Utf8ascii
String
utf8ascii
(
String
s
);
// Draws a string at the given location
void
drawString
(
int
x
,
int
y
,
String
text
);
...
...
@@ -161,4 +170,4 @@ public:
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
void
setFont
(
const
char
*
fontData
);
};
};
\ No newline at end of file
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