harmonize coding style and messages; use report()/debug() instead of printf()/perror()

This commit is contained in:
marschap
2006-04-08 21:00:37 +00:00
parent bf47e2e0ed
commit 1f0028cb6e
+19 -19
View File
@@ -54,6 +54,8 @@
# include "config.h"
#endif
#include "report.h"
#define min(a, b) ((a)<(b) ? (a) : (b))
#define True 1
#define False 0
@@ -121,7 +123,7 @@ int read_tele(pylcd_private_data *status, char *buffer)
&& (zeichen==cc))
{
buffer[len]=0x00;
if (DEBUG) printf("DEBUG: read %s\n", buffer);
debug(RPT_DEBUG, "%s: read %s", __FUNCTION__, buffer);
return True;
}
else
@@ -160,7 +162,7 @@ int send_tele(pylcd_private_data *status, char *buffer)
write(status->FD, buffer2, len+1);
/* tcflush (status->FD, TCIFLUSH); */
if (DEBUG) printf("DEBUG: sent: %s\n", buffer);
debug(RPT_DEBUG, "%s: sent %s", __FUNCTION__, buffer);
return 0;
}
@@ -183,7 +185,7 @@ unsigned long long timestamp(pylcd_private_data *status)
/* Sets the serial device, used for communication with the LCD, into raw mode
*/
int initTTY(int FD)
int initTTY(Driver *drvthis, int FD)
{
struct termios tty_mode;
@@ -198,11 +200,11 @@ int initTTY(int FD)
tty_mode.c_cc[VTIME] = 1;
if (tcsetattr(FD, TCSANOW, &tty_mode) != 0) {
perror("Setting TTY failed");
report(RPT_ERR, "%s: setting TTY failed: %s", drvthis->name, strerror(errno));
return -1;
}
} else {
perror("Reading TTY faild");
report(RPT_ERR, "%s: reading TTY failed: %s", drvthis->name, strerror(errno));
return -1;
}
@@ -238,7 +240,7 @@ MODULE_EXPORT int pylcd_init (Driver *drvthis, char *args)
status = (pylcd_private_data *) malloc(sizeof(pylcd_private_data));
if ((status == NULL) || (drvthis->store_private_ptr(drvthis, status) < 0))
{
printf("Error allocating memory for modules private data\n");
report(RPT_ERR, "%s: error allocating memory for modules private data", drvthis->name);
return -1;
}
@@ -246,18 +248,17 @@ MODULE_EXPORT int pylcd_init (Driver *drvthis, char *args)
/* Which serial device should be used? */
strncpy(status->devicename, drvthis->config_get_string(drvthis->name, "Device", 0, "/dev/lcd"), sizeof(status->devicename));
status->devicename[sizeof(status->devicename)-1]=0;
printf("pylcd: Using device: %s\n", status->devicename);
status->devicename[sizeof(status->devicename)-1] = '\0';
report(RPT_INFO, "%s: using Device %s", drvthis->name, status->devicename);
/* open and initialize serial device */
status->FD = open(status->devicename, O_RDWR);
if (status->FD==-1)
{
perror("Opening device failed");
if (status->FD == -1) {
report(RPT_ERR, "%s: opening device failed: %s", drvthis->name, strerror(errno));
return -1;
}
if (initTTY(status->FD)!=0)
if (initTTY(drvthis, status->FD) != 0)
return -1;
status->timeout.tv_sec = 0;
@@ -274,8 +275,7 @@ MODULE_EXPORT int pylcd_init (Driver *drvthis, char *args)
*/
tcflush(status->FD, TCIFLUSH); /* clear everything */
while (1)
{
while (1) {
i = read_tele(status, buffer);
if (i == True)
send_ACK(status);
@@ -298,6 +298,8 @@ MODULE_EXPORT int pylcd_init (Driver *drvthis, char *args)
status->led[i] = 0;
set_leds(status);
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0;
};
@@ -375,7 +377,6 @@ MODULE_EXPORT void pylcd_chr (Driver *drvthis, int x, int y, char c)
x = min(status->width, x);
y = min(status->height, y);
status->framebuffer[x+status->width*(y-1)]=c;
};
@@ -440,8 +441,7 @@ MODULE_EXPORT const char *pylcd_get_key (Driver *drvthis)
pylcd_private_data *status = (pylcd_private_data *) drvthis->private_data;
/* Now we read everything from the display and as long as we got ACKs, we ignore them. */
while (1)
{
while (1) {
retval = read_tele(status, buffer);
if ((retval == False) || (buffer[0] != 'Q')) break;
}
@@ -459,14 +459,14 @@ MODULE_EXPORT const char *pylcd_get_key (Driver *drvthis)
|| (strcmp(buffer, "K0300") == 0)
|| (strcmp(buffer, "K3000") == 0))
{
if (DEBUG) printf("DEBUG: Key released: %s\n", status->last_key_pressed);
debug(RPT_DEBUG, "%s: Key released: %s", __FUNCTION__, status->last_key_pressed);
strcpy(status->last_key_pressed, NOKEY);
return NULL;
}
else /* It must be a new key event */
{
strcpy(status->last_key_pressed, buffer);
if (DEBUG) printf("DEBUG: Key pressed: %s\n", status->last_key_pressed);
debug(RPT_DEBUG, "%s: Key pressed: %s", __FUNCTION__, status->last_key_pressed);
}
}
/* If no keys are pressed at this time, we are done. */