Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C SSD1306 OLED Support and Button Support #303

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
bd9214c
Added the new libraries
arfrie22 Jun 11, 2024
ed68589
moved lcd functions outside of the arduino def in opensprinkler.h
arfrie22 Jun 11, 2024
98a0ed4
made sure it compiles still for esp8266
arfrie22 Jun 11, 2024
2314143
moving more code to use the display defines
arfrie22 Jun 11, 2024
c3b32bb
added wiringpi
arfrie22 Jun 11, 2024
22a5964
fix buildscript
arfrie22 Jun 11, 2024
994b457
added dummy defines for i2c
arfrie22 Jun 11, 2024
02bcab6
fixed building
arfrie22 Jun 11, 2024
da5b82d
added flash_screen
arfrie22 Jun 11, 2024
1b93e17
added to defines
arfrie22 Jun 11, 2024
21f0b34
added inline keyword
arfrie22 Jun 11, 2024
37b2b97
fixed inline issue and fixed the def issue with the screen commands
arfrie22 Jun 11, 2024
a911876
fixed ssd1306 rpi
arfrie22 Jun 11, 2024
c9323bb
moved back to char
arfrie22 Jun 11, 2024
c52dea1
updated init display
arfrie22 Jun 11, 2024
1c518a5
included the header in cpp file
arfrie22 Jun 11, 2024
16ead0b
fix the bitmap rendering
arfrie22 Jun 11, 2024
54667bf
added wiringpi to install
arfrie22 Jun 11, 2024
b6634e7
change impl
arfrie22 Jun 11, 2024
24d41bf
add state machine
arfrie22 Jun 11, 2024
39559ff
commented out code
arfrie22 Jun 11, 2024
16d5815
add in screen
arfrie22 Jun 11, 2024
dbb21fe
fix def check
arfrie22 Jun 11, 2024
4efd03a
try write block
arfrie22 Jun 11, 2024
086e2a9
fixed code
arfrie22 Jun 11, 2024
29f79bc
chunk write
arfrie22 Jun 11, 2024
3253fa6
fixed size
arfrie22 Jun 11, 2024
359a75a
display chunk size
arfrie22 Jun 11, 2024
5a3ac79
update display
arfrie22 Jun 11, 2024
d16775d
revert display
arfrie22 Jun 11, 2024
cdefdff
revert
arfrie22 Jun 11, 2024
678efc0
more progress towards adding a display
arfrie22 Jun 11, 2024
c6a6c07
fix define
arfrie22 Jun 11, 2024
b8ccadb
once again
arfrie22 Jun 11, 2024
13e4956
int printing
arfrie22 Jun 11, 2024
95d9fb2
fixed buffer
arfrie22 Jun 11, 2024
dda2ff9
more define
arfrie22 Jun 11, 2024
c0cc375
Working lcd
arfrie22 Jun 11, 2024
d8a1d0b
Compiling code
arfrie22 Jun 12, 2024
d5b46bf
Fixed building with debug
arfrie22 Jun 12, 2024
c99dfd7
Working display and input
arfrie22 Jun 12, 2024
4a69a1e
update to use the bcm2835 and SSD1306_OLED_RPI lib
arfrie22 Jun 12, 2024
c1f6fd2
faster oled
arfrie22 Jun 12, 2024
0af86b0
check if wiringpi is installed already
arfrie22 Jun 12, 2024
5dd6d35
added brightness
arfrie22 Jun 12, 2024
a90eb41
added display on/off
arfrie22 Jun 12, 2024
fde7b2b
added ip display
arfrie22 Jun 12, 2024
276664b
added ip address to rpi screen
arfrie22 Jun 12, 2024
1da105d
changed led blink
arfrie22 Jun 12, 2024
660aead
Merge branch 'master' into rpi-update
arfrie22 Jun 19, 2024
db87db6
Merge branch 'master' into rpi-update
arfrie22 Jul 31, 2024
45ce24c
update build
arfrie22 Jul 31, 2024
f100270
Merge pull request #301 from arfrie22/rpi-update
arfrie22 Jul 31, 2024
0bc40b6
fix make
arfrie22 Jul 31, 2024
402986e
added rpi time library
arfrie22 Jul 31, 2024
5d54f43
fixed header def
arfrie22 Jul 31, 2024
70ce4cf
fix if in header
arfrie22 Jul 31, 2024
a0cc920
update funcitons for pi
arfrie22 Jul 31, 2024
22d6a22
added ui state machine
arfrie22 Jul 31, 2024
ceebf21
add system idle
arfrie22 Aug 1, 2024
5db69b4
update build script to prepare for switching to libi2c
arfrie22 Aug 1, 2024
d5b741e
switch to i2cdev for ssd1306
arfrie22 Aug 1, 2024
85e6c17
update docker and build for demo
arfrie22 Aug 1, 2024
f62af23
fix typos
arfrie22 Aug 1, 2024
080dccb
fix narrowing conversion of images
arfrie22 Aug 1, 2024
cbedb78
remove wiring pi
arfrie22 Aug 1, 2024
2285210
push to move dev to rpi
arfrie22 Aug 1, 2024
d0a8efb
fix get board type
arfrie22 Aug 2, 2024
ac5e75d
move gpio chip to get_board_type
arfrie22 Aug 2, 2024
bb7addb
move i2c device handling to another class
arfrie22 Aug 2, 2024
f968999
remove magic numbers
arfrie22 Aug 2, 2024
c2a4ef4
fix capitalization
arfrie22 Aug 2, 2024
40b5a08
fix build script
arfrie22 Aug 2, 2024
1fcc971
Merge branch 'master' into rpi-update
arfrie22 Aug 5, 2024
3dbd976
enable i2c
arfrie22 Aug 5, 2024
76ec0dd
Merge branch 'master' into rpi-update
arfrie22 Aug 5, 2024
3b90546
0 enables i2c not 1 with raspi-config
arfrie22 Aug 5, 2024
8f0c187
make sure raspi-config is there to enable i2c
arfrie22 Aug 5, 2024
5fa5526
switch order of i2c enable
arfrie22 Aug 5, 2024
9ccadd7
fix function call
arfrie22 Aug 5, 2024
b5a83a5
update build script to set clock speed
arfrie22 Aug 5, 2024
b71e76a
fix grep
arfrie22 Aug 5, 2024
1d5c046
update if
arfrie22 Aug 5, 2024
7626e93
fix if statement
arfrie22 Aug 5, 2024
0944c73
negate statement
arfrie22 Aug 5, 2024
36fda48
change build script not to override i2c
arfrie22 Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN make
FROM base AS os-build

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y bash g++ make libmosquittopp-dev libssl-dev
RUN apt-get update && apt-get install -y bash g++ make libmosquittopp-dev libssl-dev libi2c-dev
RUN rm -rf /var/lib/apt/lists/*
COPY . /OpenSprinkler
WORKDIR /OpenSprinkler
Expand All @@ -34,7 +34,7 @@ RUN make VERSION=${BUILD_VERSION}
FROM base

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y libstdc++6 libmosquittopp1
RUN apt-get update && apt-get install -y libstdc++6 libmosquittopp1 libi2c0
RUN rm -rf /var/lib/apt/lists/*
RUN mkdir /OpenSprinkler
RUN mkdir -p /data/logs
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CXX=g++
VERSION=OSPI
CXXFLAGS=-std=gnu++14 -D$(VERSION) -DSMTP_OPENSSL -Wall -include string.h -Iexternal/TinyWebsockets/tiny_websockets_lib/include -Iexternal/OpenThings-Framework-Firmware-Library/
LD=$(CXX)
LIBS=pthread mosquitto ssl crypto
LIBS=pthread mosquitto ssl crypto i2c
LDFLAGS=$(addprefix -l,$(LIBS))
BINARY=OpenSprinkler
SOURCES=main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp mqtt.cpp smtp.c $(wildcard external/TinyWebsockets/tiny_websockets_lib/src/*.cpp) $(wildcard external/OpenThings-Framework-Firmware-Library/*.cpp)
Expand Down
148 changes: 117 additions & 31 deletions OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ extern char tmp_buffer[];
extern char ether_buffer[];
extern ProgramData pd;

#if defined(ESP8266)
#if defined(USE_SSD1306)
SSD1306Display OpenSprinkler::lcd(0x3c, SDA, SCL);
#elif defined(USE_LCD)
LiquidCrystal OpenSprinkler::lcd;
#endif

#if defined(ESP8266)
unsigned char OpenSprinkler::state = OS_STATE_INITIAL;
unsigned char OpenSprinkler::prev_station_bits[MAX_NUM_BOARDS];
IOEXP* OpenSprinkler::expanders[MAX_NUM_BOARDS/2];
Expand All @@ -90,13 +95,11 @@ extern ProgramData pd;
unsigned char OpenSprinkler::wifi_channel=255;
unsigned char OpenSprinkler::wifi_testmode = 0;
#elif defined(ARDUINO)
LiquidCrystal OpenSprinkler::lcd;
extern SdFat sd;
#else
#if defined(OSPI)
unsigned char OpenSprinkler::pin_sr_data = PIN_SR_DATA;
#endif
// todo future: LCD define for Linux-based systems
#endif

#if defined(USE_OTF)
Expand Down Expand Up @@ -796,16 +799,16 @@ void OpenSprinkler::update_dev() {
}
#endif // end network init functions

#if defined(ARDUINO)
#if defined(USE_DISPLAY)
/** Initialize LCD */
void OpenSprinkler::lcd_start() {

#if defined(ESP8266)
#if defined(USE_SSD1306)
// initialize SSD1306
lcd.init();
lcd.begin();
flash_screen();
#else
#elif defined(USE_LCD)
// initialize 16x2 character LCD
// turn on lcd
lcd.init(1, PIN_LCD_RS, 255, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7, 0,0,0,0);
Expand Down Expand Up @@ -956,6 +959,12 @@ void OpenSprinkler::begin() {
pinMode(PIN_SR_DATA, OUTPUT);
#endif

#endif

#if defined(OSPI)
pinModeExt(PIN_BUTTON_1, INPUT_PULLUP);
pinModeExt(PIN_BUTTON_2, INPUT_PULLUP);
pinModeExt(PIN_BUTTON_3, INPUT_PULLUP);
#endif

// Reset all stations
Expand Down Expand Up @@ -1038,27 +1047,28 @@ void OpenSprinkler::begin() {
baseline_current = 0;

#endif

#endif
#if defined(USE_DISPLAY)
lcd_start();

#if defined(ESP8266)
#if defined(USE_SSD1306)
lcd.createChar(ICON_ETHER_CONNECTED, _iconimage_ether_connected);
lcd.createChar(ICON_ETHER_DISCONNECTED, _iconimage_ether_disconnected);
#else
lcd.createChar(ICON_WIFI_CONNECTED, _iconimage_wifi_connected);
lcd.createChar(ICON_WIFI_DISCONNECTED, _iconimage_wifi_disconnected);
#elif defined(USE_LCD)
lcd.createChar(ICON_ETHER_CONNECTED, _iconimage_connected);
lcd.createChar(ICON_ETHER_DISCONNECTED, _iconimage_disconnected);
#endif

lcd.createChar(ICON_REMOTEXT, _iconimage_remotext);
lcd.createChar(ICON_RAINDELAY, _iconimage_raindelay);
lcd.createChar(ICON_RAIN, _iconimage_rain);
lcd.createChar(ICON_SOIL, _iconimage_soil);
#endif

#if defined(ARDUINO)
#if defined(ESP8266)

/* create custom characters */
lcd.createChar(ICON_WIFI_CONNECTED, _iconimage_wifi_connected);
lcd.createChar(ICON_WIFI_DISCONNECTED, _iconimage_wifi_disconnected);

lcd.setCursor(0,0);
lcd.print(F("Init file system"));
lcd.setCursor(0,1);
Expand Down Expand Up @@ -1753,8 +1763,9 @@ unsigned char OpenSprinkler::weekday_today() {
ulong wd = now_tz() / 86400L;
return (wd+3) % 7; // Jan 1, 1970 is a Thursday
#else
return 0;
// todo future: is this function needed for RPI/BBB?
time_t t = time(NULL);
struct tm *tm = localtime(&t);
return (tm->tm_wday+6) % 7;
#endif
}

Expand Down Expand Up @@ -2550,6 +2561,7 @@ void OpenSprinkler::raindelay_stop() {
}

/** LCD and button functions */
#if defined(USE_DISPLAY)
#if defined(ARDUINO) // AVR LCD and button functions
/** print a program memory string */
#if defined(ESP8266)
Expand Down Expand Up @@ -2579,6 +2591,28 @@ void OpenSprinkler::lcd_print_line_clear_pgm(PGM_P PROGMEM str, unsigned char li
for(; (16-cnt) >= 0; cnt ++) lcd_print_pgm(PSTR(" "));
}

#else
void OpenSprinkler::lcd_print_pgm(const char *str) {
lcd.print(str);
}
void OpenSprinkler::lcd_print_line_clear_pgm(const char *str, uint8_t line) {
char buf[16];
uint8_t c;
int8_t cnt = 0;
while((c=*str++)!= '\0' && cnt<16) {
buf[cnt] = c;
cnt++;
}

for(int i=cnt; i<16; i++) buf[i] = ' ';

lcd.setCursor(0, line);
lcd.print(buf);
}

#define PGSTR(s) s
#endif

void OpenSprinkler::lcd_print_2digit(int v)
{
lcd.print((int)(v/10));
Expand All @@ -2588,59 +2622,91 @@ void OpenSprinkler::lcd_print_2digit(int v)
/** print time to a given line */
void OpenSprinkler::lcd_print_time(time_os_t t)
{
#if defined(ESP8266)
#if defined(USE_SSD1306)
lcd.setAutoDisplay(false);
#endif
lcd.setCursor(0, 0);
lcd_print_2digit(hour(t));

lcd_print_pgm(PSTR(":"));

lcd_print_2digit(minute(t));

lcd_print_pgm(PSTR(" "));

// each weekday string has 3 characters + ending 0
lcd_print_pgm(days_str+4*weekday_today());

lcd_print_pgm(PSTR(" "));

lcd_print_2digit(month(t));

lcd_print_pgm(PSTR("-"));

lcd_print_2digit(day(t));
#if defined(ESP8266)
#if defined(USE_SSD1306)
lcd.display();
lcd.setAutoDisplay(true);
#endif
}

/** print ip address */
void OpenSprinkler::lcd_print_ip(const unsigned char *ip, unsigned char endian) {
#if defined(ESP8266)
#if defined(USE_SSD1306)
lcd.clear(0, 1);
#else
lcd.setAutoDisplay(false);
#elif defined(USE_LCD)
lcd.clear();
#endif
lcd.setCursor(0, 0);
for (unsigned char i=0; i<4; i++) {
lcd.print(endian ? (int)ip[3-i] : (int)ip[i]);
if(i<3) lcd_print_pgm(PSTR("."));

if(i<3) {
lcd_print_pgm(PSTR("."));
}
}

#if defined(USE_SSD1306)
lcd.display();
lcd.setAutoDisplay(true);
#endif
}

/** print mac address */
void OpenSprinkler::lcd_print_mac(const unsigned char *mac) {
#if defined(USE_SSD1306)
lcd.setAutoDisplay(false); // reduce screen drawing time by turning off display() when drawing individual characters
#endif
lcd.setCursor(0, 0);
for(unsigned char i=0; i<6; i++) {
if(i) lcd_print_pgm(PSTR("-"));
if(i) {
lcd_print_pgm(PSTR("-"));
}

lcd.print((mac[i]>>4), HEX);
lcd.print((mac[i]&0x0F), HEX);
if(i==4) lcd.setCursor(0, 1);
}
#if defined(ARDUINO)
if(useEth) {
lcd_print_pgm(PSTR(" (Ether MAC)"));
} else {
lcd_print_pgm(PSTR(" (WiFi MAC)"));
}
#else
lcd_print_pgm(PSTR(" (MAC)"));
#endif

#if defined(USE_SSD1306)
lcd.display();
lcd.setAutoDisplay(true);
#endif
}

/** print station bits */
void OpenSprinkler::lcd_print_screen(char c) {
#if defined(ESP8266)
#if defined(USE_SSD1306)
lcd.setAutoDisplay(false); // reduce screen drawing time by turning off display() when drawing individual characters
#endif
lcd.setCursor(0, 1);
Expand Down Expand Up @@ -2728,9 +2794,12 @@ void OpenSprinkler::lcd_print_screen(char c) {
lcd.write(status.network_fails>2?ICON_ETHER_DISCONNECTED:ICON_ETHER_CONNECTED); // if network failure detection is more than 2, display disconnect icon
#endif

#if defined(ESP8266)

if(useEth || (get_wifi_mode()==WIFI_MODE_STA && WiFi.status()==WL_CONNECTED && WiFi.localIP())) {
#if defined(USE_SSD1306)
#if defined(ESP8266)
if(useEth || (get_wifi_mode()==WIFI_MODE_STA && WiFi.status()==WL_CONNECTED && WiFi.localIP())) {
#else
{
#endif
lcd.setCursor(0, -1);
if(status.rain_delayed) {
lcd.print(F("<Rain Delay On> "));
Expand All @@ -2742,17 +2811,21 @@ void OpenSprinkler::lcd_print_screen(char c) {
lcd.print(F(" (System Idle) "));
}

#if defined(ESP8266)
lcd.setCursor(2, 2);
if(status.program_busy && !status.pause_state) {
//lcd.print(F("Curr: "));
lcd.print(read_current());
lcd.print(F(" mA "));
} else {
#else
{
#endif
lcd.clear(2, 2);
}
}
#endif
#if defined(ESP8266)


lcd.display();
lcd.setAutoDisplay(true);
#endif
Expand Down Expand Up @@ -2855,6 +2928,7 @@ void OpenSprinkler::lcd_print_option(int i) {

}


/** Button functions */
/** wait for button */
unsigned char OpenSprinkler::button_read_busy(unsigned char pin_butt, unsigned char waitmode, unsigned char butt, unsigned char is_holding) {
Expand Down Expand Up @@ -2906,6 +2980,8 @@ unsigned char OpenSprinkler::button_read(unsigned char waitmode)
return ret;
}

#if defined(ARDUINO)

/** user interface for setting options during startup */
void OpenSprinkler::ui_set_options(int oid)
{
Expand Down Expand Up @@ -2971,6 +3047,9 @@ void OpenSprinkler::ui_set_options(int oid)
lcd.noBlink();
}

#else
#endif // end of LCD and button functions

/** Set LCD contrast (using PWM) */
void OpenSprinkler::lcd_set_contrast() {
#ifdef PIN_LCD_CONTRAST
Expand Down Expand Up @@ -3005,17 +3084,18 @@ void OpenSprinkler::lcd_set_brightness(unsigned char value) {
}
}

#elif defined(ESP8266)
#elif defined(USE_SSD1306)
if (value) {lcd.displayOn();lcd.setBrightness(255); }
else {
if(iopts[IOPT_LCD_DIMMING]==0) lcd.displayOff();
else { lcd.displayOn();lcd.setBrightness(iopts[IOPT_LCD_DIMMING]); }
}
#endif
}
#endif // end of LCD and button functions

#if defined(ESP8266)


#if defined(USE_SSD1306)
#include "images.h"
void OpenSprinkler::flash_screen() {
lcd.setCursor(0, -1);
Expand All @@ -3041,6 +3121,12 @@ void OpenSprinkler::set_screen_led(unsigned char status) {
lcd.setColor(WHITE);
}

#endif

#endif

#if defined(ESP8266)

void OpenSprinkler::reset_to_ap() {
iopts[IOPT_WIFI_MODE] = WIFI_MODE_AP;
iopts_save();
Expand Down
Loading