forked from kjhughes097/pi-ssd1306-oled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssd1306.h
69 lines (55 loc) · 1.72 KB
/
ssd1306.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Ken Hughes
// July 2016
// Modified for 128x32 by Jochen Peters Krefeld (Aug 2017)
#include <unistd.h>//Needed for I2C port
#include <fcntl.h>//Needed for I2C port
#include <sys/ioctl.h>//Needed for I2C port
#include <linux/i2c-dev.h>//Needed for I2C port
#include <stdio.h>
#include <string.h>
#ifndef BOOL
#define BOOL
#define FALSE 0
#define TRUE -1
#endif
#ifndef SSD1306_H_INCLUDED
#define SSD1306_H_INCLUDED
class SSD1306
{
public:
enum Mode
{
SCROLL,
WRAP
};
SSD1306();
void clearDisplay();
void initDisplay();
void textDisplay(const char *message);
void setWordWrap(int);
void setDisplayMode(SSD1306::Mode);
private:
// line buffers (128 chars * 4 lines)
unsigned char displayLines[4][128];
int currentLine = 0;
int wordWrap = FALSE;
int displayMode = Mode::SCROLL;
int currentScrollLine = 0;
int needScroll = FALSE;
// i2c handles
int i2cHandle = -1;
int i2cInitialised = FALSE;
int i2cAddress = 0x3C;
// ssd1306 command sequences
unsigned char initSequence[26] = {0x00,0xAE,0xA8,0x1F,0xD3,0x00,0x40,0xA1,0xC8,0xDA,0x02,0x81,0x8F,
0xA4,0xA6,0xD5,0x80,0x8D,0x14,0xD9,0x22,0xD8,0x30,0x20,0x00,0xAF};
unsigned char setFullRange[7] = {0x00,0x21,0x00,0x7F,0x22,0x00,0x03};
unsigned char scrollUpSequence[3] = {0x00,0xD3,0x04};
// helper functions
int addFontBytes(int curr, unsigned char c);
void setDisplayRange(int line);
void updateDisplayFull();
void writeI2C(unsigned char* data, int bytes);
void scrollUp(int);
};
#endif