Skip to content

Commit c5e66a1

Browse files
committed
Merge pull request ThingPulse#44 from squix78/add-upgrade-guide
Upgrade Guide from 2.0 to 3.0
2 parents e3605d7 + 63dc8a0 commit c5e66a1

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

UPGRADE-3.0.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Upgrade from 2.0 to 3.0
2+
3+
While developing version 3.0 we made some breaking changes to the public
4+
API of this library. This document will help you update your code to work with
5+
version 3.0
6+
7+
## Font Definitions
8+
9+
To get better performance and a smaller font definition format, we change the memory
10+
layout of the font definition format. If you are using custom fonts not included in
11+
this library we updated the font generator [here](http://oleddisplay.squix.ch/#/home).
12+
Please update your fonts to be working with 3.0.
13+
14+
15+
## Architectural Changes
16+
17+
To become a more versatile library for the SSD1306 chipset we abstracted the
18+
hardware connection into subclasses of the base display class now called `OLEDDisplay`.
19+
This library is currently shipping with three implementations:
20+
21+
* `SSD1306Wire` implementing the I2C protocol using the Wire Library.
22+
* `SSD1306Brzo` implementing the I2C protocol using the faster [`brzo_i2c`](https://github.com/pasko-zh/brzo_i2c) library.
23+
* `SSD1306Spi` implementing the SPI protocol.
24+
25+
To keep backwards compatiblity with the old API `SSD1306` is an alias of `SSD1306Wire`.
26+
If you are not using the UI components you don't have to change anything to keep your code working.
27+
28+
## Name Changes
29+
30+
[Naming things is hard](http://martinfowler.com/bliki/TwoHardThings.html), to better reflect our intention with this library
31+
we changed the name of the base class to `OLEDDisplay` and the UI library accordingly to `OLEDDisplayUi`.
32+
As a consequence the type definitions of all frame and overlay related functions changed.
33+
This means that you have to update all your frame drawing callbacks from:
34+
35+
```c
36+
bool frame1(SSD1306 *display, SSD1306UiState* state, int x, int y);
37+
```
38+
39+
too
40+
41+
```c
42+
void frame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y);
43+
```
44+
45+
And your overlay drawing functions from:
46+
47+
```c
48+
bool overlay1(SSD1306 *display, SSD1306UiState* state);
49+
```
50+
51+
too
52+
53+
```c
54+
void overlay1(OLEDDisplay *display, OLEDDisplayUiState* state);
55+
```
56+
57+
## New Features
58+
59+
### Loading Animation
60+
61+
While using this library ourself we noticed a pattern emerging. We want to drawing
62+
a loading progress while connecting to WiFi and updating weather data etc.
63+
64+
The simplest thing was to add the function `drawProgressBar(x, y, width, height, progress)`
65+
,where `progress` is between `0` and `100`, right to the `OLEDDisplay` class.
66+
67+
But we didn't stop there. We added a new feature to the `OLEDDisplayUi` called `LoadingStages`.
68+
You can define your loading process like this:
69+
70+
```c++
71+
LoadingStage loadingStages[] = {
72+
{
73+
.process = "Connect to WiFi",
74+
.callback = []() {
75+
// Connect to WiFi
76+
}
77+
},
78+
{
79+
.process = "Get time from NTP",
80+
.callback = []() {
81+
// Get current time via NTP
82+
}
83+
}
84+
// more steps
85+
};
86+
87+
int LOADING_STAGES_COUNT = sizeof(loadingStages) / sizeof(LoadingStage);
88+
```
89+
90+
After defining your array of `LoadingStages` you can than run the loading process by using
91+
`ui.runLoadingProcess(loadingStages, LOADING_STAGES_COUNT)`. This will give you a
92+
nice little loading animation you can see in the beginning of [this](https://vimeo.com/168362918)
93+
video.
94+
95+
To further customize this you are free to define your own `LoadingDrawFunction` like this:
96+
97+
```c
98+
void myLoadingDraw(OLEDDisplay *display, LoadingStage* stage, uint8_t progress) {
99+
display->setTextAlignment(TEXT_ALIGN_CENTER);
100+
display->setFont(ArialMT_Plain_10);
101+
// stage->process contains the text of the current progress e.q. "Connect to WiFi"
102+
display->drawString(64, 18, stage->process);
103+
// you could just print the current process without the progress bar
104+
display->drawString(64, 28, progress);
105+
}
106+
```
107+
108+
After defining a function like that, you can pass it to the Ui library by use
109+
`ui.setLoadingDrawFunction(myLoadingDraw)`.
110+
111+
112+
### Text Logging
113+
114+
It is always useful to display some text on the display without worrying to much
115+
where it goes and managing it. In 3.0 we made the `OLEDDisplay` class implement
116+
[`Print`](https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Print.h)
117+
so you can use it like you would use `Serial`. We calls this feature `LogBuffer`
118+
and the only thing you have to do is to define how many lines you want to display
119+
and how many characters there are on average on each. This is done by calling
120+
`setLogBuffer(lines, chars);`. If there is not enough memory the function will
121+
return false.
122+
123+
After that you can draw the `LogBuffer` anywhere you want by calling `drawLogBuffer(x, y)`.
124+
(Note: You have to call `display()` to update the screen)
125+
We made a [video](https://www.youtube.com/watch?v=8Fiss77A3TE) showing this feature in action.

0 commit comments

Comments
 (0)