Skip to content

Commit 386f206

Browse files
committed
dispsrv: added runtime auto detection of sdd1306 or other i2c based displays
1 parent 0711a83 commit 386f206

File tree

8 files changed

+284
-29
lines changed

8 files changed

+284
-29
lines changed

sources/lib/lib-adav-old/include/ADSysInfo.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ class ADSysInfo
2424
int get_mem_and_free_mem(int *mem_kb,int *mem_free_kb);
2525
int get_uptime(int* uptime);
2626
int get_cpu_model_name(char* model);
27-
int probe_eth_interface_details(int *total_detected, eth_name_ip_str *list);
2827
int get_cpu_frequency(char* freq);
2928
public:
3029
ADSysInfo();
3130
~ADSysInfo();
3231
int read_system_status(int *mem,int* memfree,int *cores,int* cur_load,int* avg_load,int* uptime,char* cpu_model);
3332
int read_network_info(char* eth,char *mac,char* ip,char* netmask);
3433
int read_network_info_ifconfig(char* eth,char* mac,char* ip,char* netmask);
35-
34+
int probe_eth_interface_details(int *total_detected, eth_name_ip_str *list);
3635
int read_mem_info(char* mem,char *memfree,char* memused);
3736
int read_load_info(char* curload,char* avgload,char* uptime);
3837
int read_cpu_info(char* cpumodel,char *cores,char* cpufreq);

sources/lib/lib-adav-old/include/I2CBusAccess.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace std;
1212
#define I2C_SMBUS_WRITE 0
1313
#define I2C_SMBUS_QUICK 0
1414
#define I2C_SMBUS_BYTE 1
15-
#define I2C_SMBUS_BYTE_DATA 2
15+
#define I2C_SMBUS_BYTE_DATA 2
1616
#define I2C_SMBUS_WORD_DATA 3
1717
#define I2C_SMBUS_PROC_CALL 4
1818
#define I2C_SMBUS_BLOCK_DATA 5
@@ -42,9 +42,9 @@ do \
4242
return(-1);\
4343
}\
4444
} while (0)*/
45-
#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
45+
#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
4646
#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
47-
union i2c_smbus_data
47+
union i2c_smbus_data
4848
{
4949
uint8_t byte;
5050
uint16_t word;
@@ -65,7 +65,6 @@ class I2CBusAccess
6565
bool is_number(const std::string& s);
6666
bool validateIpAddress(const string &ipAddress);
6767
RPC_SRV_RESULT is_it_network_node(std::string devnode,int &port,std::string &ip);
68-
RPC_SRV_RESULT is_it_device_node(std::string devnode);
6968
int32_t i2c_smbus_access(int file, char read_write, uint8_t command,int size, union i2c_smbus_data *data);
7069
int32_t i2c_smbus_read_byte(int file);
7170
int32_t i2c_smbus_write_byte(int file,uint8_t value);
@@ -82,5 +81,6 @@ class I2CBusAccess
8281
RPC_SRV_RESULT write_dword(uint32_t addr, uint32_t data);
8382
RPC_SRV_RESULT write_array(uint32_t addr, uint8_t *data,uint32_t len);
8483
RPC_SRV_RESULT read_array(uint32_t addr, uint8_t *data,uint32_t len);
84+
RPC_SRV_RESULT is_it_device_node(std::string devnode);
8585
};
8686
#endif

sources/lib/lib-adav-old/src/I2CBusAccess.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <iostream>
1717
#include <vector>
1818
#include <arpa/inet.h>
19-
#include <stdlib.h>
19+
#include <stdlib.h>
2020
//#include "i2cbusses.h"
2121
//#include <linux/i2c.h>
2222
#include <linux/i2c-dev.h>
@@ -83,7 +83,7 @@ RPC_SRV_RESULT I2CBusAccess::is_it_network_node(std::string devnode,int &port,st
8383
istringstream f(devnode);//"192.168.1.1,40001");
8484
string s,str1,str2;
8585
ip="none";
86-
port=-1;
86+
port=-1;
8787

8888
while (getline(f, s, ':'))
8989
{
@@ -140,7 +140,7 @@ RPC_SRV_RESULT I2CBusAccess::is_it_device_node(std::string devnode)
140140
/*****************************************************************************/
141141
RPC_SRV_RESULT I2CBusAccess::SetSlaveAddr(uint8_t addr)
142142
{
143-
if (ioctl(fd, I2C_SLAVE, addr) < 0)
143+
if (ioctl(fd, I2C_SLAVE, addr) < 0)
144144
{
145145
//cout<<"I2CBusAccess::SetSlaveAddr:Unable to Set Slave Addr to "<<addr<<endl;
146146
return RPC_SRV_RESULT_BUS_ERROR;//RPC_SRV_RESULT_FAIL;
@@ -178,7 +178,7 @@ RPC_SRV_RESULT I2CBusAccess::read_byte(uint32_t addr, uint8_t *data)
178178
RPC_SRV_RESULT retval=Client.get_integer_type_with_addr_para((char*)RPCMGR_RPC_MW_BYTE_GET,(char*)RPCMGR_RPC_MW_ARGADDR,addr,(char*)RPCMGR_RPC_MW_ARGDATA,tmpbuf);
179179
if(retval==RPC_SRV_RESULT_SUCCESS)
180180
*data=(uint8_t)atoi(tmpbuf);
181-
return retval;
181+
return retval;
182182
}
183183
else
184184
return RPC_SRV_RESULT_FAIL;
@@ -236,7 +236,7 @@ RPC_SRV_RESULT I2CBusAccess::read_word(uint32_t addr, uint16_t *data)
236236
RPC_SRV_RESULT retval=Client.get_integer_type_with_addr_para((char*)RPCMGR_RPC_MW_WORD_GET,(char*)RPCMGR_RPC_MW_ARGADDR,addr,(char*)RPCMGR_RPC_MW_ARGDATA,tmpbuf);
237237
if(retval==RPC_SRV_RESULT_SUCCESS)
238238
*data=(uint16_t)atoi(tmpbuf);
239-
return retval;
239+
return retval;
240240
}
241241
else
242242
return RPC_SRV_RESULT_FAIL;
@@ -288,7 +288,7 @@ RPC_SRV_RESULT I2CBusAccess::read_dword(uint32_t addr, uint32_t *data)
288288
RPC_SRV_RESULT retval=Client.get_integer_type_with_addr_para((char*)RPCMGR_RPC_MW_DWORD_GET,(char*)RPCMGR_RPC_MW_ARGADDR,addr,(char*)RPCMGR_RPC_MW_ARGDATA,tmpbuf);
289289
if(retval==RPC_SRV_RESULT_SUCCESS)
290290
*data=(uint32_t)atoi(tmpbuf);//TODO: check if atol is needed
291-
return retval;
291+
return retval;
292292
}
293293
else
294294
return RPC_SRV_RESULT_FAIL;
@@ -351,7 +351,7 @@ RPC_SRV_RESULT I2CBusAccess::test_write_byte(char* dev,uint8_t addr, uint8_t dat
351351
{
352352
int myfd;
353353
myfd = open(dev, O_RDWR);
354-
if (myfd < 0)
354+
if (myfd < 0)
355355
{
356356
//printf("I2CBusAccess::test_write_byte:Error opening file: %s\n", strerror(errno));
357357
//return RPC_SRV_RESULT_FILE_OPEN_ERR;
@@ -364,15 +364,15 @@ RPC_SRV_RESULT I2CBusAccess::test_write_byte(char* dev,uint8_t addr, uint8_t dat
364364
}
365365
}
366366
//fcntl(myfd, F_SETFL,fcntl(myfd, F_GETFL) | O_NONBLOCK);
367-
if (ioctl(myfd, I2C_SLAVE, addr) < 0)
367+
if (ioctl(myfd, I2C_SLAVE, addr) < 0)
368368
{
369369
//printf("I2CBusAccess::test_write_byte:ioctl error: %s\n", strerror(errno));
370370
return RPC_SRV_RESULT_FILE_WRITE_ERR;
371371
}
372372
uint8_t buff[16];buff[0]=data;
373373
//int val=atoi(argv[1]);
374374
unsigned int tst=data;
375-
int sz=I2C_WRITE(myfd, &tst, 1);// != 1)
375+
int sz=I2C_WRITE(myfd, &tst, 1);// != 1)
376376
if(sz!=1)
377377
{
378378
//printf("I2CBusAccess::test_write_byte:Error writing file:written %d bytes, errorno:%s\n",sz,strerror(errno));
@@ -419,6 +419,3 @@ int32_t I2CBusAccess::i2c_smbus_write_byte(int file,uint8_t value)
419419
#endif
420420
}
421421
/*****************************************************************************/
422-
423-
424-

sources/lib/lib-adav-old/src/I2CSsd1306.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool I2CSsd1306::writeText (std::string text, uint8_t row, uint8_t col) //
119119
return true;
120120
}
121121
/*****************************************************************************/
122-
RPC_SRV_RESULT I2CSsd1306::init_display()
122+
RPC_SRV_RESULT I2CSsd1306::init_display()
123123
{
124124
return init_display_new();
125125
bool retval = false;
@@ -381,7 +381,7 @@ RPC_SRV_RESULT I2CSsd1306::init_display_new()
381381
std::string node(devNode);
382382
int position = node.find("i2c-");
383383
std::string value = node.substr(position+4);//(devNode.length()-position)+3);
384-
cout<<"node:"<<node<<":pos="<<position<<" : dev-node="<<value<<" : type="<<iOLEDType<<endl;
384+
//cout<<"node:"<<node<<":pos="<<position<<" : dev-node="<<value<<" : type="<<iOLEDType<<endl;
385385
iChannel = std::stoi(value);
386386

387387
i=oledInit(&ssoled, iOLEDType, iOLEDAddr, bFlip, bInvert, 1, iChannel, iOLEDAddr, -1, 400000);
@@ -396,5 +396,3 @@ RPC_SRV_RESULT I2CSsd1306::init_display_new()
396396
return RPC_SRV_RESULT_FAIL;
397397
}
398398
/*****************************************************************************/
399-
400-

sources/services/dispsrv/include/DispsrvJsonDef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef enum EJSON_DISPSRV_LINE_T
5555
#define DISPSRV_RPC_DISP_GET_BKLT "display_backlight_get"
5656
#define DISPSRV_RPC_DISP_SET_BKLT "display_backlight_set"
5757
#define DISPSRV_RPC_DISP_BKLT_ARG "status"
58-
#define DISPSRV_RPC_DISP_BKLT_ARG_TABL {"off","on","unknown","none","\0"}
58+
#define DISPSRV_RPC_DISP_BKLT_ARG_TABL {"off","on","unknown","none","\0"}
5959
typedef enum DISPSRV_BKLT_STS_T
6060
{
6161
DISPSRV_BKLT_STS_OFF,
@@ -81,12 +81,14 @@ typedef struct DISPSRV_CMN_DATA_CACHE_T
8181
//unsigned int gpio_data[GPIOCTL_MAX_GPIO_PINS];//allow max 64gpio addresses(0 to 63)
8282
//unsigned int gpio_data_prev[GPIOCTL_MAX_GPIO_PINS];//comparing the last value for eventing
8383
DisplayDevice *pDisplay;
84+
ADLIB_DISPLAY_TYPE disp_type;//display-type suggested by user via commandline
8485
DISPSRV_CMN_DATA_CACHE_T() //constructor(initializer)
8586
{
8687
pDevInfo=NULL;
8788
pEventNotifier=NULL;
8889
//pDispAccess=NULL;
8990
pDisplay=NULL;
91+
disp_type=ADLIB_DISPLAY_TYPE_UNKNOWN;
9092
};
9193
}DISPSRV_CMN_DATA_CACHE;
9294
/* ------------------------------------------------------------------------- */
@@ -98,4 +100,3 @@ typedef enum DISPSRV_EVENT_TYPE_T
98100
}DISPSRV_EVENT_TYPE;
99101
#define SERVER_JSON_PORT_NUM DISPSRV_JSON_PORT_NUMBER
100102
#endif
101-

0 commit comments

Comments
 (0)