diff --git a/C/Makefile b/C/Makefile index e0edba2..57ec65d 100644 --- a/C/Makefile +++ b/C/Makefile @@ -1,12 +1,14 @@ -Target = display -CXX = gcc -ODIR = obj -SRC =$(wildcard *.c) -DIR =$(notdir $(SRC)) -OBJ = $(patsubst %.c, %.o, $(DIR)) +Target = display +CFLAGS = -Wall +CXX = gcc +LIBS = +ODIR = obj +SRC = $(wildcard *.c) +DIR = $(notdir $(SRC)) +OBJ = $(patsubst %.c, %.o, $(DIR)) $(Target): $(OBJ) - $(CXX) $^ -o $@ -g -rdynamic -.PHONY:clean + $(CXX) $^ -o $@ $(LIBS) +.PHONY: clean clean: rm -rf *.o rm -rf $(Target) diff --git a/C/README.md b/C/README.md deleted file mode 100644 index a9a4862..0000000 --- a/C/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# U6143_ssd1306 -## Enable i2c -```bash -sudo raspi-config -``` -Choose Interface Options -Enable i2c - -## Download library -```bash -git clone https://github.com/UCTRONICS/U6143_ssd1306.git -``` -## Compile the source code -```bash -cd U6143_ssd1306/C -``` -```bash -make -``` - - -## Run the display - -```bash -cd U6143_ssd1306/C -``` -```bash -./display -``` - - - diff --git a/C/bmp.h b/C/bmp.h index 471d444..d8cefe8 100644 --- a/C/bmp.h +++ b/C/bmp.h @@ -1,73 +1,107 @@ -////////////////////////////////////////////////////////////////////////////////// -// -// -// -///////////////////////////////////////////////////////////////////////////////// - #ifndef __BMP_H #define __BMP_H -unsigned char BMP[][512]= -{ -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x08,0x18,0x18,0xFC,0x04,0x04,0x04,0x04,0x04,0xE4,0x24,0x24,0x64,0x04,0x04,0x04,0x04,0x04,0xFC,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00, -0x80,0x80,0x80,0x80,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x80,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0xFE,0x80,0x80,0x80,0x80,0x80,0xBF,0xA0,0xA0, -0xB0,0x80,0x80,0x80,0x80,0x80,0xFF,0x63,0x63,0x63,0x00,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x73,0x00,0x7F,0x04,0x04,0x07,0x00,0x7F,0x40,0x40,0x7F,0x00,0x21,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x7F,0x04,0x04, -0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x11,0x08,0x04,0x22,0x51,0x20,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - - +// 128 x 32 px +unsigned char BMP[][512] = + { + {0xff, 0x00, 0xff, 0x09, 0x09, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xfc, 0x04, 0x04, 0x04, 0x04, 0x04, 0xe4, 0x24, 0x24, 0x64, + 0x04, 0x04, 0x04, 0x04, 0x04, 0xfc, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x40, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0xbf, 0xa0, 0xa0, 0xb0, + 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x40, + 0x40, 0x63, 0x00, 0x7f, 0x04, 0x04, 0x07, 0x00, 0x7f, 0x40, 0x40, 0x7f, 0x00, 0x22, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f, 0x40, 0x40, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x08, 0x04, 0x22, 0x51, 0x20, 0x00, 0x00, 0x00}, -{ -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0x08,0x08,0x04,0xFC,0x00,0xFC,0x04,0x08,0x08,0x10,0x20,0xC0,0x00,0x00, -0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x0D,0x15,0x25,0x45,0x45,0x85,0x85,0x84,0x87,0x80,0x40,0x40,0x20,0x10,0x0F,0x00,0x00,0x00,0x7F,0x01,0x02,0x04,0x02,0x01,0x7F,0x00,0x7F,0x49,0x49,0x4F,0x00,0x7F,0x02, -0x0C,0x02,0x7F,0x00,0x00,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x60,0x18,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x40,0x48,0x48, -0x39,0x00,0x7F,0x44,0x44,0x47,0x7C,0x00,}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x09, 0x09, 0x0f, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0x20, 0x10, 0x08, 0x08, 0x04, 0xfc, 0x00, 0xfc, 0x04, 0x08, 0x08, 0x10, 0x20, 0xc0, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, + 0x15, 0x25, 0x45, 0x45, 0x85, 0x85, 0x84, 0x87, 0x80, 0x40, 0x40, 0x20, 0x10, 0x0f, 0x00, 0x00, + 0x00, 0x7f, 0x01, 0x02, 0x04, 0x02, 0x01, 0x7f, 0x00, 0x7f, 0x49, 0x49, 0x4f, 0x00, 0x7f, 0x02, + 0x0c, 0x02, 0x7f, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0x40, 0x48, 0x48, 0x39, 0x00, 0x7f, 0x44, 0x44, 0x47, 0x7c, 0x00}, -{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0x04,0x08,0x38,0xE0,0x00,0x00,0x80,0x80,0x80,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, -0x7F,0x00,0x00,0x7F,0x40,0x40,0x21,0x1E,0x00,0x74,0x00,0x44,0x4A,0x4A,0x32,0x00,0x7F,0x04,0x0A,0x71,0x00,0x22,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x40,0x48,0x48, -0x39,0x00,0x7F,0x44,0x44,0x47,0x7C,0x00,}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x09, 0x09, 0x0f, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x08, 0x38, 0xe0, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f, 0x00, 0x00, 0x7f, 0x40, 0x40, 0x21, 0x1e, + 0x00, 0x74, 0x00, 0x44, 0x4a, 0x4a, 0x32, 0x00, 0x7f, 0x04, 0x0a, 0x71, 0x00, 0x22, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0x40, 0x48, 0x48, 0x39, 0x00, 0x7f, 0x44, 0x44, 0x47, 0x7c, 0x00}, }; -#endif - - +#endif \ No newline at end of file diff --git a/C/display.c b/C/display.c index 6e1d0d0..a3ccc19 100644 --- a/C/display.c +++ b/C/display.c @@ -1,35 +1,50 @@ -/****** -Demo for ssd1306 i2c driver for Raspberry Pi -******/ -#include -#include "ssd1306_i2c.h" -#include "time.h" -#include +/********************************************************************* + * Demo for SSD1306 I2C driver for Raspberry Pi + *********************************************************************/ +#include +#include // exit +#include // sleep, usleep +#include "ssd1306_i2c.h" // LCD_Display, ssd1306_begin +void sig_handler(int signum) // Return type of the handler function should be void +{ + switch (signum) + { + case SIGHUP: + OLED_Clear(); + exit(0); + case SIGINT: + OLED_Clear(); + exit(0); + case SIGTERM: + OLED_Clear(); + exit(0); + default: + break; + } +} -int main(void) +int main(void) { - unsigned char symbol=0; - ssd1306_begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS); //LCD Screen initialization - if(i2cd<0) - { - printf("I2C device failed to open\r\n"); - return 0; - } - usleep(150*1000); //Short delay Ensure the normal response of the lower function - FirstGetIpAddress(); //Get IP address - while(1) + unsigned short int count = 0; + + signal(SIGHUP, sig_handler); // Register signal handler (can't catch SIGKILL or SIGSTOP) + signal(SIGINT, sig_handler); // Register signal handler (can't catch SIGKILL or SIGSTOP) + signal(SIGTERM, sig_handler); // Register signal handler (can't catch SIGKILL or SIGSTOP) + + ssd1306_begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS); // LCD Screen initialization + usleep(150000); // Short delay to ensure the normal response of the lower functions + + // Loop forever + for (;;) + { + LCD_Display(count); + sleep(1); + count++; + if (count > 2) { - LCD_Display(symbol); - sleep(1); - sleep(1); - sleep(1); - symbol++; - if(symbol==3) - { - symbol=0; - } + count = 0; } - return 0; + } } diff --git a/C/oled_fonts.h b/C/oled_fonts.h index 004fe40..e65e553 100644 --- a/C/oled_fonts.h +++ b/C/oled_fonts.h @@ -2,11 +2,10 @@ #define OLED_FONTS_H #define PROGMEM - -// Standard ASCII 5x7 font Adaf +// Standard ASCII 5x7 font Adaf static const unsigned char font[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, @@ -260,205 +259,202 @@ static const unsigned char font[] PROGMEM = { 0x00, 0x1F, 0x01, 0x01, 0x1E, 0x00, 0x19, 0x1D, 0x17, 0x12, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, - 0x00, 0x00, 0x00, 0x00, 0x00 -}; + 0x00, 0x00, 0x00, 0x00, 0x00}; -const unsigned char F6x8[][6] = -{ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp -0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! -0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " -0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # -0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ -0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % -0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & -0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' -0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( -0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) -0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * -0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + -0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , -0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - -0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . -0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / -0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 -0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 -0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 -0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 -0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 -0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 -0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 -0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 -0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 -0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 -0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : -0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; -0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < -0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = -0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > -0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? -0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ -0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A -0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B -0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C -0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D -0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E -0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F -0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G -0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H -0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I -0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J -0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K -0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L -0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M -0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N -0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O -0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P -0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q -0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R -0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S -0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T -0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U -0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V -0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W -0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X -0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y -0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z -0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ -0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 -0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] -0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ -0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ -0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' -0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a -0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b -0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c -0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d -0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e -0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f -0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g -0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h -0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i -0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j -0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k -0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l -0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m -0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n -0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o -0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p -0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q -0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r -0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s -0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t -0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u -0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v -0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w -0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x -0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y -0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z -0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +const unsigned char F6x8[][6] = + { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // sp + {0x00, 0x00, 0x00, 0x2f, 0x00, 0x00}, // ! + {0x00, 0x00, 0x07, 0x00, 0x07, 0x00}, // " + {0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14}, // # + {0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12}, // $ + {0x00, 0x62, 0x64, 0x08, 0x13, 0x23}, // % + {0x00, 0x36, 0x49, 0x55, 0x22, 0x50}, // & + {0x00, 0x00, 0x05, 0x03, 0x00, 0x00}, // ' + {0x00, 0x00, 0x1c, 0x22, 0x41, 0x00}, // ( + {0x00, 0x00, 0x41, 0x22, 0x1c, 0x00}, // ) + {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14}, // * + {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08}, // + + {0x00, 0x00, 0x00, 0xA0, 0x60, 0x00}, // , + {0x00, 0x08, 0x08, 0x08, 0x08, 0x08}, // - + {0x00, 0x00, 0x60, 0x60, 0x00, 0x00}, // . + {0x00, 0x20, 0x10, 0x08, 0x04, 0x02}, // / + {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0 + {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00}, // 1 + {0x00, 0x42, 0x61, 0x51, 0x49, 0x46}, // 2 + {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31}, // 3 + {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10}, // 4 + {0x00, 0x27, 0x45, 0x45, 0x45, 0x39}, // 5 + {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6 + {0x00, 0x01, 0x71, 0x09, 0x05, 0x03}, // 7 + {0x00, 0x36, 0x49, 0x49, 0x49, 0x36}, // 8 + {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E}, // 9 + {0x00, 0x00, 0x36, 0x36, 0x00, 0x00}, // : + {0x00, 0x00, 0x56, 0x36, 0x00, 0x00}, // ; + {0x00, 0x08, 0x14, 0x22, 0x41, 0x00}, // < + {0x00, 0x14, 0x14, 0x14, 0x14, 0x14}, // = + {0x00, 0x00, 0x41, 0x22, 0x14, 0x08}, // > + {0x00, 0x02, 0x01, 0x51, 0x09, 0x06}, // ? + {0x00, 0x32, 0x49, 0x59, 0x51, 0x3E}, // @ + {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C}, // A + {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36}, // B + {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22}, // C + {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C}, // D + {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41}, // E + {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01}, // F + {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A}, // G + {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F}, // H + {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00}, // I + {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01}, // J + {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41}, // K + {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40}, // L + {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F}, // M + {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F}, // N + {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E}, // O + {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06}, // P + {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E}, // Q + {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46}, // R + {0x00, 0x46, 0x49, 0x49, 0x49, 0x31}, // S + {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01}, // T + {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F}, // U + {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F}, // V + {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F}, // W + {0x00, 0x63, 0x14, 0x08, 0x14, 0x63}, // X + {0x00, 0x07, 0x08, 0x70, 0x08, 0x07}, // Y + {0x00, 0x61, 0x51, 0x49, 0x45, 0x43}, // Z + {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00}, // [ + {0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55}, // 55 + {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00}, // ] + {0x00, 0x04, 0x02, 0x01, 0x02, 0x04}, // ^ + {0x00, 0x40, 0x40, 0x40, 0x40, 0x40}, // _ + {0x00, 0x00, 0x01, 0x02, 0x04, 0x00}, // ' + {0x00, 0x20, 0x54, 0x54, 0x54, 0x78}, // a + {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38}, // b + {0x00, 0x38, 0x44, 0x44, 0x44, 0x20}, // c + {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F}, // d + {0x00, 0x38, 0x54, 0x54, 0x54, 0x18}, // e + {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02}, // f + {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C}, // g + {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78}, // h + {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00}, // i + {0x00, 0x40, 0x80, 0x84, 0x7D, 0x00}, // j + {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00}, // k + {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00}, // l + {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78}, // m + {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78}, // n + {0x00, 0x38, 0x44, 0x44, 0x44, 0x38}, // o + {0x00, 0xFC, 0x24, 0x24, 0x24, 0x18}, // p + {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC}, // q + {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08}, // r + {0x00, 0x48, 0x54, 0x54, 0x54, 0x20}, // s + {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20}, // t + {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C}, // u + {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C}, // v + {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C}, // w + {0x00, 0x44, 0x28, 0x10, 0x28, 0x44}, // x + {0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C}, // y + {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44}, // z + {0x14, 0x14, 0x14, 0x14, 0x14, 0x14}, // horiz lines }; - - -/****************************************8*16的点�***********************************/ -const unsigned char F8X16[]= -{ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 - 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 - 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 - 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 - 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 - 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 - 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 - 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 - 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 - 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 - 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 - 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 - 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 - 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 - 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 - 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 - 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 - 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 - 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 - 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 - 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 - 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 - 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 - 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 - 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 - 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 - 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 - 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 - 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 - 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 - 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 - 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 - 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 - 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 - 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 - 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 - 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 - 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 - 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 - 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 - 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 - 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 - 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 - 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 - 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 - 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 - 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 - 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 - 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 - 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 - 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 - 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 - 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 - 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 - 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 - 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 - 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 - 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 - 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 - 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 - 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 - 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 - 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 - 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 - 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 - 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 - 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 - 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 - 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 - 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 - 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 - 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 - 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 - 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 - 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 - 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 - 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 - 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 - 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 - 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 - 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 - 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 - 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 - 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 - 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 - 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 - 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 - 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 - 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 - 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 - 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +/****************************************8*16的点�?***********************************/ +const unsigned char F8X16[] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 + 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x30, 0x00, 0x00, 0x00, //! 1 + 0x00, 0x10, 0x0C, 0x06, 0x10, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //" 2 + 0x40, 0xC0, 0x78, 0x40, 0xC0, 0x78, 0x40, 0x00, 0x04, 0x3F, 0x04, 0x04, 0x3F, 0x04, 0x04, 0x00, //# 3 + 0x00, 0x70, 0x88, 0xFC, 0x08, 0x30, 0x00, 0x00, 0x00, 0x18, 0x20, 0xFF, 0x21, 0x1E, 0x00, 0x00, //$ 4 + 0xF0, 0x08, 0xF0, 0x00, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x21, 0x1C, 0x03, 0x1E, 0x21, 0x1E, 0x00, //% 5 + 0x00, 0xF0, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x1E, 0x21, 0x23, 0x24, 0x19, 0x27, 0x21, 0x10, //& 6 + 0x10, 0x16, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //' 7 + 0x00, 0x00, 0x00, 0xE0, 0x18, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0x40, 0x00, //( 8 + 0x00, 0x02, 0x04, 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00, //) 9 + 0x40, 0x40, 0x80, 0xF0, 0x80, 0x40, 0x40, 0x00, 0x02, 0x02, 0x01, 0x0F, 0x01, 0x02, 0x02, 0x00, //* 10 + 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x01, 0x01, 0x01, 0x00, //+ 11 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xB0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, //, 12 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, //- 13 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, //. 14 + 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x04, 0x00, 0x60, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, /// 15 + 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x10, 0x0F, 0x00, // 0 16 + 0x00, 0x10, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // 1 17 + 0x00, 0x70, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x30, 0x00, // 2 18 + 0x00, 0x30, 0x08, 0x88, 0x88, 0x48, 0x30, 0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // 3 19 + 0x00, 0x00, 0xC0, 0x20, 0x10, 0xF8, 0x00, 0x00, 0x00, 0x07, 0x04, 0x24, 0x24, 0x3F, 0x24, 0x00, // 4 20 + 0x00, 0xF8, 0x08, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x19, 0x21, 0x20, 0x20, 0x11, 0x0E, 0x00, // 5 21 + 0x00, 0xE0, 0x10, 0x88, 0x88, 0x18, 0x00, 0x00, 0x00, 0x0F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // 6 22 + 0x00, 0x38, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, // 7 23 + 0x00, 0x70, 0x88, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x1C, 0x22, 0x21, 0x21, 0x22, 0x1C, 0x00, // 8 24 + 0x00, 0xE0, 0x10, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x00, 0x00, 0x31, 0x22, 0x22, 0x11, 0x0F, 0x00, // 9 25 + 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, //: 26 + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x00, 0x00, 0x00, 0x00, //; 27 + 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, //< 28 + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, //= 29 + 0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, //> 30 + 0x00, 0x70, 0x48, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x36, 0x01, 0x00, 0x00, //? 31 + 0xC0, 0x30, 0xC8, 0x28, 0xE8, 0x10, 0xE0, 0x00, 0x07, 0x18, 0x27, 0x24, 0x23, 0x14, 0x0B, 0x00, //@ 32 + 0x00, 0x00, 0xC0, 0x38, 0xE0, 0x00, 0x00, 0x00, 0x20, 0x3C, 0x23, 0x02, 0x02, 0x27, 0x38, 0x20, // A 33 + 0x08, 0xF8, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x11, 0x0E, 0x00, // B 34 + 0xC0, 0x30, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, 0x07, 0x18, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, // C 35 + 0x08, 0xF8, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // D 36 + 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x23, 0x20, 0x18, 0x00, // E 37 + 0x08, 0xF8, 0x88, 0x88, 0xE8, 0x08, 0x10, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, // F 38 + 0xC0, 0x30, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x07, 0x18, 0x20, 0x20, 0x22, 0x1E, 0x02, 0x00, // G 39 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x21, 0x3F, 0x20, // H 40 + 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // I 41 + 0x00, 0x00, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, 0x00, // J 42 + 0x08, 0xF8, 0x88, 0xC0, 0x28, 0x18, 0x08, 0x00, 0x20, 0x3F, 0x20, 0x01, 0x26, 0x38, 0x20, 0x00, // K 43 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, // L 44 + 0x08, 0xF8, 0xF8, 0x00, 0xF8, 0xF8, 0x08, 0x00, 0x20, 0x3F, 0x00, 0x3F, 0x00, 0x3F, 0x20, 0x00, // M 45 + 0x08, 0xF8, 0x30, 0xC0, 0x00, 0x08, 0xF8, 0x08, 0x20, 0x3F, 0x20, 0x00, 0x07, 0x18, 0x3F, 0x00, // N 46 + 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0F, 0x00, // O 47 + 0x08, 0xF8, 0x08, 0x08, 0x08, 0x08, 0xF0, 0x00, 0x20, 0x3F, 0x21, 0x01, 0x01, 0x01, 0x00, 0x00, // P 48 + 0xE0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xE0, 0x00, 0x0F, 0x18, 0x24, 0x24, 0x38, 0x50, 0x4F, 0x00, // Q 49 + 0x08, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x03, 0x0C, 0x30, 0x20, // R 50 + 0x00, 0x70, 0x88, 0x08, 0x08, 0x08, 0x38, 0x00, 0x00, 0x38, 0x20, 0x21, 0x21, 0x22, 0x1C, 0x00, // S 51 + 0x18, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // T 52 + 0x08, 0xF8, 0x08, 0x00, 0x00, 0x08, 0xF8, 0x08, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // U 53 + 0x08, 0x78, 0x88, 0x00, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x07, 0x38, 0x0E, 0x01, 0x00, 0x00, // V 54 + 0xF8, 0x08, 0x00, 0xF8, 0x00, 0x08, 0xF8, 0x00, 0x03, 0x3C, 0x07, 0x00, 0x07, 0x3C, 0x03, 0x00, // W 55 + 0x08, 0x18, 0x68, 0x80, 0x80, 0x68, 0x18, 0x08, 0x20, 0x30, 0x2C, 0x03, 0x03, 0x2C, 0x30, 0x20, // X 56 + 0x08, 0x38, 0xC8, 0x00, 0xC8, 0x38, 0x08, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x00, 0x00, // Y 57 + 0x10, 0x08, 0x08, 0x08, 0xC8, 0x38, 0x08, 0x00, 0x20, 0x38, 0x26, 0x21, 0x20, 0x20, 0x18, 0x00, // Z 58 + 0x00, 0x00, 0x00, 0xFE, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x00, //[ 59 + 0x00, 0x0C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x38, 0xC0, 0x00, //\ 60 + 0x00, 0x02, 0x02, 0x02, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x00, 0x00, 0x00, //] 61 + 0x00, 0x00, 0x04, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //^ 62 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, //_ 63 + 0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //` 64 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x19, 0x24, 0x22, 0x22, 0x22, 0x3F, 0x20, // a 65 + 0x08, 0xF8, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x11, 0x20, 0x20, 0x11, 0x0E, 0x00, // b 66 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x20, 0x11, 0x00, // c 67 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0xF8, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0x10, 0x3F, 0x20, // d 68 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00, // e 69 + 0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x18, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // f 70 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x6B, 0x94, 0x94, 0x94, 0x93, 0x60, 0x00, // g 71 + 0x08, 0xF8, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // h 72 + 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // i 73 + 0x00, 0x00, 0x00, 0x80, 0x98, 0x98, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x7F, 0x00, 0x00, // j 74 + 0x08, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x24, 0x02, 0x2D, 0x30, 0x20, 0x00, // k 75 + 0x00, 0x08, 0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x00, 0x00, // l 76 + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x3F, 0x20, 0x00, 0x3F, 0x20, 0x00, 0x3F, // m 77 + 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x3F, 0x21, 0x00, 0x00, 0x20, 0x3F, 0x20, // n 78 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x20, 0x1F, 0x00, // o 79 + 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xA1, 0x20, 0x20, 0x11, 0x0E, 0x00, // p 80 + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0E, 0x11, 0x20, 0x20, 0xA0, 0xFF, 0x80, // q 81 + 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x20, 0x20, 0x3F, 0x21, 0x20, 0x00, 0x01, 0x00, // r 82 + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x33, 0x24, 0x24, 0x24, 0x24, 0x19, 0x00, // s 83 + 0x00, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x00, 0x00, // t 84 + 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x1F, 0x20, 0x20, 0x20, 0x10, 0x3F, 0x20, // u 85 + 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x01, 0x0E, 0x30, 0x08, 0x06, 0x01, 0x00, // v 86 + 0x80, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, 0x80, 0x0F, 0x30, 0x0C, 0x03, 0x0C, 0x30, 0x0F, 0x00, // w 87 + 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x20, 0x31, 0x2E, 0x0E, 0x31, 0x20, 0x00, // x 88 + 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x81, 0x8E, 0x70, 0x18, 0x06, 0x01, 0x00, // y 89 + 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x21, 0x30, 0x2C, 0x22, 0x21, 0x30, 0x00, // z 90 + 0x00, 0x00, 0x00, 0x00, 0x80, 0x7C, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x40, //{ 91 + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, //| 92 + 0x00, 0x02, 0x02, 0x7C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00, //} 93 + 0x00, 0x06, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //~ 94 }; #endif diff --git a/C/ssd1306_i2c.c b/C/ssd1306_i2c.c index 4b27efb..80fcdf1 100644 --- a/C/ssd1306_i2c.c +++ b/C/ssd1306_i2c.c @@ -1,458 +1,658 @@ #include -#include -#include -#include +#include // open +#include // errno +#include // I2C_SLAVE_FORCE +#include // atof +#include // strcmp, strcpy, strtok +#include // statfs +#include // sysinfo #include "ssd1306_i2c.h" #include "bmp.h" #include "oled_fonts.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -char IPSource[20]={0}; -int i2cd; - -// Init SSD1306 +#include // ioctl +#include // if +#include // close, sleep, usleep +#include // inet_ntoa + +int i2cfd; + +/* + * Init SSD1306 + */ void ssd1306_begin(unsigned int vccstate, unsigned int i2caddr) { - unsigned char count=0; - FILE* fp; - unsigned char buffer[20]={0}; - unsigned char i2c[20]="/dev/i2c-1"; - // I2C Init - i2cd = open(i2c,O_RDWR); - if (i2cd < 0) + // I2C init + i2cfd = open("/dev/i2c-1", O_RDWR); + if (i2cfd < 0) { - fprintf(stderr, "Device I2C-1 failed to initialize\n"); - return; + fprintf(stderr, "ssd1306_i2c: Unable to initialize /dev/i2c-1: %s.\n", strerror(errno)); + exit(1); } - if (ioctl(i2cd, I2C_SLAVE_FORCE, i2caddr) < 0) + + if (ioctl(i2cfd, I2C_SLAVE_FORCE, i2caddr) < 0) { - return; + fprintf(stderr, "ssd1306_i2c: ioctl error: %s.\n", strerror(errno)); + exit(1); } - OLED_WR_Byte(0xAE,OLED_CMD);//Disable display - OLED_WR_Byte(0x40,OLED_CMD);//---set low column address - OLED_WR_Byte(0xB0,OLED_CMD);//---set high column address - OLED_WR_Byte(0xC8,OLED_CMD);//-not offset - OLED_WR_Byte(0x81,OLED_CMD);//Set Contrast - OLED_WR_Byte(0xff,OLED_CMD); - OLED_WR_Byte(0xa1,OLED_CMD); - OLED_WR_Byte(0xa6,OLED_CMD); - OLED_WR_Byte(0xa8,OLED_CMD); - OLED_WR_Byte(0x1f,OLED_CMD); - OLED_WR_Byte(0xd3,OLED_CMD); - OLED_WR_Byte(0x00,OLED_CMD); - OLED_WR_Byte(0xd5,OLED_CMD); - OLED_WR_Byte(0xf0,OLED_CMD); - OLED_WR_Byte(0xd9,OLED_CMD); - OLED_WR_Byte(0x22,OLED_CMD); - OLED_WR_Byte(0xda,OLED_CMD); - OLED_WR_Byte(0x02,OLED_CMD); - OLED_WR_Byte(0xdb,OLED_CMD); - OLED_WR_Byte(0x49,OLED_CMD); - OLED_WR_Byte(0x8d,OLED_CMD); - OLED_WR_Byte(0x14,OLED_CMD); - OLED_WR_Byte(0xaf,OLED_CMD); + + OLED_WR_Byte(0xAE, OLED_CMD); // Disable display + OLED_WR_Byte(0x40, OLED_CMD); // ---set low column address + OLED_WR_Byte(0xB0, OLED_CMD); // ---set high column address + OLED_WR_Byte(0xC8, OLED_CMD); // -not offset + OLED_WR_Byte(0x81, OLED_CMD); // Set Contrast + OLED_WR_Byte(0xff, OLED_CMD); + OLED_WR_Byte(0xa1, OLED_CMD); + OLED_WR_Byte(0xa6, OLED_CMD); + OLED_WR_Byte(0xa8, OLED_CMD); + OLED_WR_Byte(0x1f, OLED_CMD); + OLED_WR_Byte(0xd3, OLED_CMD); + OLED_WR_Byte(0x00, OLED_CMD); + OLED_WR_Byte(0xd5, OLED_CMD); + OLED_WR_Byte(0xf0, OLED_CMD); + OLED_WR_Byte(0xd9, OLED_CMD); + OLED_WR_Byte(0x22, OLED_CMD); + OLED_WR_Byte(0xda, OLED_CMD); + OLED_WR_Byte(0x02, OLED_CMD); + OLED_WR_Byte(0xdb, OLED_CMD); + OLED_WR_Byte(0x49, OLED_CMD); + OLED_WR_Byte(0x8d, OLED_CMD); + OLED_WR_Byte(0x14, OLED_CMD); + OLED_WR_Byte(0xaf, OLED_CMD); } +/* + * To send data + */ +void Write_IIC_Data(unsigned char IIC_Data) +{ + unsigned char msg[2] = {0x40, 0}; + msg[1] = IIC_Data; + if (write(i2cfd, msg, 2) != 2) + { + fprintf(stderr, "ssd1306_i2c: Error writing data to /dev/i2c-1: %s.\n", strerror(errno)); + } +} +/* + * Send the command + */ +void Write_IIC_Command(unsigned char IIC_Command) +{ + unsigned char msg[2] = {0x00, 0}; + msg[1] = IIC_Command; + if (write(i2cfd, msg, 2) != 2) + { + fprintf(stderr, "ssd1306_i2c: Error writing command to /dev/i2c-1: %s.\n", strerror(errno)); + } +} -//Displays a string of characters -void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr,unsigned char Char_Size) +/* + * Write a byte + */ +void OLED_WR_Byte(unsigned int dat, unsigned int cmd) { - unsigned char j=0; - while (chr[j]!='\0') - { OLED_ShowChar(x,y,chr[j],Char_Size); - x+=8; - if(x>120){x=0;y+=2;} - j++; - } + if (cmd) + { + Write_IIC_Data(dat); + } + else + { + Write_IIC_Command(dat); + } + + usleep(500); } -void OLED_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size) -{ - unsigned char c=0,i=0; - c=chr-' '; //Get the offset value - if(x>SSD1306_LCDWIDTH-1){x=0;y=y+2;} - if(Char_Size ==16) - { - OLED_Set_Pos(x,y); - for(i=0;i<8;i++) - OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); - OLED_Set_Pos(x,y+1); - for(i=0;i<8;i++) - OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); - } - - else { - OLED_Set_Pos(x,y); - for(i=0;i<6;i++) - OLED_WR_Byte(F6x8[c][i],OLED_DATA); - - } +/* + * Coordinate setting + */ +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WR_Byte(0xb0 + y, OLED_CMD); + OLED_WR_Byte(((x & 0xf0) >> 4) | 0x10, OLED_CMD); + OLED_WR_Byte((x & 0x0f), OLED_CMD); } -unsigned int oled_pow(unsigned char m,unsigned char n) +void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char chr, unsigned char Char_Size) { - unsigned int result=1; - while(n--)result*=m; - return result; -} - -//According to digital -//x,y :Starting point coordinates -//len :Number of digits -//size:The font size -//mode: 0,Fill mode;1,Stacking patterns -//num:(0~4294967295); -void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size2) -{ - unsigned char t,temp; - unsigned char enshow=0; - for(t=0;t>4)|0x10,OLED_CMD); - OLED_WR_Byte((x&0x0f),OLED_CMD); -} - -//Write a byte -void OLED_WR_Byte(unsigned dat,unsigned cmd) + unsigned char c = 0, i = 0; + + c = chr - ' '; // Get the offset value + if (x > SSD1306_LCDWIDTH - 1) + { + x = 0; + y = y + 2; + } + if (Char_Size == 16) + { + OLED_Set_Pos(x, y); + for (i = 0; i < 8; i++) + OLED_WR_Byte(F8X16[c * 16 + i], OLED_DATA); + OLED_Set_Pos(x, y + 1); + for (i = 0; i < 8; i++) + OLED_WR_Byte(F8X16[c * 16 + i + 8], OLED_DATA); + } + + else + { + OLED_Set_Pos(x, y); + for (i = 0; i < 6; i++) + OLED_WR_Byte(F6x8[c][i], OLED_DATA); + } +} + +unsigned int OLED_pow(unsigned char m, unsigned char n) { + unsigned int result = 1; + + while (n--) + result *= m; + return result; +} - if(cmd) - { - Write_IIC_Data(dat); - } - else - { - Write_IIC_Command(dat); - } +/* + * According to digital + * x,y :Starting point coordinates + * num :Integer [0-4294967295] + * len :Number of digits + * size:The font size + * mode:0 - Fill mode; 1 - Stacking patterns + */ +void OLED_ShowNum(unsigned char x, unsigned char y, unsigned int num, unsigned char len, unsigned char size2) +{ + unsigned char t, temp; + unsigned char enshow = 0; - usleep(500); + for (t = 0; t < len; t++) + { + temp = (num / OLED_pow(10, len - t - 1)) % 10; + if (enshow == 0 && t < (len - 1)) + { + if (temp == 0) + { + OLED_ShowChar(x + (size2 / 2) * t, y, ' ', size2); + continue; + } + else + enshow = 1; + } + OLED_ShowChar(x + (size2 / 2) * t, y, temp + '0', size2); + } } -//To send data -void Write_IIC_Data(unsigned char IIC_Data) +/* + * Displays a string of characters + */ +void OLED_ShowString(unsigned char x, unsigned char y, char *chr, unsigned char Char_Size) { - unsigned char msg[2]={0x40,0}; - msg[1]=IIC_Data; - write(i2cd, msg, 2); + unsigned char j = 0; + + while (chr[j] != '\0') + { + OLED_ShowChar(x, y, chr[j], Char_Size); + x += 8; + if (x > 120) + { + x = 0; + y += 2; + } + j++; + } } -//Send the command -void Write_IIC_Command(unsigned char IIC_Command) +/* + * Display the BMP image 128X32 + * x,y:Starting point coordinates; x [0-127], y[0-4] + */ +void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[][512], unsigned char symbol) { - unsigned char msg[2]={0x00,0}; - msg[1]=IIC_Command; - write(i2cd, msg, 2); + unsigned int j = 0; + unsigned char x, y; + + if (y1 % 8 == 0) + y = y1 / 8; + else + y = y1 / 8 + 1; + for (y = y0; y < y1; y++) + { + OLED_Set_Pos(x0, y); + for (x = x0; x < x1; x++) + { + OLED_WR_Byte(BMP[symbol][j++], OLED_DATA); + } + } } +void OLED_DrawPartBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[][512], unsigned char symbol) +{ + unsigned int j = x1 * y0; + unsigned char x, y; -/***********Display the BMP image 128X32 Starting point coordinates(x,y),The range of x 0~127 The range of y 0~4*****************/ -void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[][512],unsigned char symbol) -{ - unsigned int j=0; - unsigned char x,y; - - if(y1%8==0) y=y1/8; - else y=y1/8+1; - for(y=y0;y=100) + int prec = len - 1; + float power10 = 1.0; + + while (f >= power10 && prec > 0) { - OLED_ShowChar(50,3,temp/100+'0',8); //According to the temperature - OLED_ShowChar(58,3,temp/10%10+'0',8); //According to the temperature - OLED_ShowChar(66,3,temp%10+'0',8); + power10 *= 10; + prec--; } - else if(temp<100&&temp>=10) + + char buf[len + 2]; + snprintf(buf, sizeof buf, "%.*f", prec, f); + if (buf[0] == '0') { - OLED_ShowChar(58,3,temp/10+'0',8); //According to the temperature - OLED_ShowChar(66,3,temp%10+'0',8); + strcpy(dest, buf + 1); + return; } else { - OLED_ShowChar(66,3,temp+'0',8); + strncpy(dest, buf, (unsigned int)len); + dest[len] = 0; + } + + // Result is shorter than width + if (strlen(buf) < len) + { + // Right-align to field + snprintf(dest, len + 1, "%*s", len, buf); } - OLED_ShowString(87,3,buffer,8); //Display CPU load } -unsigned char Obaintemperature(void) +/* + * Get CPU usage using popen(top / grep /awk) + */ +float GetCpuUsageTop(void) { - FILE *fd; - unsigned int temp; - char buff[150] = {0}; - fd = fopen("/sys/class/thermal/thermal_zone0/temp","r"); - fgets(buff,sizeof(buff),fd); - sscanf(buff, "%d", &temp); - fclose(fd); - return temp/1000*1.8+32; + FILE *fp; + char buffer[16] = {0}; + + fp = popen("env CPULOOP=1 top -bn 1 | grep -m 1 'Cpu(s)' | awk '{print 100 - $8}'", "r"); + if (fp == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to query top for CPU usage.\n"); + return 0; + } + + fgets(buffer, sizeof(buffer), fp); + + pclose(fp); + /* + fprintf(stderr, "top CPU %f%%\n", atof(buffer)); + */ + + return atof(buffer); } +struct cpustat +{ + unsigned long int t_user; + unsigned long int t_nice; + unsigned long int t_system; + unsigned long int t_idle; + unsigned long int t_iowait; + unsigned long int t_irq; + unsigned long int t_softirq; + unsigned long int t_steal; + unsigned long int t_guest; + unsigned long int t_guestnice; +}; + /* -* LCD displays CPU memory and other information -*/ -void LCD_DisPlayCpuMemory(void) + * Get CPU usage using pstat + */ +float GetCpuUsagePstat(void) { - struct sysinfo s_info; - float Totalram=0.0; - float freeram=0.0; - unsigned int value=0; - unsigned char Total[10]={0}; - unsigned char free[10]={0}; - unsigned char buffer[100]={0}; - unsigned char famer[100]={0}; - if(sysinfo(&s_info)==0) //Get memory information - { - OLED_ClearLint(2,4); - OLED_DrawPartBMP(0,2,128,4,BMP,1); - FILE* fp=fopen("/proc/meminfo","r"); - if(fp==NULL) - { - return ; - } - while(fgets(buffer,sizeof(buffer),fp)) + FILE *fd; + struct cpustat prev, cur; + + fd = fopen("/proc/stat", "r"); + if (fd == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to open /proc/stat file.\n"); + return 0; + } + + fscanf(fd, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", + &prev.t_user, &prev.t_nice, &prev.t_system, &prev.t_idle, &prev.t_iowait, &prev.t_irq, &prev.t_softirq, &prev.t_steal, &prev.t_guest, &prev.t_guestnice); + + fclose(fd); + + unsigned long long int prev_total = prev.t_idle + prev.t_iowait + prev.t_user + prev.t_nice + prev.t_system + prev.t_irq + prev.t_softirq + prev.t_steal; + + /* + fprintf(stderr, "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", prev.t_user, prev.t_nice, prev.t_system, prev.t_idle, prev.t_iowait, prev.t_irq, prev.t_softirq, prev.t_steal, prev.t_guest, prev.t_guestnice); + unsigned long long int prev_idle = prev.t_idle + prev.t_iowait; + unsigned long long int prev_nonidle = prev.t_user + prev.t_nice + prev.t_system + prev.t_irq + prev.t_softirq + prev.t_steal; + //unsigned long long int prev_total = prev_idle + prev_nonidle; + */ + + // Wait for one second to collect data to calculate delta + sleep(3); + + fd = fopen("/proc/stat", "r"); + if (fd == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to open /proc/stat peudofile.\n"); + return 0; + } + + fscanf(fd, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", + &cur.t_user, &cur.t_nice, &cur.t_system, &cur.t_idle, &cur.t_iowait, &cur.t_irq, &cur.t_softirq, &cur.t_steal, &cur.t_guest, &cur.t_guestnice); + + fclose(fd); + + unsigned long long int cur_total = cur.t_idle + cur.t_iowait + cur.t_user + cur.t_nice + cur.t_system + cur.t_irq + cur.t_softirq + cur.t_steal; + + /* + fprintf(stderr, "%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", cur.t_user, cur.t_nice, cur.t_system, cur.t_idle, cur.t_iowait, cur.t_irq, cur.t_softirq, cur.t_steal, cur.t_guest, cur.t_guestnice); + unsigned long long int cur_idle = cur.t_idle + cur.t_iowait; + unsigned long long int cur_nonidle = cur.t_user + cur.t_nice + cur.t_system + cur.t_irq + cur.t_softirq + cur.t_steal; + //unsigned long long int cur_total = cur_idle + cur_nonidle; + + fprintf(stderr, "PREV: idle:%llu\tnonidle: %llu\ttotal: %llu\n", prev_idle, prev_nonidle, prev_total); + fprintf(stderr, "CUR: idle:%llu\tnonidle: %llu\ttotal: %llu\n", cur_idle, cur_nonidle, cur_total); + + // Calculate delta values + unsigned long int total_d = cur_total - prev_total; + unsigned long int idle_d = cur_idle - prev_idle; + unsigned long int used_d = total_d - idle_d; + //float cpu_perc = (float)used_d / (float)total_d * 100.0; + fprintf(stderr, "TOTAL prev: %llu\tcurr: %llu\tdelta: %lu\n", prev_total, cur_total, total_d); + fprintf(stderr, "IDLE prev: %llu\tcurr: %llu\tdelta: %lu\n", prev_idle, cur_idle, idle_d); + fprintf(stderr, "USED delta: %lu\n", used_d); + */ + + float cpu_perc = (float)(cur_total - prev_total - cur.t_idle - cur.t_iowait + prev.t_idle + prev.t_iowait) / (float)(cur_total - prev_total) * 100.0; + + /* + fprintf(stderr, "pstat CPU %f%%\n", cpu_perc); + */ + + return cpu_perc; +} + +char *GetIpAddress(void) +{ + FILE *fd; + char line[100], *p, *c; + + fd = fopen("/proc/net/route", "r"); + if (fd == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to open /proc/net/route pseudofile.\n"); + return '\0'; + } + + while (fgets(line, 100, fd)) + { + p = strtok(line, " \t"); + c = strtok(NULL, " \t"); + + if (p != NULL && c != NULL) { - if(sscanf(buffer,"%s%u",famer,&value)!=2) + if (strcmp(c, "00000000") == 0) { - continue; - } - if(strcmp(famer,"MemTotal:")==0) - { - Totalram=value/1024.0/1024.0; - } - else if(strcmp(famer,"MemFree:")==0) - { - freeram=value/1024.0/1024.0; + break; } } - fclose(fp); - Total[0]=(unsigned char)Totalram+'0'; - Total[1]='.'; - Total[2]=((unsigned char)(Totalram*10))%10+'0'; - Total[3]=='\0'; - - free[0]=(unsigned char)freeram+'0'; - free[1]='.'; - free[2]=((unsigned char)(freeram*10))%10+'0'; - free[3]=='\0'; - OLED_ShowString(55,3,free,8); - OLED_ShowString(90,3,Total,8); } + + fclose(fd); + + // Default to eth0 interface + if (p == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to determine default interface. Defaulting to eth0.\n"); + p = "eth0"; + } + + int sockfd; + struct ifreq ifr; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + + // Type of address to retrieve - IPv4 IP address + ifr.ifr_addr.sa_family = AF_INET; + + // Copy the interface name in the ifreq structure + strncpy(ifr.ifr_name, p, IFNAMSIZ - 1); + + ioctl(sockfd, SIOCGIFADDR, &ifr); + + close(sockfd); + + return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); +} + +float GetTemperature(void) +{ + FILE *fd; + char buffer[150] = {0}; + unsigned int temp; + + fd = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); + if (fd == NULL) + { + fprintf(stderr, "ssd1306_i2c: Unable to open /sys/class/thermal/thermal_zone0/temp peudofile.\n"); + return 0; + } + + fgets(buffer, sizeof(buffer), fd); + + fclose(fd); + + // Parse buffer + sscanf(buffer, "%u", &temp); + + return temp / 1000; // Temperature in degrees Celsius } +/* + * LCD displays CPU temperature and other information + */ +void LCD_DisplayTemperature(void) +{ + char temp[3] = {0}; + char cpu_perc[5] = {0}; + char ip[16] = {0}; + + sprintf_fix(temp, 2, GetTemperature()); // Gets the temperature of the CPU + sprintf_fix(cpu_perc, 4, GetCpuUsagePstat()); // Gets the load on the CPU + strcpy(ip, GetIpAddress()); // Gets the IP address of the default interface + OLED_Clear(); // Clear the screen + OLED_DrawBMP(0, 0, 128, 4, BMP, 0); + + OLED_ShowString(8, 0, ip, 8); // Display IP address + OLED_ShowString(48, 3, temp, 8); // Display CPU temperature + OLED_ShowString(85, 3, cpu_perc, 8); // Display CPU load +} /* -* LCD displays SD card memory information -*/ -void LCD_DisplaySdMemory(void) + * LCD displays CPU memory and other information + */ +void LCD_DisplayCpuMemory(void) { - char usedsize_GB[10]={0}; - char totalsize_GB[10]={0}; - unsigned int MemSize=0; - unsigned int size=0; - struct statfs diskInfo; - statfs("/",&diskInfo); - OLED_ClearLint(2,4); - OLED_DrawPartBMP(0,2,128,4,BMP,2); - unsigned long long blocksize = diskInfo.f_bsize;// The number of bytes per block - unsigned long long totalsize = blocksize*diskInfo.f_blocks;//Total number of bytes - MemSize=(unsigned int)(totalsize>>30); - snprintf(totalsize_GB,7,"%d",MemSize); - if(MemSize>0&&MemSize<10) - { - OLED_ShowString(106,3,totalsize_GB,8); - } - else if(MemSize>=10&&MemSize<100) - { - OLED_ShowString(98,3,totalsize_GB,8); + struct sysinfo s_info; + char free[4] = {0}; + char total[4] = {0}; + + if (sysinfo(&s_info) == 0) // Get memory information + { + OLED_ClearLint(2, 4); + OLED_DrawPartBMP(0, 2, 128, 4, BMP, 1); + + float freeram = ((unsigned long long int)s_info.freeram * (unsigned long long int)s_info.mem_unit >> 20) / 1024.0; + sprintf_fix(free, 3, freeram); + float totalram = ((unsigned long long int)s_info.totalram * (unsigned long long int)s_info.mem_unit >> 20) / 1024.0; + sprintf_fix(total, 3, totalram); + + /* + fprintf(stderr, "mem_unit: %u\n", s_info.mem_unit); + fprintf(stderr, "RAM Free: %f GiB\tTotal: %f GiB\n", + (float)(s_info.freeram * (unsigned long long)s_info.mem_unit >> 20) / 1024.0, + (float)(s_info.totalram * (unsigned long long)s_info.mem_unit >> 20) / 1024.0); + */ + + OLED_ShowString(55, 3, free, 8); + OLED_ShowString(90, 3, total, 8); } else { - OLED_ShowString(90,3,totalsize_GB,8); + fprintf(stderr, "ssd1306_i2c: sysinfo() call failed.\n"); } +} - - unsigned long long freesize = blocksize*diskInfo.f_bfree; //Now let's figure out how much space we have left - size=freesize>>30; - size=MemSize-size; - snprintf(usedsize_GB,7,"%d",size); - if(size>0&&size<10) +/* + * LCD displays SD card memory information using popen(df / awk) + * (Better portability) + */ +void LCD_DisplaySdMemoryDf(void) +{ + char *mnt_dir = "/"; + FILE *fp; + char buffer[32] = {0}; + float usedsize = 0; + float totalsize = 0; + char used[4] = {0}; + char total[4] = {0}; + + fp = popen("df / | awk '{if (NR==2) {print $3 / 1048576\" \"$2 / 1048576}}'", "r"); + if (fp == NULL) { - OLED_ShowString(65,3,usedsize_GB,8); + fprintf(stderr, "ssd1306_i2c: Unable to stat %s filesystem.\n", mnt_dir); + return; } - else if(size>=10&&size<100) + + fgets(buffer, sizeof(buffer), fp); + + pclose(fp); + + // Parse buffer + sscanf(buffer, "%f %f", &usedsize, &totalsize); + sprintf_fix(total, 3, totalsize); + sprintf_fix(used, 3, usedsize); + + /* + fprintf(stderr, "Disk Used: %f\tTotal: %f\n", usedsize, totalsize); + fprintf(stderr, "Disk Used: %s GiB\tTotal: %s GiB\n", used, total); + */ + + OLED_ClearLint(2, 4); + OLED_DrawPartBMP(0, 2, 128, 4, BMP, 2); + + OLED_ShowString(90, 3, total, 8); + OLED_ShowString(55, 3, used, 8); +} + +/* + * LCD displays SD card memory information using statfs() + */ +void LCD_DisplaySdMemoryStatfs(void) +{ + char *mnt_dir = "/"; + struct statfs fs; + char used[4] = {0}; + char total[4] = {0}; + if (statfs(mnt_dir, &fs) == 0) // Get mounted filesystem information { - OLED_ShowString(58,3,usedsize_GB,8); + float totalsize = (((unsigned long long int)fs.f_blocks * (unsigned long long int)fs.f_bsize) >> 20) / 1024.0; + sprintf_fix(total, 3, totalsize); + float usedsize = (((unsigned long long int)(fs.f_blocks - fs.f_bfree) * (unsigned long long int)fs.f_bsize) >> 20) / 1024.4; + sprintf_fix(used, 3, usedsize); + + /* + fprintf(stderr, "f_bsize: %u\n", fs.f_bsize); + fprintf(stderr, "Disk Used: %f GiB\tTotal: %f GiB\n", usedsize, totalsize); + fprintf(stderr, "Disk Used: %s GiB\tTotal: %s GiB\n", used, total); + */ + + OLED_ClearLint(2, 4); + OLED_DrawPartBMP(0, 2, 128, 4, BMP, 2); + + OLED_ShowString(90, 3, total, 8); + OLED_ShowString(55, 3, used, 8); } else { - OLED_ShowString(55,3,usedsize_GB,8); + fprintf(stderr, "ssd1306_i2c: Unable to stat %s filesystem.\n", mnt_dir); } } /* -*According to the information -*/ -void LCD_Display(unsigned char symbol) + * Display according to the information + */ +void LCD_Display(unsigned short int count) { - switch(symbol) + switch (count) { - case 0: - LCD_DisplayTemperature(); + case 0: + LCD_DisplayTemperature(); + sleep(3); break; - case 1: - LCD_DisPlayCpuMemory(); + case 1: + LCD_DisplayCpuMemory(); + sleep(3); break; - case 2: - LCD_DisplaySdMemory(); + case 2: + LCD_DisplaySdMemoryDf(); break; - default: + default: break; } } - - -void FirstGetIpAddress(void) -{ - strcpy(IPSource,GetIpAddress()); -} - -char* GetIpAddress(void) -{ - int fd; - struct ifreq ifr; - int symbol=0; - fd = socket(AF_INET, SOCK_DGRAM, 0); - - /* I want to get an IPv4 IP address */ - ifr.ifr_addr.sa_family = AF_INET; - /* I want IP address attached to "eth0" */ - strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1); - symbol=ioctl(fd, SIOCGIFADDR, &ifr); - close(fd); - if(symbol==0) - { - return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); - } - else - { - fd = socket(AF_INET, SOCK_DGRAM, 0); - /* I want to get an IPv4 IP address */ - ifr.ifr_addr.sa_family = AF_INET; - /* I want IP address attached to "wlan0" */ - strncpy(ifr.ifr_name, "wlan0", IFNAMSIZ-1); - symbol=ioctl(fd, SIOCGIFADDR, &ifr); - close(fd); - if(symbol==0) - { - return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr); - } - else - { - char* buffer="0.0.0.0"; - return buffer; - } - } - /* display result */ -} diff --git a/C/ssd1306_i2c.h b/C/ssd1306_i2c.h index 054d1f0..1492c30 100644 --- a/C/ssd1306_i2c.h +++ b/C/ssd1306_i2c.h @@ -1,7 +1,8 @@ /********************************************************************* -*This is UCTRONICS ssd1306 library header file; -This library just support 128X32 lcd with i2c interface; -*********************************************************************/ + * This is the UCTRONICS ssd1306 library header file + * This library just supports the 128X32 LCD with I2C interface + *********************************************************************/ + #ifndef SSD1306_I2C_H_ #define SSD1306_I2C_H_ @@ -11,30 +12,36 @@ extern int i2cd; #define WHITE 1 #define INVERSE 2 -#define OLED_CMD 0 //command -#define OLED_DATA 1 //data -#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x0C +#define OLED_CMD 0 // command +#define OLED_DATA 1 // data +#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x0C #define SSD1306_SWITCHCAPVCC 0x2 -#define SSD1306_LCDWIDTH 128 -#define SSD1306_LCDHEIGHT 32 -void ssd1306_begin(unsigned int switchvcc, unsigned int i2caddr); //switchvcc should be SSD1306_SWITCHCAPVCC -void OLED_ShowString(unsigned char x,unsigned char y, unsigned char *p,unsigned char Char_Size); -void OLED_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size); -void OLED_Set_Pos(unsigned char x, unsigned char y); -void OLED_WR_Byte(unsigned dat,unsigned cmd); +#define SSD1306_LCDWIDTH 128 +#define SSD1306_LCDHEIGHT 32 + +void ssd1306_begin(unsigned int switchvcc, unsigned int i2caddr); // switchvcc should be SSD1306_SWITCHCAPVCC void Write_IIC_Data(unsigned char IIC_Data); void Write_IIC_Command(unsigned char IIC_Command); -void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[][512],unsigned char); -void OLED_DrawPartBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[][512],unsigned char); +void OLED_WR_Byte(unsigned int dat, unsigned int cmd); +void OLED_Set_Pos(unsigned char x, unsigned char y); +void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char chr, unsigned char Char_Size); +unsigned int OLED_pow(unsigned char, unsigned char); +void OLED_ShowNum(unsigned char, unsigned char, unsigned int, unsigned char, unsigned char); +void OLED_ShowString(unsigned char x, unsigned char y, char *p, unsigned char Char_Size); +void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[][512], unsigned char); +void OLED_DrawPartBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[][512], unsigned char); +void OLED_ClearLint(unsigned char, unsigned char); void OLED_Clear(void); -void OLED_ClearLint(unsigned char,unsigned char); -void OLED_ShowNum(unsigned char,unsigned char,unsigned int,unsigned char,unsigned char); -unsigned int oled_pow(unsigned char,unsigned char); -void LCD_Display(unsigned char symbol); -void LCD_DisPlayCpuMemory(void); -void LCD_DisplaySdMemory(void); -void FirstGetIpAddress(void); -char* GetIpAddress(void); -unsigned char Obaintemperature(void); -#endif /* _SSD1306_I2C_H_ */ +void sprintf_fix(char *dest, int len, float f); +float GetCpuUsageTop(void); +float GetCpuUsagePstat(void); +char *GetIpAddress(void); +float GetTemperature(void); +void LCD_DisplayTemperature(void); +void LCD_DisplayCpuMemory(void); +void LCD_DisplaySdMemoryDf(void); +void LCD_DisplaySdMemoryStatfs(void); +void LCD_Display(unsigned short int symbol); + +#endif /* _SSD1306_I2C_H_ */ diff --git a/README.md b/README.md index ed6a950..130d4d5 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,89 @@ # U6143_ssd1306 -## Preparation + +Display driver for UCTRONICS Ultimate Rack with PoE Functionality for Raspberry Pi 4 (SKU U6145) + +## I2C +Begin by enabling the I2C interface: + ```bash sudo raspi-config ``` -Choose Interface Options -Enable i2c -## Clone U6143_ssd1306 library +Choose `Interface Options` | `I2C`, then answer `Yes` to whether you would like the ARM I2C interface to be enabled. + +Install Git and library dependencies + +```bash +sudo apt update +sudo apt install git wiringpi +``` + +## Clone U6143_ssd1306 library ```bash git clone https://github.com/UCTRONICS/U6143_ssd1306.git ``` + ## Compile ```bash cd U6143_ssd1306/C ``` ```bash -sudo make clean && sudo make +make clean && make ``` + ## Run ``` sudo ./display ``` ## Add automatic start script -- Open the rc.local file +Copy the binary file to `/usr/local/bin/`: + ```bash -sudo nano /etc/rc.local +sudo cp ./display /usr/local/bin/ ``` -- Add command to the rc.local file + +Choose one of the following configuration options (`systemd` **or** `rc.local`): + ```bash -cd /home/pi/U6143_ssd1306/C -sudo make clean -sudo make -sudo ./display & +sudo cp ./contrib/U6143_ssd1306.service /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable U6143_ssd1306.service +sudo systemctl start U6143_ssd1306.service ``` -- reboot your system -## For older 0.91 inch lcd without mcu -- For the older version lcd without mcu controller, you can use python demo -- Install the dependent library files +**OR** add the startup command to the `rc.local` script (not recommended) + ```bash -sudo pip3 install adafruit-circuitpython-ssd1306 -sudo apt-get install python3-pip -sudo apt-get install python3-pil -``` -- Test demo -```bash -cd /home/pi/U6143_ssd1306/python -sudo python3 ssd1306_stats.py +sudo nano /etc/rc.local ``` +and add the command to the rc.local file: +```bash +/usr/local/bin/display & +``` +Reboot your system: +```bash +sudo reboot now +``` +## For older 0.91 inch LCD without MCU +For the older version LCD without MCU controller, you can use the Python demo. +Install the dependent library files: +```bash +sudo apt update +sudo apt install python3-pil python3-pip +sudo pip3 install adafruit-circuitpython-ssd1306 +``` +Test demo: - +```bash +cd U6143_ssd1306/python +sudo python3 ssd1306_stats.py +``` diff --git a/contrib/U6143_ssd1306.service b/contrib/U6143_ssd1306.service new file mode 100644 index 0000000..3686f20 --- /dev/null +++ b/contrib/U6143_ssd1306.service @@ -0,0 +1,10 @@ +[Unit] +Description=Pi Rack (U6143) OLED display service +After=network.target + +[Service] +Type=idle +ExecStart=/usr/local/bin/display + +[Install] +WantedBy=multi-user.target diff --git a/contrib/image1.png b/contrib/image1.png new file mode 100644 index 0000000..796a4da Binary files /dev/null and b/contrib/image1.png differ diff --git a/contrib/image2.png b/contrib/image2.png new file mode 100644 index 0000000..b220e16 Binary files /dev/null and b/contrib/image2.png differ diff --git a/contrib/image3.png b/contrib/image3.png new file mode 100644 index 0000000..5fc561b Binary files /dev/null and b/contrib/image3.png differ diff --git a/contrib/make_tarball.sh b/contrib/make_tarball.sh new file mode 100644 index 0000000..d51ef53 --- /dev/null +++ b/contrib/make_tarball.sh @@ -0,0 +1,12 @@ +#/bin/sh + +#sudo mkdir -p /usr/local/bin && sudo cp ./display /usr/local/bin/ + +tar -Pcvf U6143_ssd1306.tar \ + /etc/systemd/system/U6143_ssd1306.service \ + /usr/local/bin/display \ + +## To extract: +# sudo tar -xvhf U6143_ssd1306.tar +# sudo systemctl daemon-reload +# sudo systemctl enable U6143_ssd1306.service