Browse Source

增加显示ip和电量的程序

corvin rasp melodic 2 years ago
parent
commit
19b8321d9f

+ 2 - 0
.gitignore

@@ -3,3 +3,5 @@ devel/
 *.pyc
 *.so
 .vscode/
+src/dual_iic/build/
+src/dual_iic/.vscode/

+ 0 - 1
src/CMakeLists.txt

@@ -1 +0,0 @@
-/opt/ros/melodic/share/catkin/cmake/toplevel.cmake

+ 69 - 0
src/CMakeLists.txt

@@ -0,0 +1,69 @@
+# toplevel CMakeLists.txt for a catkin workspace
+# catkin/cmake/toplevel.cmake
+
+cmake_minimum_required(VERSION 3.0.2)
+
+project(Project)
+
+set(CATKIN_TOPLEVEL TRUE)
+
+# search for catkin within the workspace
+set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
+execute_process(COMMAND ${_cmd}
+  RESULT_VARIABLE _res
+  OUTPUT_VARIABLE _out
+  ERROR_VARIABLE _err
+  OUTPUT_STRIP_TRAILING_WHITESPACE
+  ERROR_STRIP_TRAILING_WHITESPACE
+)
+if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
+  # searching fot catkin resulted in an error
+  string(REPLACE ";" " " _cmd_str "${_cmd}")
+  message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
+endif()
+
+# include catkin from workspace or via find_package()
+if(_res EQUAL 0)
+  set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
+  # include all.cmake without add_subdirectory to let it operate in same scope
+  include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
+  add_subdirectory("${_out}")
+
+else()
+  # use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
+  # or CMAKE_PREFIX_PATH from the environment
+  if(NOT DEFINED CMAKE_PREFIX_PATH)
+    if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
+      if(NOT WIN32)
+        string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
+      else()
+        set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
+      endif()
+    endif()
+  endif()
+
+  # list of catkin workspaces
+  set(catkin_search_path "")
+  foreach(path ${CMAKE_PREFIX_PATH})
+    if(EXISTS "${path}/.catkin")
+      list(FIND catkin_search_path ${path} _index)
+      if(_index EQUAL -1)
+        list(APPEND catkin_search_path ${path})
+      endif()
+    endif()
+  endforeach()
+
+  # search for catkin in all workspaces
+  set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
+  find_package(catkin QUIET
+    NO_POLICY_SCOPE
+    PATHS ${catkin_search_path}
+    NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+  unset(CATKIN_TOPLEVEL_FIND_PACKAGE)
+
+  if(NOT catkin_FOUND)
+    message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
+  endif()
+endif()
+
+catkin_workspace()

+ 13 - 0
src/dual_iic/CMakeLists.txt

@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.0.2)
+project(dual_iic)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+
+find_package(Threads REQUIRED)
+
+include_directories(
+  include 
+)
+
+add_executable(dual_iic src/main.cpp src/device.cpp src/driver.cpp)
+target_link_libraries(dual_iic -lbcm2835 -lm Threads::Threads)

+ 2 - 0
src/dual_iic/README.md

@@ -0,0 +1,2 @@
+# dual_iic
+

+ 58 - 0
src/dual_iic/include/device.h

@@ -0,0 +1,58 @@
+/*
+ * @Copyright(C): 2016-2021 ROS小课堂 www.corvin.cn
+ * @Author: adam_zhuo
+ * @Date: 2022-07-08 10:58:18
+ * @Description: file content
+ * @History: 20210429:-adam_zhuo
+ */
+#ifndef _DEVICE_H_
+#define _DEVICE_H_
+
+#include <bcm2835.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#define IIC_CMD        0X00
+#define IIC_RAM        0X40
+
+#define UBYTE   uint8_t
+#define UWORD   uint16_t
+#define UDOUBLE uint32_t
+
+// #define OLED_CS         8
+// #define OLED_RST        25
+// #define OLED_DC         24
+
+// #define OLED_CS_0      DEV_Digital_Write(OLED_CS,0)
+// #define OLED_CS_1      DEV_Digital_Write(OLED_CS,1)
+
+// #define OLED_RST_0      DEV_Digital_Write(OLED_RST,0)
+// #define OLED_RST_1      DEV_Digital_Write(OLED_RST,1)
+// #define OLED_RST_RD     DEV_Digital_Read(OLED_RST)
+
+// #define OLED_DC_0       DEV_Digital_Write(OLED_DC,0)
+// #define OLED_DC_1       DEV_Digital_Write(OLED_DC,1)
+
+class Device
+{
+    private:
+        uint8_t addr;
+
+    public:
+        Device(uint8_t a):addr(a){} 
+        static uint8_t DEV_ModuleInit(void);
+        static void    DEV_ModuleExit(void);
+        // void    DEV_GPIO_Init();
+        void    I2C_Write_Byte(uint8_t value, uint8_t Cmd);
+        int     I2C_Read_Battery(void);
+        // void    DEV_GPIO_Mode(UWORD Pin, UWORD Mode);
+        // void    DEV_Digital_Write(UWORD Pin, UBYTE Value);
+        // UBYTE   DEV_Digital_Read(UWORD Pin);
+        void    DEV_Delay_ms(UDOUBLE xms);
+        void    DEV_Set_Slave(void);
+};
+
+#endif

+ 110 - 0
src/dual_iic/include/driver.h

@@ -0,0 +1,110 @@
+#ifndef _DRIVER_H_
+#define _DRIVER_H_
+#include "device.h"
+#include "fonts.h"
+#include <string>
+
+#define	COLOR				uint16_t		 
+#define	POINT				uint16_t		
+#define	LENGTH				uint16_t		
+#define OLED_X_MAXPIXEL  132  //OLED width maximum memory 
+#define OLED_Y_MAXPIXEL  64 //OLED height maximum memory
+#define OLED_X	 2
+#define OLED_Y	 0
+
+#define OLED_WIDTH  (OLED_X_MAXPIXEL - 2 * OLED_X)  //OLED width
+#define OLED_HEIGHT  OLED_Y_MAXPIXEL //OLED height
+
+typedef enum{
+	L2R_U2D  = 0,	//The display interface is displayed , left to right, up to down 
+	L2R_D2U  ,
+	R2L_U2D  ,
+	R2L_D2U  ,
+	
+	U2D_L2R  ,
+	U2D_R2L  ,
+	D2U_L2R  ,
+	D2U_R2L  , 
+}OLED_SCAN_DIR;
+
+#define SCAN_DIR_DFT  L2R_U2D  //Default scan direction = L2R_U2D
+typedef struct{
+	LENGTH OLED_Dis_Column;	//COLUMN
+	LENGTH OLED_Dis_Page;	//PAGE
+	OLED_SCAN_DIR OLED_Scan_Dir;
+	POINT OLED_X_Adjust;		//OLED x actual display position calibration
+	POINT OLED_Y_Adjust;		//OLED y actual display position calibration
+}OLED_DIS;
+
+typedef enum{
+	DOT_PIXEL_1X1  = 1,		// dot pixel 1 x 1
+	DOT_PIXEL_2X2  , 		// dot pixel 2 X 2 
+	DOT_PIXEL_3X3  ,		// dot pixel 3 X 3
+	DOT_PIXEL_4X4  ,		// dot pixel 4 X 4
+	DOT_PIXEL_5X5  , 		// dot pixel 5 X 5
+	DOT_PIXEL_6X6  , 		// dot pixel 6 X 6
+	DOT_PIXEL_7X7  , 		// dot pixel 7 X 7
+	DOT_PIXEL_8X8  , 		// dot pixel 8 X 8
+}DOT_PIXEL;
+#define DOT_PIXEL_DFT  DOT_PIXEL_1X1  //Default dot pilex
+
+typedef enum{
+	DOT_FILL_AROUND  = 1,		// dot pixel 1 x 1
+	DOT_FILL_RIGHTUP  , 		// dot pixel 2 X 2 
+}DOT_STYLE;
+#define DOT_STYLE_DFT  DOT_FILL_AROUND  //Default dot pilex
+
+typedef enum{
+	LINE_SOLID = 0,
+	LINE_DOTTED,
+}LINE_STYLE;
+
+typedef enum{
+	DRAW_EMPTY = 0,
+	DRAW_FULL,
+}DRAW_FILL;
+
+#define OLED_BACKGROUND		BLACK   //Default background color
+#define FONT_BACKGROUND		BLACK   //Default font background color
+#define FONT_FOREGROUND	    WHITE    //Default font foreground color
+
+#define WHITE          0xFF
+#define BLACK          0x00 
+#define ARRAY_LEN 255
+
+class Driver
+{
+    private:
+        Device oled_dev;
+        OLED_DIS sOLED_DIS;
+        char Buffer[OLED_WIDTH *OLED_HEIGHT /8];
+		char char_bat[10] = "BAT: ";
+		char char_ip[10] = "IP: ";
+		char char_percent[2] = "%";
+    public:
+        Driver(Device dev):oled_dev(dev){}
+        void OLED_InitReg(void);
+        void OLED_Init(OLED_SCAN_DIR OLED_ScanDir);
+        void OLED_SetGramScanWay(OLED_SCAN_DIR Scan_dir);
+        void OLED_WriteData_nLen8Bit(uint8_t *pBuf, uint32_t Len);
+        void OLED_WriteReg(uint8_t Reg);
+
+        //OLED set cursor + windows + color
+        void OLED_SetCursor(POINT Xpoint, POINT Ypoint);
+        void OLED_SetColor(POINT Xpoint, POINT Ypoint, COLOR Color);
+        void OLED_Clear(COLOR  Color);
+        void OLED_Display(void);
+
+        //Drawing
+        void GUI_DrawPoint(POINT Xpoint, POINT Ypoint, COLOR Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_FillWay);
+        //Display string
+        void GUI_DisChar(POINT Xpoint, POINT Ypoint, const char Acsii_Char, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground);
+        void GUI_DisString_EN(POINT Xstart, POINT Ystart, const char * pString, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground );
+        void GUI_DisNum(POINT Xpoint, POINT Ypoint, int32_t Nummber, sFONT* Font, COLOR Color_Background, COLOR Color_Foreground );
+
+        void GUI_Show(std::string bat);
+
+};
+
+
+#endif

+ 1358 - 0
src/dual_iic/include/fonts.h

@@ -0,0 +1,1358 @@
+
+#ifndef __FONTS_H
+#define __FONTS_H
+
+/* Max size of bitmap will based on a font24 (17x24) */
+#define MAX_HEIGHT_FONT         24
+#define MAX_WIDTH_FONT          17
+#define OFFSET_BITMAP           54
+
+
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdint.h>
+
+typedef struct _tFont
+{    
+  const uint8_t *table;
+  uint16_t Width;
+  uint16_t Height;
+  
+} sFONT;
+
+const uint8_t Font12_Table[] = 
+{
+	// @0 ' ' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @12 '!' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @24 '"' (7 pixels wide)
+	0x00, //        
+	0x6C, //  ## ## 
+	0x48, //  #  #  
+	0x48, //  #  #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @36 '#' (7 pixels wide)
+	0x00, //        
+	0x14, //    # # 
+	0x14, //    # # 
+	0x28, //   # #  
+	0x7C, //  ##### 
+	0x28, //   # #  
+	0x7C, //  ##### 
+	0x28, //   # #  
+	0x50, //  # #   
+	0x50, //  # #   
+	0x00, //        
+	0x00, //        
+
+	// @48 '$' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x38, //   ###  
+	0x40, //  #     
+	0x40, //  #     
+	0x38, //   ###  
+	0x48, //  #  #  
+	0x70, //  ###   
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+
+	// @60 '%' (7 pixels wide)
+	0x00, //        
+	0x20, //   #    
+	0x50, //  # #   
+	0x20, //   #    
+	0x0C, //     ## 
+	0x70, //  ###   
+	0x08, //     #  
+	0x14, //    # # 
+	0x08, //     #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @72 '&' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x18, //    ##  
+	0x20, //   #    
+	0x20, //   #    
+	0x54, //  # # # 
+	0x48, //  #  #  
+	0x34, //   ## # 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @84 ''' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @96 '(' (7 pixels wide)
+	0x00, //        
+	0x08, //     #  
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x08, //     #  
+	0x08, //     #  
+	0x00, //        
+
+	// @108 ')' (7 pixels wide)
+	0x00, //        
+	0x20, //   #    
+	0x20, //   #    
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x20, //   #    
+	0x20, //   #    
+	0x00, //        
+
+	// @120 '*' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x7C, //  ##### 
+	0x10, //    #   
+	0x28, //   # #  
+	0x28, //   # #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @132 '+' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0xFE, // #######
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @144 ',' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x18, //    ##  
+	0x10, //    #   
+	0x30, //   ##   
+	0x20, //   #    
+	0x00, //        
+
+	// @156 '-' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @168 '.' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x30, //   ##   
+	0x30, //   ##   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @180 '/' (7 pixels wide)
+	0x00, //        
+	0x04, //      # 
+	0x04, //      # 
+	0x08, //     #  
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x20, //   #    
+	0x20, //   #    
+	0x40, //  #     
+	0x00, //        
+	0x00, //        
+
+	// @192 '0' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @204 '1' (7 pixels wide)
+	0x00, //        
+	0x30, //   ##   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @216 '2' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x04, //      # 
+	0x08, //     #  
+	0x10, //    #   
+	0x20, //   #    
+	0x44, //  #   # 
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @228 '3' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x04, //      # 
+	0x18, //    ##  
+	0x04, //      # 
+	0x04, //      # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @240 '4' (7 pixels wide)
+	0x00, //        
+	0x0C, //     ## 
+	0x14, //    # # 
+	0x14, //    # # 
+	0x24, //   #  # 
+	0x44, //  #   # 
+	0x7E, //  ######
+	0x04, //      # 
+	0x0E, //     ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @252 '5' (7 pixels wide)
+	0x00, //        
+	0x3C, //   #### 
+	0x20, //   #    
+	0x20, //   #    
+	0x38, //   ###  
+	0x04, //      # 
+	0x04, //      # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @264 '6' (7 pixels wide)
+	0x00, //        
+	0x1C, //    ### 
+	0x20, //   #    
+	0x40, //  #     
+	0x78, //  ####  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @276 '7' (7 pixels wide)
+	0x00, //        
+	0x7C, //  ##### 
+	0x44, //  #   # 
+	0x04, //      # 
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @288 '8' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @300 '9' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x3C, //   #### 
+	0x04, //      # 
+	0x08, //     #  
+	0x70, //  ###   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @312 ':' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x30, //   ##   
+	0x30, //   ##   
+	0x00, //        
+	0x00, //        
+	0x30, //   ##   
+	0x30, //   ##   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @324 ';' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x18, //    ##  
+	0x18, //    ##  
+	0x00, //        
+	0x00, //        
+	0x18, //    ##  
+	0x30, //   ##   
+	0x20, //   #    
+	0x00, //        
+	0x00, //        
+
+	// @336 '<' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x0C, //     ## 
+	0x10, //    #   
+	0x60, //  ##    
+	0x80, // #      
+	0x60, //  ##    
+	0x10, //    #   
+	0x0C, //     ## 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @348 '=' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x7C, //  ##### 
+	0x00, //        
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @360 '>' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0xC0, // ##     
+	0x20, //   #    
+	0x18, //    ##  
+	0x04, //      # 
+	0x18, //    ##  
+	0x20, //   #    
+	0xC0, // ##     
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @372 '?' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x18, //    ##  
+	0x24, //   #  # 
+	0x04, //      # 
+	0x08, //     #  
+	0x10, //    #   
+	0x00, //        
+	0x30, //   ##   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @384 '@' (7 pixels wide)
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x4C, //  #  ## 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x4C, //  #  ## 
+	0x40, //  #     
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+
+	// @396 'A' (7 pixels wide)
+	0x00, //        
+	0x30, //   ##   
+	0x10, //    #   
+	0x28, //   # #  
+	0x28, //   # #  
+	0x28, //   # #  
+	0x7C, //  ##### 
+	0x44, //  #   # 
+	0xEE, // ### ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @408 'B' (7 pixels wide)
+	0x00, //        
+	0xF8, // #####  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x78, //  ####  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xF8, // #####  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @420 'C' (7 pixels wide)
+	0x00, //        
+	0x3C, //   #### 
+	0x44, //  #   # 
+	0x40, //  #     
+	0x40, //  #     
+	0x40, //  #     
+	0x40, //  #     
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @432 'D' (7 pixels wide)
+	0x00, //        
+	0xF0, // ####   
+	0x48, //  #  #  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x48, //  #  #  
+	0xF0, // ####   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @444 'E' (7 pixels wide)
+	0x00, //        
+	0xFC, // ###### 
+	0x44, //  #   # 
+	0x50, //  # #   
+	0x70, //  ###   
+	0x50, //  # #   
+	0x40, //  #     
+	0x44, //  #   # 
+	0xFC, // ###### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @456 'F' (7 pixels wide)
+	0x00, //        
+	0x7E, //  ######
+	0x22, //   #   #
+	0x28, //   # #  
+	0x38, //   ###  
+	0x28, //   # #  
+	0x20, //   #    
+	0x20, //   #    
+	0x70, //  ###   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @468 'G' (7 pixels wide)
+	0x00, //        
+	0x3C, //   #### 
+	0x44, //  #   # 
+	0x40, //  #     
+	0x40, //  #     
+	0x4E, //  #  ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @480 'H' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x7C, //  ##### 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xEE, // ### ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @492 'I' (7 pixels wide)
+	0x00, //        
+	0x7C, //  ##### 
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @504 'J' (7 pixels wide)
+	0x00, //        
+	0x3C, //   #### 
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x48, //  #  #  
+	0x48, //  #  #  
+	0x48, //  #  #  
+	0x30, //   ##   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @516 'K' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x48, //  #  #  
+	0x50, //  # #   
+	0x70, //  ###   
+	0x48, //  #  #  
+	0x44, //  #   # 
+	0xE6, // ###  ##
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @528 'L' (7 pixels wide)
+	0x00, //        
+	0x70, //  ###   
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x24, //   #  # 
+	0x24, //   #  # 
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @540 'M' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x6C, //  ## ## 
+	0x6C, //  ## ## 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xEE, // ### ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @552 'N' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x64, //  ##  # 
+	0x64, //  ##  # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x4C, //  #  ## 
+	0xEC, // ### ## 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @564 'O' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @576 'P' (7 pixels wide)
+	0x00, //        
+	0x78, //  ####  
+	0x24, //   #  # 
+	0x24, //   #  # 
+	0x24, //   #  # 
+	0x38, //   ###  
+	0x20, //   #    
+	0x20, //   #    
+	0x70, //  ###   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @588 'Q' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x1C, //    ### 
+	0x00, //        
+	0x00, //        
+
+	// @600 'R' (7 pixels wide)
+	0x00, //        
+	0xF8, // #####  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x78, //  ####  
+	0x48, //  #  #  
+	0x44, //  #   # 
+	0xE2, // ###   #
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @612 'S' (7 pixels wide)
+	0x00, //        
+	0x34, //   ## # 
+	0x4C, //  #  ## 
+	0x40, //  #     
+	0x38, //   ###  
+	0x04, //      # 
+	0x04, //      # 
+	0x64, //  ##  # 
+	0x58, //  # ##  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @624 'T' (7 pixels wide)
+	0x00, //        
+	0xFE, // #######
+	0x92, // #  #  #
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @636 'U' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @648 'V' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x28, //   # #  
+	0x28, //   # #  
+	0x28, //   # #  
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @660 'W' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x28, //   # #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @672 'X' (7 pixels wide)
+	0x00, //        
+	0xC6, // ##   ##
+	0x44, //  #   # 
+	0x28, //   # #  
+	0x10, //    #   
+	0x10, //    #   
+	0x28, //   # #  
+	0x44, //  #   # 
+	0xC6, // ##   ##
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @684 'Y' (7 pixels wide)
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x28, //   # #  
+	0x28, //   # #  
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @696 'Z' (7 pixels wide)
+	0x00, //        
+	0x7C, //  ##### 
+	0x44, //  #   # 
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x20, //   #    
+	0x44, //  #   # 
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @708 '[' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x38, //   ###  
+	0x00, //        
+
+	// @720 '\' (7 pixels wide)
+	0x00, //        
+	0x40, //  #     
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x10, //    #   
+	0x10, //    #   
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x00, //        
+	0x00, //        
+
+	// @732 ']' (7 pixels wide)
+	0x00, //        
+	0x38, //   ###  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x38, //   ###  
+	0x00, //        
+
+	// @744 '^' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x10, //    #   
+	0x28, //   # #  
+	0x44, //  #   # 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @756 '_' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xFE, // #######
+
+	// @768 '`' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x08, //     #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @780 'a' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x3C, //   #### 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x3E, //   #####
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @792 'b' (7 pixels wide)
+	0x00, //        
+	0xC0, // ##     
+	0x40, //  #     
+	0x58, //  # ##  
+	0x64, //  ##  # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xF8, // #####  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @804 'c' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x3C, //   #### 
+	0x44, //  #   # 
+	0x40, //  #     
+	0x40, //  #     
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @816 'd' (7 pixels wide)
+	0x00, //        
+	0x0C, //     ## 
+	0x04, //      # 
+	0x34, //   ## # 
+	0x4C, //  #  ## 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x3E, //   #####
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @828 'e' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x7C, //  ##### 
+	0x40, //  #     
+	0x40, //  #     
+	0x3C, //   #### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @840 'f' (7 pixels wide)
+	0x00, //        
+	0x1C, //    ### 
+	0x20, //   #    
+	0x7C, //  ##### 
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @852 'g' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x36, //   ## ##
+	0x4C, //  #  ## 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x3C, //   #### 
+	0x04, //      # 
+	0x38, //   ###  
+	0x00, //        
+
+	// @864 'h' (7 pixels wide)
+	0x00, //        
+	0xC0, // ##     
+	0x40, //  #     
+	0x58, //  # ##  
+	0x64, //  ##  # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xEE, // ### ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @876 'i' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x00, //        
+	0x70, //  ###   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @888 'j' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x00, //        
+	0x78, //  ####  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x08, //     #  
+	0x70, //  ###   
+	0x00, //        
+
+	// @900 'k' (7 pixels wide)
+	0x00, //        
+	0xC0, // ##     
+	0x40, //  #     
+	0x5C, //  # ### 
+	0x48, //  #  #  
+	0x70, //  ###   
+	0x50, //  # #   
+	0x48, //  #  #  
+	0xDC, // ## ### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @912 'l' (7 pixels wide)
+	0x00, //        
+	0x30, //   ##   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @924 'm' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xE8, // ### #  
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0xFE, // #######
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @936 'n' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xD8, // ## ##  
+	0x64, //  ##  # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0xEE, // ### ###
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @948 'o' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x38, //   ###  
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @960 'p' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xD8, // ## ##  
+	0x64, //  ##  # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x78, //  ####  
+	0x40, //  #     
+	0xE0, // ###    
+	0x00, //        
+
+	// @972 'q' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x36, //   ## ##
+	0x4C, //  #  ## 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x3C, //   #### 
+	0x04, //      # 
+	0x0E, //     ###
+	0x00, //        
+
+	// @984 'r' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x6C, //  ## ## 
+	0x30, //   ##   
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @996 's' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x3C, //   #### 
+	0x44, //  #   # 
+	0x38, //   ###  
+	0x04, //      # 
+	0x44, //  #   # 
+	0x78, //  ####  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1008 't' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x20, //   #    
+	0x7C, //  ##### 
+	0x20, //   #    
+	0x20, //   #    
+	0x20, //   #    
+	0x22, //   #   #
+	0x1C, //    ### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1020 'u' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xCC, // ##  ## 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x4C, //  #  ## 
+	0x36, //   ## ##
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1032 'v' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x44, //  #   # 
+	0x28, //   # #  
+	0x28, //   # #  
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1044 'w' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x54, //  # # # 
+	0x28, //   # #  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1056 'x' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xCC, // ##  ## 
+	0x48, //  #  #  
+	0x30, //   ##   
+	0x30, //   ##   
+	0x48, //  #  #  
+	0xCC, // ##  ## 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1068 'y' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0xEE, // ### ###
+	0x44, //  #   # 
+	0x24, //   #  # 
+	0x28, //   # #  
+	0x18, //    ##  
+	0x10, //    #   
+	0x10, //    #   
+	0x78, //  ####  
+	0x00, //        
+
+	// @1080 'z' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x7C, //  ##### 
+	0x48, //  #  #  
+	0x10, //    #   
+	0x20, //   #    
+	0x44, //  #   # 
+	0x7C, //  ##### 
+	0x00, //        
+	0x00, //        
+	0x00, //        
+
+	// @1092 '{' (7 pixels wide)
+	0x00, //        
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x20, //   #    
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x08, //     #  
+	0x00, //        
+
+	// @1104 '|' (7 pixels wide)
+	0x00, //        
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x00, //        
+	0x00, //        
+
+	// @1116 '}' (7 pixels wide)
+	0x00, //        
+	0x20, //   #    
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x08, //     #  
+	0x10, //    #   
+	0x10, //    #   
+	0x10, //    #   
+	0x20, //   #    
+	0x00, //        
+
+	// @1128 '~' (7 pixels wide)
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x24, //   #  # 
+	0x58, //  # ##  
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+	0x00, //        
+};
+
+#endif /* __FONTS_H */
+ 
+

+ 10 - 0
src/dual_iic/oled_self_startup.service

@@ -0,0 +1,10 @@
+[Unit]
+Description=just for oled_startup
+
+[Service]
+Type=simple
+ExecStart=/home/corvin/ros_minibot_ws/src/dual_iic/build/dual_iic 
+Restart=1
+
+[Install]
+WantedBy=multi-user.target

+ 82 - 0
src/dual_iic/src/device.cpp

@@ -0,0 +1,82 @@
+/*
+ * @Copyright(C): 2016-2021 ROS小课堂 www.corvin.cn
+ * @Author: adam_zhuo
+ * @Date: 2022-07-08 11:14:17
+ * @Description: file content
+ * @History: 20210429:-adam_zhuo
+ */
+#include "device.h"
+#include <fstream>
+#include <iostream>
+
+uint8_t Device::DEV_ModuleInit(void)
+{
+    if(!bcm2835_init()) {
+        printf("bcm2835 init failed  !!! \r\n");
+        return 1;
+    } else {
+        printf("bcm2835 init success !!! \r\n");
+    }
+    printf("USE_IIC\r\n");
+    bcm2835_i2c_begin();
+    // bcm2835_i2c_setSlaveAddress(addr);
+}
+
+void Device::DEV_Set_Slave(void)
+{
+    bcm2835_i2c_setSlaveAddress(addr);
+}
+
+void Device::I2C_Write_Byte(uint8_t value, uint8_t Cmd)
+{
+    char wbuf[2]={Cmd, value};
+    bcm2835_i2c_write(wbuf, 2);
+}
+
+int Device::I2C_Read_Battery(void)
+{
+    // char wbuf[2] = {0x67, 0x0D};
+    // char buf[8]={0};
+    // bcm2835_i2c_write(wbuf, 2);
+    // usleep(30000);
+    // bcm2835_i2c_read(buf, 4);
+    // printf("buffer is %d\n", atoi(buf));
+    // return atoi(buf); 
+    std::ifstream fin;
+    int bat;
+    fin.open("/home/corvin/.bat");
+    if(!fin.is_open())
+    {
+        std::ofstream fout("/home/corvin/.bat", std::ios::out);
+        bat = 50;
+        fout << bat;
+        fout.close();
+    }else
+    {
+        fin >> bat;
+    }
+    return bat;
+}
+
+void Device::DEV_ModuleExit(void)
+{
+    bcm2835_close();
+    bcm2835_i2c_end();
+}
+
+void Device::DEV_Delay_ms(UDOUBLE xms)
+{
+    bcm2835_delay(xms);
+}
+
+// void Device::DEV_Digital_Write(UWORD Pin, UBYTE Value)
+// {
+//     bcm2835_gpio_write(Pin, Value);
+// }
+
+// UBYTE Device::DEV_Digital_Read(UWORD Pin)
+// {
+//     UBYTE Read_value = 0;
+//     Read_value = bcm2835_gpio_lev(Pin);
+//     return Read_value;
+// }

+ 275 - 0
src/dual_iic/src/driver.cpp

@@ -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);	
+}
+
+
+
+

+ 41 - 0
src/dual_iic/src/main.cpp

@@ -0,0 +1,41 @@
+/*
+ * @Copyright(C): 2016-2021 ROS小课堂 www.corvin.cn
+ * @Author: adam_zhuo
+ * @Date: 2022-07-08 11:29:12
+ * @Description: file content
+ * @History: 20210429:-adam_zhuo
+ */
+#include <thread>
+
+#include <stdio.h>		//printf()
+#include <stdlib.h>		//exit()
+#include "driver.h"
+
+int main()
+{
+   
+    Device oled_dev(0x3c);
+    Device battery_dev(0x08);
+    Driver oled_driver(oled_dev);
+    // 1.init
+    Device::DEV_ModuleInit();
+    oled_dev.DEV_Set_Slave();
+    // 2.show
+	printf("**********Init OLED**********\r\n");
+	OLED_SCAN_DIR OLED_ScanDir = SCAN_DIR_DFT;//SCAN_DIR_DFT = D2U_L2R
+	oled_driver.OLED_Init(OLED_ScanDir);
+
+    printf("OLED Show \r\n");
+
+    while(1)
+	{
+        // int battery = battery_dev.I2C_Read_Battery();
+        std::string bat_percent = std::to_string(battery_dev.I2C_Read_Battery()) + "%";
+        oled_driver.GUI_Show(bat_percent);
+		sleep(60);
+	}
+    //3.System Exit
+	Device::DEV_ModuleExit();
+    
+	return 0;
+}

+ 11 - 7
src/robot_bringup/CMakeLists.txt

@@ -7,7 +7,11 @@ project(robot_bringup)
 ## Find catkin macros and libraries
 ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
 ## is used, also find other catkin packages
-find_package(catkin REQUIRED)
+find_package(catkin REQUIRED
+  roscpp
+  ros_arduino_msgs
+  std_msgs
+)
 
 ## System dependencies are found with CMake's conventions
 # find_package(Boost REQUIRED COMPONENTS system)
@@ -36,7 +40,7 @@ catkin_package(
 ## Your package locations should be listed before other locations
 include_directories(
 # include
-# ${catkin_INCLUDE_DIRS}
+  ${catkin_INCLUDE_DIRS}
 )
 
 ## Declare a C++ library
@@ -52,7 +56,7 @@ include_directories(
 ## Declare a C++ executable
 ## With catkin_make all packages are built within a single CMake context
 ## The recommended prefix ensures that target names across packages don't collide
-# add_executable(${PROJECT_NAME}_node src/robot_bringup_node.cpp)
+add_executable(get_battery_node src/get_battery.cpp)
 
 ## Rename C++ executable without prefix
 ## The above recommended prefix causes long target names, the following renames the
@@ -62,12 +66,12 @@ include_directories(
 
 ## Add cmake target dependencies of the executable
 ## same as for the library above
-# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
+add_dependencies(get_battery_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
 
 ## Specify libraries to link a library or executable target against
-# target_link_libraries(${PROJECT_NAME}_node
-#   ${catkin_LIBRARIES}
-# )
+target_link_libraries(get_battery_node
+  ${catkin_LIBRARIES}
+)
 
 #############
 ## Install ##

+ 4 - 0
src/robot_bringup/launch/get_battery.launch

@@ -0,0 +1,4 @@
+<launch>
+    <node pkg="robot_bringup" type="get_battery_node" name="get_battery_node" output="screen">
+    </node>
+</launch>

+ 3 - 0
src/robot_bringup/launch/robot_bringup.launch

@@ -38,5 +38,8 @@
         <remap from="input" to="/robot_pose_ekf/odom_combined" />
         <remap from="output" to="/odom_ekf" />
     </node>
+
+    <!-- (7) startup get battery-->
+    <include file="$(find robot_bringup)/launch/get_battery.launch" />
 </launch>
 

+ 6 - 0
src/robot_bringup/package.xml

@@ -14,6 +14,12 @@
   <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
   <license>TODO</license>
   <buildtool_depend>catkin</buildtool_depend>
+  <build_depend>ros_arduino_msgs</build_depend>
+  <build_depend>roscpp</build_depend>
+  <build_export_depend>ros_arduino_msgs</build_export_depend>
+  <build_export_depend>roscpp</build_export_depend>
+  <exec_depend>ros_arduino_msgs</exec_depend>
+  <exec_depend>roscpp</exec_depend>
   <!-- The export tag contains other, unspecified, tags -->
   <export>
     <!-- Other tools can request additional information be placed here -->

+ 27 - 0
src/robot_bringup/src/get_battery.cpp

@@ -0,0 +1,27 @@
+/*
+ * @Author: adam_zhuo
+ * @Date: 2022-07-09 14:10:00
+ * @Description: Init this file.
+ * @History: 20210429:-adam_zhuo
+ */
+#include <ros/ros.h>
+#include "ros_arduino_msgs/Digital.h"
+#include <fstream>
+#include <iostream>
+
+void battery_callback(const ros_arduino_msgs::Digital::ConstPtr& msg)
+{
+    std::ofstream bat_file;
+    bat_file.open("/home/corvin/.bat", std::ios::out);
+    bat_file << int(msg->value);
+    bat_file.close();
+}
+
+int main(int argc, char **argv)
+{
+    ros::init(argc, argv, "get_battery_node");
+    ros::NodeHandle handle;
+    ros::Subscriber sub_battey = handle.subscribe("/mobilebase_arduino/sensor/batPercent", 1, battery_callback);
+    ros::spin();
+    return 0;
+}

+ 5 - 0
update_code.sh

@@ -24,6 +24,11 @@ echo -e "\n"
 sleep 3
 echo -e "${green}>>> 2: 开始编译代码${normal}"
 catkin_make
+
+cd src/dual_iic/build
+make
+cd ../..
+
 if [ $? -eq 0 ];then
     echo -e "${green}编译代码完成,现在可以启动代码...${normal}"
 else