|
@@ -0,0 +1,275 @@
|
|
|
+#include "driver.h"
|
|
|
+
|
|
|
+sFONT Font12 = {
|
|
|
+ Font12_Table,
|
|
|
+ 7, /* Width */
|
|
|
+ 12, /* Height */
|
|
|
+};
|
|
|
+void Driver::OLED_InitReg(void)
|
|
|
+{
|
|
|
+ OLED_WriteReg(0xAE);//--turn off oled panel
|
|
|
+ OLED_WriteReg(0x00);//---set low column address
|
|
|
+ OLED_WriteReg(0x10);//---set high column address
|
|
|
+ OLED_WriteReg(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
|
|
|
+ OLED_WriteReg(0x81);//--set contrast control register
|
|
|
+ OLED_WriteReg(0xA0);//--Set SEG/Column Mapping
|
|
|
+ OLED_WriteReg(0xC0);//Set COM/Row Scan Direction
|
|
|
+ OLED_WriteReg(0xA6);//--set normal display
|
|
|
+ OLED_WriteReg(0xA8);//--set multiplex ratio(1 to 64)
|
|
|
+ OLED_WriteReg(0x3F);//--1/64 duty
|
|
|
+ OLED_WriteReg(0xD3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
|
|
|
+ OLED_WriteReg(0x00);//-not offset
|
|
|
+ OLED_WriteReg(0xd5);//--set display clock divide ratio/oscillator frequency
|
|
|
+ OLED_WriteReg(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
|
|
|
+ OLED_WriteReg(0xD9);//--set pre-charge period
|
|
|
+ OLED_WriteReg(0xF1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
|
|
|
+ OLED_WriteReg(0xDA);//--set com pins hardware configuration
|
|
|
+ OLED_WriteReg(0x12);
|
|
|
+ OLED_WriteReg(0xDB);//--set vcomh
|
|
|
+ OLED_WriteReg(0x40);//Set VCOM Deselect Level
|
|
|
+ OLED_WriteReg(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
|
|
|
+ OLED_WriteReg(0x02);//
|
|
|
+ OLED_WriteReg(0xA4);// Disable Entire Display On (0xa4/0xa5)
|
|
|
+ OLED_WriteReg(0xA6);// Disable Inverse Display On (0xa6/a7)
|
|
|
+ OLED_WriteReg(0xA1);
|
|
|
+ OLED_WriteReg(0xC8);
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_Init(OLED_SCAN_DIR OLED_ScanDir)
|
|
|
+{
|
|
|
+ //Set the initialization register
|
|
|
+ OLED_InitReg();
|
|
|
+
|
|
|
+ //Set the display scan and color transfer modes
|
|
|
+ OLED_SetGramScanWay(OLED_ScanDir );
|
|
|
+ oled_dev.DEV_Delay_ms(200);
|
|
|
+
|
|
|
+ //Turn on the OLED display
|
|
|
+ OLED_WriteReg(0xAF);
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_SetGramScanWay(OLED_SCAN_DIR Scan_dir)
|
|
|
+{
|
|
|
+ sOLED_DIS.OLED_Scan_Dir = Scan_dir;
|
|
|
+
|
|
|
+ //Get GRAM and OLED width and height
|
|
|
+ if(Scan_dir == L2R_U2D || Scan_dir == L2R_D2U || Scan_dir == R2L_U2D || Scan_dir == R2L_D2U) {
|
|
|
+ sOLED_DIS.OLED_Dis_Column = OLED_WIDTH ;
|
|
|
+ sOLED_DIS.OLED_Dis_Page = OLED_HEIGHT ;
|
|
|
+ sOLED_DIS.OLED_X_Adjust = OLED_X;
|
|
|
+ sOLED_DIS.OLED_Y_Adjust = OLED_Y;
|
|
|
+ } else {
|
|
|
+ sOLED_DIS.OLED_Dis_Column = OLED_HEIGHT ;
|
|
|
+ sOLED_DIS.OLED_Dis_Page = OLED_WIDTH ;
|
|
|
+ sOLED_DIS.OLED_X_Adjust = OLED_Y;
|
|
|
+ sOLED_DIS.OLED_Y_Adjust = OLED_X;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_WriteData_nLen8Bit(uint8_t *pBuf, uint32_t Len)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ for(i = 0; i < Len; i++) {
|
|
|
+ oled_dev.I2C_Write_Byte(*pBuf,IIC_RAM);
|
|
|
+ pBuf++;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_WriteReg(uint8_t Reg)
|
|
|
+{
|
|
|
+ oled_dev.I2C_Write_Byte(Reg,IIC_CMD);
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_SetCursor(POINT Xpoint, POINT Ypoint)
|
|
|
+{
|
|
|
+ if((Xpoint > sOLED_DIS.OLED_Dis_Column) || (Ypoint > sOLED_DIS.OLED_Dis_Page))
|
|
|
+ return;
|
|
|
+
|
|
|
+ /* set page address */
|
|
|
+ OLED_WriteReg(0xB0 + (Ypoint / 8));
|
|
|
+ /* set low column address */
|
|
|
+ OLED_WriteReg((Xpoint & 0x0f) + sOLED_DIS.OLED_X_Adjust);
|
|
|
+ /* set high column address */
|
|
|
+ OLED_WriteReg((Xpoint >> 4) + 0x10);
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_SetColor(POINT Xpoint, POINT Ypoint, COLOR Color)
|
|
|
+{
|
|
|
+ if(Xpoint < 0 || Xpoint >= sOLED_DIS.OLED_Dis_Column ||
|
|
|
+ Ypoint < 0 || Ypoint >= sOLED_DIS.OLED_Dis_Page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //Transform line by line into column line
|
|
|
+ if (Color) {
|
|
|
+ Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 1 << (Ypoint % 8);
|
|
|
+ } else {
|
|
|
+ Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 0 << (Ypoint % 8);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::OLED_Clear(COLOR Color)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ for(i = 0; i < sizeof(Buffer); i++) {
|
|
|
+ Buffer[i] = Color;
|
|
|
+ }
|
|
|
+}
|
|
|
+void Driver::OLED_Display(void)
|
|
|
+{
|
|
|
+ uint8_t page;
|
|
|
+ char *pBuf = (char *)Buffer;
|
|
|
+
|
|
|
+ for (page = 0; page < 8; page++) {
|
|
|
+ /* set page address */
|
|
|
+ OLED_WriteReg(0xB0 + page);
|
|
|
+ /* set low column address */
|
|
|
+ OLED_WriteReg(0x02);
|
|
|
+ /* set high column address */
|
|
|
+ OLED_WriteReg(0x10);
|
|
|
+
|
|
|
+ /* write data */
|
|
|
+ OLED_WriteData_nLen8Bit((uint8_t *)pBuf, sOLED_DIS.OLED_Dis_Column);
|
|
|
+ pBuf += sOLED_DIS.OLED_Dis_Column;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::GUI_DrawPoint(POINT Xpoint, POINT Ypoint, COLOR Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_FillWay)
|
|
|
+{
|
|
|
+ if(Xpoint > sOLED_DIS.OLED_Dis_Column || Ypoint > sOLED_DIS.OLED_Dis_Page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ uint16_t XDir_Num ,YDir_Num;
|
|
|
+ if(Dot_FillWay == DOT_STYLE_DFT) {
|
|
|
+ for(XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
|
|
|
+ for(YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
|
|
|
+ OLED_SetColor(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for(XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
|
|
|
+ for(YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
|
|
|
+ OLED_SetColor(Xpoint + XDir_Num - 1 , Ypoint + YDir_Num -1 , Color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::GUI_DisChar(POINT Xpoint, POINT Ypoint, const char Acsii_Char, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground)
|
|
|
+{
|
|
|
+ POINT Page, Column;
|
|
|
+
|
|
|
+ if(Xpoint >= sOLED_DIS.OLED_Dis_Column || Ypoint >= sOLED_DIS.OLED_Dis_Page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ uint32_t Char_Offset =(Acsii_Char - ' ') * Font->Height *(Font->Width / 8 +(Font->Width % 8 ? 1 : 0));
|
|
|
+ const unsigned char *ptr = &Font->table[Char_Offset];
|
|
|
+
|
|
|
+ for(Page = 0; Page < Font->Height; Page ++ ) {
|
|
|
+ for(Column = 0; Column < Font->Width; Column ++ ) {
|
|
|
+
|
|
|
+ //To determine whether the font background color and screen background color is consistent
|
|
|
+ if(FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
|
|
|
+ if(*ptr &(0x80 >>(Column % 8)))
|
|
|
+ GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
|
|
|
+ } else {
|
|
|
+ if(*ptr &(0x80 >>(Column % 8))) {
|
|
|
+ GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
|
|
|
+ } else {
|
|
|
+ GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //One pixel is 8 bits
|
|
|
+ if(Column % 8 == 7)
|
|
|
+ ptr++;
|
|
|
+ }/* Write a line */
|
|
|
+ if(Font->Width % 8 != 0)
|
|
|
+ ptr++;
|
|
|
+ }/* Write all */
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::GUI_DisString_EN(POINT Xstart, POINT Ystart, const char * pString, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground )
|
|
|
+{
|
|
|
+ POINT Xpoint = Xstart;
|
|
|
+ POINT Ypoint = Ystart;
|
|
|
+
|
|
|
+ if(Xstart >= sOLED_DIS.OLED_Dis_Column || Ystart >= sOLED_DIS.OLED_Dis_Page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(* pString != '\0') {
|
|
|
+ //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the height of the character
|
|
|
+ if((Xpoint + Font->Width ) > sOLED_DIS.OLED_Dis_Column ) {
|
|
|
+ Xpoint = Xstart;
|
|
|
+ Ypoint += Font->Height;
|
|
|
+ }
|
|
|
+
|
|
|
+ // If the Y direction is full, reposition to(Xstart, Ystart)
|
|
|
+ if((Ypoint + Font->Height ) > sOLED_DIS.OLED_Dis_Page ) {
|
|
|
+ Xpoint = Xstart;
|
|
|
+ Ypoint = Ystart;
|
|
|
+ }
|
|
|
+ GUI_DisChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
|
|
|
+
|
|
|
+ //The next character of the address
|
|
|
+ pString ++;
|
|
|
+
|
|
|
+ //The next word of the abscissa increases the font of the broadband
|
|
|
+ Xpoint += Font->Width;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::GUI_DisNum(POINT Xpoint, POINT Ypoint, int32_t Nummber, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground )
|
|
|
+{
|
|
|
+ int16_t Num_Bit = 0, Str_Bit = 0;
|
|
|
+ uint8_t Str_Array[ARRAY_LEN] = {0},Num_Array[ARRAY_LEN] = {0};
|
|
|
+ uint8_t *pStr = Str_Array;
|
|
|
+
|
|
|
+ if(Xpoint >= sOLED_DIS.OLED_Dis_Column || Ypoint >= sOLED_DIS.OLED_Dis_Page) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Converts a number to a string
|
|
|
+ while(Nummber) {
|
|
|
+ Num_Array[Num_Bit] = Nummber % 10 + '0';
|
|
|
+ Num_Bit++;
|
|
|
+ Nummber /= 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ //The string is inverted
|
|
|
+ while(Num_Bit > 0) {
|
|
|
+ Str_Array[Str_Bit] = Num_Array[Num_Bit -1];
|
|
|
+ Str_Bit ++;
|
|
|
+ Num_Bit --;
|
|
|
+ }
|
|
|
+
|
|
|
+ //show
|
|
|
+ GUI_DisString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground );
|
|
|
+}
|
|
|
+
|
|
|
+void Driver::GUI_Show(std::string bat)
|
|
|
+{
|
|
|
+ printf("OLED Clear \r\n");
|
|
|
+ OLED_Clear(OLED_BACKGROUND);//OLED_BACKGROUND
|
|
|
+ OLED_Display();
|
|
|
+
|
|
|
+ FILE *fp;
|
|
|
+ char buffer[14];
|
|
|
+ fp = popen("hostname -I | cut -d\' \' -f1", "r");
|
|
|
+ fgets(buffer, sizeof(buffer), fp);
|
|
|
+ if(buffer[0] == '\n')
|
|
|
+ {
|
|
|
+ strcpy(buffer, "No IP");
|
|
|
+ }
|
|
|
+ GUI_DisString_EN(0, 20, char_ip, &Font12, FONT_BACKGROUND, WHITE);
|
|
|
+ GUI_DisString_EN(20, 20, buffer, &Font12, FONT_BACKGROUND, WHITE);
|
|
|
+ GUI_DisString_EN(0, 40, char_bat, &Font12, FONT_BACKGROUND, WHITE);
|
|
|
+ GUI_DisString_EN(28, 40, bat.c_str(), &Font12, FONT_BACKGROUND, WHITE);
|
|
|
+ OLED_Display();
|
|
|
+ usleep(2000);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|