indentation

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1199 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
michael
2013-05-23 03:07:28 +00:00
parent ab5d1fd17f
commit 745168103c
6 changed files with 269 additions and 265 deletions
+1 -1
View File
@@ -203,7 +203,7 @@ static void drv_PICGraphic_blit(const int row, const int col, const int height,
delayDone = 0;
int row8, height8;
row8 = 8 * (row / 8);
height8 = 8 * (height / 8) + !!(height % 8);
height8 = 8 * (height / 8) + ! !(height % 8);
info("sending blit");
cmd[0] = 'b';
cmd[1] = row8;
+232 -230
View File
@@ -122,11 +122,11 @@ static char Name[] = "DPF";
* Dpf status
*/
static struct {
unsigned char *lcdBuf; // Display data buffer
unsigned char *lcdBuf; // Display data buffer
unsigned char *xferBuf; // USB transfer buffer
DPFAXHANDLE dpfh; // Handle for dpf access
int pwidth; // Physical display width
int pheight; // Physical display height
DPFAXHANDLE dpfh; // Handle for dpf access
int pwidth; // Physical display width
int pheight; // Physical display height
// Flags to translate logical to physical orientation
int isPortrait;
@@ -160,7 +160,7 @@ static struct {
static void drv_set_pixel(int x, int y, RGBA pix)
{
int changed = 0;
int sx = DCOLS;
int sy = DROWS;
int lx = x % sx;
@@ -168,39 +168,41 @@ static void drv_set_pixel(int x, int y, RGBA pix)
if (dpf.flip) {
// upside down orientation
lx = DCOLS - 1 - lx;
ly = DROWS - 1 - ly;
lx = DCOLS - 1 - lx;
ly = DROWS - 1 - ly;
}
if (dpf.rotate90) {
// wrong Orientation, rotate
int i = ly;
ly = dpf.pheight - 1 - lx;
lx = i;
// wrong Orientation, rotate
int i = ly;
ly = dpf.pheight - 1 - lx;
lx = i;
}
if (lx < 0 || lx >= (int) dpf.pwidth || ly < 0 || ly >= (int) dpf.pheight)
{
error("dpf: x/y out of bounds (x=%d, y=%d, rot=%d, flip=%d, lx=%d, ly=%d)\n", x, y, dpf.rotate90, dpf.flip, lx, ly);
return;
if (lx < 0 || lx >= (int) dpf.pwidth || ly < 0 || ly >= (int) dpf.pheight) {
error("dpf: x/y out of bounds (x=%d, y=%d, rot=%d, flip=%d, lx=%d, ly=%d)\n", x, y, dpf.rotate90, dpf.flip, lx,
ly);
return;
}
unsigned char c1 = _RGB565_0(pix);
unsigned char c2 = _RGB565_1(pix);
unsigned int i = (ly * dpf.pwidth + lx) * DPF_BPP;
if (dpf.lcdBuf[i] != c1 || dpf.lcdBuf[i+1] != c2)
{
dpf.lcdBuf[i] = c1;
dpf.lcdBuf[i+1] = c2;
if (dpf.lcdBuf[i] != c1 || dpf.lcdBuf[i + 1] != c2) {
dpf.lcdBuf[i] = c1;
dpf.lcdBuf[i + 1] = c2;
changed = 1;
}
if (changed)
{
if (lx < dpf.minx) dpf.minx = lx;
if (lx > dpf.maxx) dpf.maxx = lx;
if (ly < dpf.miny) dpf.miny = ly;
if (ly > dpf.maxy) dpf.maxy = ly;
if (changed) {
if (lx < dpf.minx)
dpf.minx = lx;
if (lx > dpf.maxx)
dpf.maxx = lx;
if (ly < dpf.miny)
dpf.miny = ly;
if (ly > dpf.maxy)
dpf.maxy = ly;
}
}
@@ -259,78 +261,74 @@ static int drv_dpf_start(const char *section)
// Get the device
dev = cfg_get(section, "Port", NULL);
if (dev == NULL || *dev == '\0') {
error("dpf: no '%s.Port' entry from %s", section, cfg_source());
return -1;
error("dpf: no '%s.Port' entry from %s", section, cfg_source());
return -1;
}
// Get font
s = cfg_get(section, "Font", "6x8");
if (s == NULL || *s == '\0') {
error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
return -1;
error("%s: no '%s.Font' entry from %s", Name, section, cfg_source());
return -1;
}
XRES = -1;
YRES = -1;
if (sscanf(s, "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
error("%s: bad Font '%s' from %s", Name, s, cfg_source());
return -1;
error("%s: bad Font '%s' from %s", Name, s, cfg_source());
return -1;
}
/* we dont want fonts below 6 width */
if (XRES < 6) {
error("%s: bad Font '%s' width '%d' using minimum of 6)", Name, s, XRES);
XRES = 6;
error("%s: bad Font '%s' width '%d' using minimum of 6)", Name, s, XRES);
XRES = 6;
}
/* we dont want fonts below 8 height */
if (YRES < 8) {
error("%s: bad Font '%s' height '%d' using minimum of 8)", Name, s, YRES);
YRES = 8;
error("%s: bad Font '%s' height '%d' using minimum of 8)", Name, s, YRES);
YRES = 8;
}
// Get the logical orientation (0 = landscape, 1 = portrait, 2 = reverse landscape, 3 = reverse portrait)
if (cfg_number(section, "Orientation", 0, 0, 3, &i) > 0)
dpf.orientation = i;
dpf.orientation = i;
else
dpf.orientation = 0;
dpf.orientation = 0;
// Get the backlight value (0 = off, 7 = max brightness)
if (cfg_number(section, "Backlight", 0, 0, 7, &i) > 0)
dpf.backlight = i;
dpf.backlight = i;
else
dpf.backlight = 7;
dpf.backlight = 7;
/* open communication with the display */
dpf.dpfh = dpf_ax_open(dev);
if (dpf.dpfh == NULL) {
error("dpf: cannot open dpf device %s", dev);
return -1;
error("dpf: cannot open dpf device %s", dev);
return -1;
}
// Get dpfs physical dimensions
dpf.pwidth = dpf_ax_getwidth(dpf.dpfh);
dpf.pheight = dpf_ax_getheight(dpf.dpfh);
// See, if we have to rotate the display
dpf.isPortrait = dpf.pwidth < dpf.pheight;
if (dpf.isPortrait) {
if (dpf.orientation == 0 || dpf.orientation == 2)
dpf.rotate90 = 1;
}
else
if (dpf.orientation == 1 || dpf.orientation == 3)
dpf.rotate90 = 1;
dpf.flip = (!dpf.isPortrait && dpf.rotate90); // adjust to make rotate por/land = physical por/land
if (dpf.orientation > 1) dpf.flip = !dpf.flip;
} else if (dpf.orientation == 1 || dpf.orientation == 3)
dpf.rotate90 = 1;
dpf.flip = (!dpf.isPortrait && dpf.rotate90); // adjust to make rotate por/land = physical por/land
if (dpf.orientation > 1)
dpf.flip = !dpf.flip;
// allocate display buffer + temp transfer buffer
dpf.lcdBuf = malloc(dpf.pwidth * dpf.pheight * DPF_BPP);
dpf.xferBuf = malloc(dpf.pwidth * dpf.pheight * DPF_BPP);
// clear display buffer + set it to "dirty"
memset(dpf.lcdBuf, 0, dpf.pwidth * dpf.pheight * DPF_BPP); //Black
memset(dpf.lcdBuf, 0, dpf.pwidth * dpf.pheight * DPF_BPP); //Black
dpf.minx = 0;
dpf.maxx = dpf.pwidth - 1;
dpf.miny = 0;
@@ -342,7 +340,7 @@ static int drv_dpf_start(const char *section)
// Set backlight (brightness)
dpf_ax_setbacklight(dpf.dpfh, dpf.backlight);
return 0;
}
@@ -354,9 +352,11 @@ static int drv_dpf_start(const char *section)
static void plugin_backlight(RESULT * result, RESULT * arg1)
{
int b = R2N(arg1);
if (b < 0) b = 0;
if (b > 7) b = 7;
if (b < 0)
b = 0;
if (b > 7)
b = 7;
dpf_ax_setbacklight(dpf.dpfh, b);
SetResult(&result, R_NUMBER, &b);
}
@@ -443,11 +443,11 @@ DRIVER drv_DPF = {
#include <usb.h>
#define AX206_VID 0x1908 // Hacked frames USB Vendor ID
#define AX206_PID 0x0102 // Hacked frames USB Product ID
#define AX206_VID 0x1908 // Hacked frames USB Vendor ID
#define AX206_PID 0x0102 // Hacked frames USB Product ID
#define USBCMD_SETPROPERTY 0x01 // USB command: Set property
#define USBCMD_BLIT 0x12 // USB command: Blit to screen
#define USBCMD_BLIT 0x12 // USB command: Blit to screen
/* Generic SCSI device stuff */
@@ -456,14 +456,14 @@ DRIVER drv_DPF = {
/* The DPF context structure */
typedef
struct dpf_context {
usb_dev_handle *udev;
unsigned int width;
unsigned int height;
struct dpf_context {
usb_dev_handle *udev;
unsigned int width;
unsigned int height;
} DPFContext;
static int wrap_scsi(DPFContext *h, unsigned char *cmd, int cmdlen, char out,
unsigned char *data, unsigned long block_len);
static int wrap_scsi(DPFContext * h, unsigned char *cmd, int cmdlen, char out,
unsigned char *data, unsigned long block_len);
/**
* Open DPF device.
@@ -477,89 +477,88 @@ static int wrap_scsi(DPFContext *h, unsigned char *cmd, int cmdlen, char out,
*/
DPFAXHANDLE dpf_ax_open(const char *dev)
{
DPFContext *dpf;
int index = -1;
usb_dev_handle *u;
DPFContext *dpf;
int index = -1;
usb_dev_handle *u;
if (dev && strlen(dev) == 4 && (strncmp(dev, "usb", 3) == 0 || strncmp(dev, "dpf", 3) == 0))
index = dev[3] - '0';
if (index < 0 || index > 9) {
fprintf(stderr, "dpf_ax_open: wrong device '%s'. Please specify a string like 'usb0'\n", dev);
return NULL;
if (dev && strlen(dev) == 4 && (strncmp(dev, "usb", 3) == 0 || strncmp(dev, "dpf", 3) == 0))
index = dev[3] - '0';
if (index < 0 || index > 9) {
fprintf(stderr, "dpf_ax_open: wrong device '%s'. Please specify a string like 'usb0'\n", dev);
return NULL;
}
usb_init();
usb_find_busses();
usb_find_devices();
struct usb_bus *b = usb_get_busses();
struct usb_device *d = NULL;
int enumeration = 0;
int found = 0;
while (b && !found) {
d = b->devices;
while (d) {
if ((d->descriptor.idVendor == AX206_VID) && (d->descriptor.idProduct == AX206_PID)) {
fprintf(stderr, "dpf_ax_open: found AX206 #%d\n", enumeration + 1);
if (enumeration == index) {
found = 1;
break;
} else
enumeration++;
}
d = d->next;
}
b = b->next;
}
usb_init();
usb_find_busses();
usb_find_devices();
if (!d) {
fprintf(stderr, "dpf_ax_open: no matching USB device '%s' found!\n", dev);
return NULL;
}
struct usb_bus *b = usb_get_busses();
struct usb_device *d = NULL;
int enumeration = 0;
int found = 0;
dpf = (DPFContext *) malloc(sizeof(DPFContext));
if (!dpf) {
fprintf(stderr, "dpf_ax_open: error allocation memory.\n");
return NULL;
}
while (b && !found) {
d = b->devices;
while (d) {
if ((d->descriptor.idVendor == AX206_VID) && (d->descriptor.idProduct == AX206_PID)) {
fprintf(stderr, "dpf_ax_open: found AX206 #%d\n", enumeration+1);
if (enumeration == index) {
found = 1;
break;
}
else enumeration++;
}
d = d->next;
}
b = b->next;
}
u = usb_open(d);
if (u == NULL) {
fprintf(stderr, "dpf_ax_open: failed to open usb device '%s'!\n", dev);
free(dpf);
return NULL;
}
if (!d) {
fprintf(stderr,"dpf_ax_open: no matching USB device '%s' found!\n", dev);
return NULL;
}
if (usb_claim_interface(u, 0) < 0) {
fprintf(stderr, "dpf_ax_open: failed to claim usb device!\n");
usb_close(u);
free(dpf);
return NULL;
}
dpf = (DPFContext *) malloc(sizeof(DPFContext));
if (!dpf) {
fprintf(stderr, "dpf_ax_open: error allocation memory.\n");
return NULL;
}
dpf->udev = u;
u = usb_open(d);
if (u == NULL) {
fprintf(stderr,"dpf_ax_open: failed to open usb device '%s'!\n", dev);
free(dpf);
return NULL;
}
if (usb_claim_interface(u, 0) < 0) {
fprintf(stderr,"dpf_ax_open: failed to claim usb device!\n");
usb_close(u);
free(dpf);
return NULL;
}
dpf->udev = u;
static unsigned char buf[5];
static unsigned char cmd[16] = {
0xcd, 0, 0, 0,
0, 2, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
cmd[5] = 2; // get LCD parameters
if (wrap_scsi(dpf, cmd, sizeof(cmd), DIR_IN, buf, 5) == 0) {
dpf->width = (buf[0]) | (buf[1] << 8);
dpf->height = (buf[2]) | (buf[3] << 8);
fprintf(stderr, "dpf_ax_open: got LCD dimensions: %dx%d\n", dpf->width, dpf->height);
}
else {
fprintf(stderr, "dpf_ax_open: error reading LCD dimensions!\n");
dpf_ax_close(dpf);
return NULL;
}
return (DPFAXHANDLE) dpf;
static unsigned char buf[5];
static unsigned char cmd[16] = {
0xcd, 0, 0, 0,
0, 2, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
cmd[5] = 2; // get LCD parameters
if (wrap_scsi(dpf, cmd, sizeof(cmd), DIR_IN, buf, 5) == 0) {
dpf->width = (buf[0]) | (buf[1] << 8);
dpf->height = (buf[2]) | (buf[3] << 8);
fprintf(stderr, "dpf_ax_open: got LCD dimensions: %dx%d\n", dpf->width, dpf->height);
} else {
fprintf(stderr, "dpf_ax_open: error reading LCD dimensions!\n");
dpf_ax_close(dpf);
return NULL;
}
return (DPFAXHANDLE) dpf;
}
/**
@@ -568,11 +567,11 @@ DPFAXHANDLE dpf_ax_open(const char *dev)
void dpf_ax_close(DPFAXHANDLE h)
{
DPFContext *dpf = (DPFContext *) h;
usb_release_interface(dpf->udev, 0);
usb_close(dpf->udev);
free(dpf);
DPFContext *dpf = (DPFContext *) h;
usb_release_interface(dpf->udev, 0);
usb_close(dpf->udev);
free(dpf);
}
/** Get screen width.
@@ -581,7 +580,7 @@ void dpf_ax_close(DPFAXHANDLE h)
*/
int dpf_ax_getwidth(DPFAXHANDLE h)
{
return ((DPFContext *) h)->width;
return ((DPFContext *) h)->width;
}
/** Get screen height.
@@ -590,15 +589,15 @@ int dpf_ax_getwidth(DPFAXHANDLE h)
*/
int dpf_ax_getheight(DPFAXHANDLE h)
{
return ((DPFContext *) h)->height;
return ((DPFContext *) h)->height;
}
static
unsigned char g_excmd[16] = {
0xcd, 0, 0, 0,
0, 6, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
0xcd, 0, 0, 0,
0, 6, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
/** Blit data to screen.
@@ -608,22 +607,22 @@ unsigned char g_excmd[16] = {
*/
void dpf_ax_screen_blit(DPFAXHANDLE h, const unsigned char *buf, short rect[4])
{
unsigned long len = (rect[2] - rect[0]) * (rect[3] - rect[1]);
len <<= 1;
unsigned char *cmd = g_excmd;
unsigned long len = (rect[2] - rect[0]) * (rect[3] - rect[1]);
len <<= 1;
unsigned char *cmd = g_excmd;
cmd[6] = USBCMD_BLIT;
cmd[7] = rect[0];
cmd[8] = rect[0] >> 8;
cmd[9] = rect[1];
cmd[10] = rect[1] >> 8;
cmd[11] = rect[2] - 1;
cmd[12] = (rect[2] - 1) >> 8;
cmd[13] = rect[3] - 1;
cmd[14] = (rect[3] - 1) >> 8;
cmd[15] = 0;
cmd[6] = USBCMD_BLIT;
cmd[7] = rect[0];
cmd[8] = rect[0] >> 8;
cmd[9] = rect[1];
cmd[10] = rect[1] >> 8;
cmd[11] = rect[2] - 1;
cmd[12] = (rect[2] - 1) >> 8;
cmd[13] = rect[3] - 1;
cmd[14] = (rect[3] - 1) >> 8;
cmd[15] = 0;
wrap_scsi((DPFContext *) h, cmd, sizeof(g_excmd), DIR_OUT, (unsigned char*) buf, len);
wrap_scsi((DPFContext *) h, cmd, sizeof(g_excmd), DIR_OUT, (unsigned char *) buf, len);
}
/** Set backlight
@@ -632,91 +631,94 @@ void dpf_ax_screen_blit(DPFAXHANDLE h, const unsigned char *buf, short rect[4])
*/
void dpf_ax_setbacklight(DPFAXHANDLE h, int b)
{
unsigned char *cmd = g_excmd;
unsigned char *cmd = g_excmd;
if (b < 0) b = 0;
if (b > 7) b = 7;
if (b < 0)
b = 0;
if (b > 7)
b = 7;
cmd[6] = USBCMD_SETPROPERTY;
cmd[7] = 0x01; // PROPERTY_BRIGHTNESS
cmd[8] = 0x00; //PROPERTY_BRIGHTNESS >> 8;
cmd[9] = b;
cmd[10] = b >> 8;
cmd[6] = USBCMD_SETPROPERTY;
cmd[7] = 0x01; // PROPERTY_BRIGHTNESS
cmd[8] = 0x00; //PROPERTY_BRIGHTNESS >> 8;
cmd[9] = b;
cmd[10] = b >> 8;
wrap_scsi((DPFContext *) h, cmd, sizeof(g_excmd), DIR_OUT, NULL, 0);
wrap_scsi((DPFContext *) h, cmd, sizeof(g_excmd), DIR_OUT, NULL, 0);
}
static unsigned char g_buf[] = {
0x55, 0x53, 0x42, 0x43, // dCBWSignature
0xde, 0xad, 0xbe, 0xef, // dCBWTag
0x00, 0x80, 0x00, 0x00, // dCBWLength
0x00, // bmCBWFlags: 0x80: data in (dev to host), 0x00: Data out
0x00, // bCBWLUN
0x10, // bCBWCBLength
0x55, 0x53, 0x42, 0x43, // dCBWSignature
0xde, 0xad, 0xbe, 0xef, // dCBWTag
0x00, 0x80, 0x00, 0x00, // dCBWLength
0x00, // bmCBWFlags: 0x80: data in (dev to host), 0x00: Data out
0x00, // bCBWLUN
0x10, // bCBWCBLength
// SCSI cmd:
0xcd, 0x00, 0x00, 0x00,
0x00, 0x06, 0x11, 0xf8,
0x70, 0x00, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00,
// SCSI cmd:
0xcd, 0x00, 0x00, 0x00,
0x00, 0x06, 0x11, 0xf8,
0x70, 0x00, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00,
};
#define ENDPT_OUT 1
#define ENDPT_IN 0x81
static int wrap_scsi(DPFContext *h, unsigned char *cmd, int cmdlen, char out,
unsigned char *data, unsigned long block_len)
static int wrap_scsi(DPFContext * h, unsigned char *cmd, int cmdlen, char out,
unsigned char *data, unsigned long block_len)
{
int len;
int ret;
static unsigned char ansbuf[13]; // Do not change size.
int len;
int ret;
static unsigned char ansbuf[13]; // Do not change size.
g_buf[14] = cmdlen;
memcpy(&g_buf[15], cmd, cmdlen);
g_buf[14] = cmdlen;
memcpy(&g_buf[15], cmd, cmdlen);
g_buf[8] = block_len;
g_buf[9] = block_len >> 8;
g_buf[10] = block_len >> 16;
g_buf[11] = block_len >> 24;
g_buf[8] = block_len;
g_buf[9] = block_len >> 8;
g_buf[10] = block_len >> 16;
g_buf[11] = block_len >> 24;
ret = usb_bulk_write(h->udev, ENDPT_OUT, (const char *)g_buf, sizeof(g_buf), 1000);
if (ret < 0) return ret;
ret = usb_bulk_write(h->udev, ENDPT_OUT, (const char *) g_buf, sizeof(g_buf), 1000);
if (ret < 0)
return ret;
if (out == DIR_OUT) {
if (data) {
ret = usb_bulk_write(h->udev, ENDPT_OUT, (const char* )data, block_len, 3000);
if (ret != (int) block_len) {
fprintf(stderr, "dpf_ax ERROR: bulk write.\n");
return ret;
}
}
} else if (data) {
ret = usb_bulk_read(h->udev, ENDPT_IN, (char *) data, block_len, 4000);
if (ret != (int) block_len) {
fprintf(stderr, "dpf_ax ERROR: bulk read.\n");
return ret;
}
if (out == DIR_OUT) {
if (data) {
ret = usb_bulk_write(h->udev, ENDPT_OUT, (const char *) data, block_len, 3000);
if (ret != (int) block_len) {
fprintf(stderr, "dpf_ax ERROR: bulk write.\n");
return ret;
}
}
// get ACK:
len = sizeof(ansbuf);
int retry = 0;
int timeout = 0;
do {
timeout = 0;
ret = usb_bulk_read(h->udev, ENDPT_IN, (char *) ansbuf, len, 5000);
if (ret != len) {
fprintf(stderr, "dpf_ax ERROR: bulk ACK read.\n");
timeout = 1;
}
retry++;
} while (timeout && retry < 5);
if (strncmp((char *) ansbuf, "USBS", 4)) {
fprintf(stderr, "dpf_ax ERROR: got invalid reply\n.");
return -1;
} else if (data) {
ret = usb_bulk_read(h->udev, ENDPT_IN, (char *) data, block_len, 4000);
if (ret != (int) block_len) {
fprintf(stderr, "dpf_ax ERROR: bulk read.\n");
return ret;
}
// pass back return code set by peer:
return ansbuf[12];
}
// get ACK:
len = sizeof(ansbuf);
int retry = 0;
int timeout = 0;
do {
timeout = 0;
ret = usb_bulk_read(h->udev, ENDPT_IN, (char *) ansbuf, len, 5000);
if (ret != len) {
fprintf(stderr, "dpf_ax ERROR: bulk ACK read.\n");
timeout = 1;
}
retry++;
} while (timeout && retry < 5);
if (strncmp((char *) ansbuf, "USBS", 4)) {
fprintf(stderr, "dpf_ax ERROR: got invalid reply\n.");
return -1;
}
// pass back return code set by peer:
return ansbuf[12];
}
//###################################################################
+1 -1
View File
@@ -164,7 +164,7 @@ static int drv_SD_start(const char *section)
sdcd = SDCONN_open(port);
if (sdcd == NULL) {
error("%s: open(%s) failed: %s", Name, port, sd_geterrormsg());
info("%s: examples:\n serraw:/dev/ttyS0\n par:/dev/parport0\n USB:<vendor>/<product>", Name);
info("%s: examples:\n serraw:/dev/ttyS0\n par:/dev/parport0\n USB:<vendor>/<product>", Name);
return -1;
}
+22 -20
View File
@@ -74,19 +74,20 @@ char tmpstr[128];
/* Note: all local functions should be declared 'static' */
/* reading an positive integer value from path, -1 on error */
static int readValue(char *path) {
static int readValue(char *path)
{
int value = -1;
FILE *fp;
fp = fopen(path, "r");
if (NULL != fp) {
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
if (1 != sscanf(tmpstr, "%i", &value)) {
error("[raspi] error reading integer value from %s\n", path);
}
error("[raspi] error reading integer value from %s\n", path);
}
} else {
error("[raspi] error opening %s: %s\n", path, strerror(errno));
error("[raspi] error opening %s: %s\n", path, strerror(errno));
}
return value;
@@ -94,16 +95,17 @@ static int readValue(char *path) {
/* reads a string from path */
static char* readStr(char *path) {
static char *readStr(char *path)
{
FILE *fp;
memset(tmpstr, 0, sizeof(tmpstr));
fp = fopen(path, "r");
if (NULL != fp) {
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
} else {
error("[raspi] error reading text value from %s: %s\n", path, strerror(errno));
error("[raspi] error reading text value from %s: %s\n", path, strerror(errno));
}
return tmpstr;
@@ -150,29 +152,29 @@ int plugin_init_raspi(void)
char checkFile[128];
snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_TEMP_PATH, RASPI_TEMP_IDFILE);
if (strncmp( readStr(checkFile), RASPI_TEMP_ID, strlen(RASPI_TEMP_ID) ) != 0) {
error("Warning: no raspberry pi thermal sensor found: value of '%s' is '%s', should be '%s'",
checkFile, readStr(checkFile), RASPI_TEMP_IDFILE);
if (strncmp(readStr(checkFile), RASPI_TEMP_ID, strlen(RASPI_TEMP_ID)) != 0) {
error("Warning: no raspberry pi thermal sensor found: value of '%s' is '%s', should be '%s'",
checkFile, readStr(checkFile), RASPI_TEMP_IDFILE);
}
snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_TEMP_PATH, RASPI_TEMP_VALUE);
if (0 == access(checkFile, R_OK)) {
AddFunction("raspi::cputemp", 0, my_cputemp);
AddFunction("raspi::cputemp", 0, my_cputemp);
} else {
error("Error: File '%s' not readable, no temperature sensor found", checkFile);
error("Error: File '%s' not readable, no temperature sensor found", checkFile);
}
snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_FREQ_PATH, RASPI_FREQ_IDFILE);
if (strncmp( readStr(checkFile), RASPI_FREQ_ID, strlen(RASPI_FREQ_ID) ) != 0) {
error("Warning: no raspberry pi frequence sensor found: value of '%s' is '%s', should be '%s'",
checkFile, readStr(checkFile), RASPI_FREQ_IDFILE);
if (strncmp(readStr(checkFile), RASPI_FREQ_ID, strlen(RASPI_FREQ_ID)) != 0) {
error("Warning: no raspberry pi frequence sensor found: value of '%s' is '%s', should be '%s'",
checkFile, readStr(checkFile), RASPI_FREQ_IDFILE);
}
snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_FREQ_PATH, RASPI_FREQ_VALUE);
if (0 == access(checkFile, R_OK)) {
AddFunction("raspi::cpufreq", 0, my_cpufreq);
AddFunction("raspi::cpufreq", 0, my_cpufreq);
} else {
error("Error: File '%s' not readable, no frequency sensor found", checkFile);
error("Error: File '%s' not readable, no frequency sensor found", checkFile);
}
return 0;
+9 -9
View File
@@ -185,7 +185,7 @@ int timer_add_group(const int interval)
if (TimerGroups[group].active == TIMER_INACTIVE) {
/* we've just found one, so let's reuse it ("group" holds its
ID) by breaking the loop */
debug("Reusing Timergroup %i", group);
debug("Reusing Timergroup %i", group);
break;
}
}
@@ -196,17 +196,17 @@ int timer_add_group(const int interval)
TIMER_GROUP *tmp;
if ((tmp = realloc(TimerGroups, (nTimerGroups + 1) * sizeof(*TimerGroups))) == NULL) {
error("Error expanding TimerGroups");
error("Error expanding TimerGroups");
/* signal unsuccessful timer group creation */
return -1;
}
TimerGroups = tmp;
nTimerGroups++;
if ((TimerGroups[group].interval = malloc(sizeof(int))) == NULL) {
/* signal unsuccessful timer group creation */
return -1;
}
if ((TimerGroups[group].interval = malloc(sizeof(int))) == NULL) {
/* signal unsuccessful timer group creation */
return -1;
}
}
/* initialize timer group's interval */
@@ -513,9 +513,9 @@ void timer_exit_group(void)
/* remove generic timer */
timer_remove(timer_process_group, TimerGroups[group].interval);
/* free memory allocated for callback data (i.e. the group's
triggering interval in milliseconds) */
free(TimerGroups[group].interval);
/* free memory allocated for callback data (i.e. the group's
triggering interval in milliseconds) */
free(TimerGroups[group].interval);
}
/* reset number of allocated timer groups */
+4 -4
View File
@@ -59,8 +59,8 @@ void widget_text_scroll(void *Self)
{
WIDGET *W = (WIDGET *) Self;
if (NULL == W || NULL == W->data) {
error("Warning: internal data error in Textwidget");
return;
error("Warning: internal data error in Textwidget");
return;
}
WIDGET_TEXT *T = W->data;
@@ -73,8 +73,8 @@ void widget_text_scroll(void *Self)
char *src, *dst;
if (NULL == string) {
error("Warning: Widget %s has no string", W->name);
return;
error("Warning: Widget %s has no string", W->name);
return;
}
num = 0;
len = strlen(string);