static int configure_mpd(void) { static int configured = 0; char *s; if (configured != 0) return configured; /* read enabled */ if (cfg_number(Section, "enabled", 0, 0, 1, &plugin_enabled) < 1) { plugin_enabled = 0; } if (plugin_enabled != 1) { info("[MPD] WARNING: Plugin is not enabled! (set 'enabled 1' to enable this plugin)"); configured = 1; return configured; } /* read server */ s = cfg_get(Section, "server", "localhost"); if (!s || *s == '\0') { info("[MPD] empty '%s.server' entry from %s, assuming 'localhost'", Section, cfg_source()); strcpy(host, "localhost"); } else strcpy(host, s); if (s) free(s); /* read port */ if (cfg_number(Section, "port", 6600, 1, 65536, &iport) < 1) { info("[MPD] no '%s.port' entry from %s using MPD's default", Section, cfg_source()); } /* read minUpdateTime in ms */ if (cfg_number(Section, "minUpdateTime", 500, 1, 10000, &waittime) < 1) { info("[MPD] no '%s.minUpdateTime' entry from %s using MPD's default", Section, cfg_source()); } /* read password */ s = cfg_get(Section, "password", ""); if (!s || *s == '\0') { info("[MPD] empty '%s.password' entry in %s, assuming none", Section, cfg_source()); memset(pw, 0, sizeof(pw)); } else strcpy(pw, s); if (s) free(s); debug("[MPD] connection detail: [%s:%d]", host, iport); configured = 1; return configured; }
static int drv_BW_start(const char *section, const int quiet) { int contrast; int rows = -1, cols = -1; char *s; s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%dx%d", &cols, &rows) != 2 || rows < 1 || cols < 1) { error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); free(s); return -1; } DROWS = rows; DCOLS = cols; if (drv_BW_open() < 0) { error("%s: could not find a BWCT USB LCD", Name); return -1; } /* reset */ drv_BW_send(LCD_RESET, 0); /* initialize display */ drv_BW_command(0x29); /* 8 Bit mode, 1/16 duty cycle, 5x8 font */ drv_BW_command(0x08); /* Display off, cursor off, blink off */ drv_BW_command(0x0c); /* Display on, cursor off, blink off */ drv_BW_command(0x06); /* curser moves to right, no shift */ if (cfg_number(section, "Contrast", 0, 0, 255, &contrast) > 0) { drv_BW_contrast(contrast); } drv_BW_clear(); /* clear display */ if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_text_greet(buffer, "www.bwct.de")) { sleep(3); drv_BW_clear(); } } return 0; }
static int configure_imon(void) { static int configured = 0; char *s; if (configured != 0) return configured; hash_create(&IMON); s = cfg_get("Plugin:Imon", "Host", "127.0.0.1"); if (*s == '\0') { error("[Imon] empty 'Host' entry in %s", cfg_source()); configured = -1; return configured; } strcpy(ihost, s); free(s); if (cfg_number("Plugin:Imon", "Port", 5000, 1, 65536, &iport) < 0) { error("[Imon] no valid port definition"); configured = -1; return configured; } s = cfg_get("Plugin:Imon", "Pass", ""); strcpy(ipass, s); free(s); configured = 1; return configured; }
static int configure_telmon(void) { static int configured = 0; char *s; if (configured != 0) return configured; hash_create(&TELMON); s = cfg_get("Plugin:Telmon", "Host", "127.0.0.1"); if (*s == '\0') { error("[Telmon] empty 'Host' entry in %s", cfg_source()); configured = -1; return configured; } strcpy(thost, s); free(s); if (cfg_number("Plugin:Telmon", "Port", 5001, 1, 65536, &tport) < 0) { error("[Telmon] no valid port definition"); configured = -1; return configured; } s = cfg_get("Plugin:Telmon", "Phonebook", "/etc/phonebook"); strcpy(phoneb, s); free(s); configured = 1; return configured; }
static int drv_BuE_start(const char *section) { int i, ret; char *model; model = cfg_get(section, "Model", NULL); if (model == NULL && *model == '\0') { error("%s: no '%s.Model' entry from %s", Name, section, cfg_source()); return -1; } for (i = 0; Models[i].name != NULL; i++) { if (strcasecmp(Models[i].name, model) == 0) break; } if (Models[i].name == NULL) { error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source()); return -1; } Model = i; Protocol = Models[Model].protocol; info("%s: using model '%s'", Name, Models[Model].name); /* initialize global variables */ DROWS = Models[Model].rows; DCOLS = Models[Model].cols; ret = 0; switch (Protocol) { case 1: ret = drv_BuE_MT_start(section); break; case 2: ret = drv_BuE_CT_start(section); break; } if (ret != 0) { return ret; } drv_BuE_clear(); return 0; }
/* start text mode display */ static int drv_EFN_start(const char *section) { int rows = -1, cols = -1; char *s; s = cfg_get(section, "Host", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Host' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%s", &Host) != 1) { error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); free(s); return -1; } if (cfg_number(section, "Port", 1000, 0, 65535, &Port) < 0) return -1; s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%dx%d", &cols, &rows) != 2 || rows < 1 || cols < 1) { error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); free(s); return -1; } DROWS = rows; DCOLS = cols; /* open communication with the display */ if (drv_EFN_open(section) < 0) { return -1; } /* initialize display */ drv_EFN_clear(); /* clear display */ return 0; }
static int drv_Pertelian_start(const char *section) { int backlight; int rows = -1, cols = -1; char *s; char cmd[12] = ""; s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%dx%d", &cols, &rows) != 2 || rows < 1 || cols < 1) { error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); free(s); return -1; } DROWS = rows; DCOLS = cols; /* open communication with the display */ if (drv_Pertelian_open(section) < 0) { return -1; } /* reset & initialize display */ cmd[0] = PERTELIAN_LCDCOMMAND; cmd[1] = 0x38; cmd[2] = PERTELIAN_LCDCOMMAND; cmd[3] = 0x06; cmd[4] = PERTELIAN_LCDCOMMAND; cmd[5] = 0x10; /* move cursor on data write */ cmd[6] = PERTELIAN_LCDCOMMAND; cmd[7] = 0x0c; cmd[8] = 0x0c; drv_Pertelian_send(cmd, 8); if (cfg_number(section, "Backlight", 0, 0, 1, &backlight) > 0) { drv_Pertelian_backlight(backlight); } drv_Pertelian_clear(); /* clear display */ return 0; }
static int drv_TF_start(const char *section, const int quiet) { int backlight; int rows = -1, cols = -1; char *s; s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } if (sscanf(s, "%dx%d", &cols, &rows) != 2 || drv_TF_valid_resolution(rows, cols) < 0) { error("%s: bad %s.Size '%s' (only 8x1/16x2/20x4) from %s", Name, section, s, cfg_source()); free(s); return -1; } DROWS = rows; DCOLS = cols; if (drv_TF_open() < 0) { error("%s: could not find a TREFON USB LCD", Name); return -1; } if (cfg_number(section, "Backlight", 1, 0, 1, &backlight) > 0) { drv_TF_backlight(backlight); } drv_TF_clear(); /* clear display */ if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_text_greet(buffer, "www.trefon.de")) { sleep(3); drv_TF_clear(); } } return 0; }
/* start graphic display */ static int drv_st2205_start2(const char *section) { char *s; 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; } 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; } /* Fixme: provider other fonts someday... */ if (XRES != 6 && YRES != 8) { error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source()); return -1; } /* open communication with the display */ if (drv_st2205_open(section) < 0) { return -1; } /* you surely want to allocate a framebuffer or something... */ fb = malloc(h->height * h->width * 3); /* set width/height from st2205 firmware specs */ DROWS = h->height; DCOLS = h->width; return 0; }
static int drv_st2205_open(const char *section) { char *dev; dev = cfg_get(section, "Port", NULL); if (dev == NULL || *dev == '\0') { error("st2205: no '%s.Port' entry from %s", section, cfg_source()); return -1; } h = st2205_open(dev); if (h == NULL) { error("st2205: cannot open st2205 device %s", dev); return -1; } return 0; }
static int drv_MO_start(const char *section, const int quiet) { int i; char *model; char buffer[256]; model = cfg_get(section, "Model", NULL); if (model != NULL && *model != '\0') { for (i = 0; Models[i].type != 0xff; i++) { if (strcasecmp(Models[i].name, model) == 0) break; } if (Models[i].type == 0xff) { error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source()); return -1; } Model = i; info("%s: using model '%s'", Name, Models[Model].name); } else { info("%s: no '%s.Model' entry from %s, auto-dedecting", Name, section, cfg_source()); Model = -1; } if (Model != -1 && Models[Model].protocol == 3) { // Sure electronics USB LCD board - full line output int i, j; for (i = 0; i < Models[Model].rows; i++) { // Clear buffer for (j = 0; j < Models[Model].cols; j++) { dispBuffer[i][j] = ' '; } } } if (drv_generic_serial_open(section, Name, 0) < 0) return -1; if (Model == -1 || Models[Model].protocol > 1) { /* read module type */ drv_generic_serial_write("\3767", 2); usleep(1000); if (drv_generic_serial_read(buffer, 1) == 1) { for (i = 0; Models[i].type != 0xff; i++) { if (Models[i].type == (int) *buffer) break; } info("%s: display reports model '%s' (type 0x%02x)", Name, Models[i].name, Models[i].type); /* auto-dedection */ if (Model == -1) Model = i; /* auto-dedection matches specified model? */ if (Models[i].type != 0xff && Model != i) { error("%s: %s.Model '%s' from %s does not match dedected Model '%s'", Name, section, model, cfg_source(), Models[i].name); return -1; } } else { info("%s: display detection failed.", Name); } } /* initialize global variables */ DROWS = Models[Model].rows; DCOLS = Models[Model].cols; GPIS = Models[Model].gpis; GPOS = Models[Model].gpos; Protocol = Models[Model].protocol; if (Protocol > 1) { /* read serial number */ drv_generic_serial_write("\3765", 2); usleep(100000); if (drv_generic_serial_read(buffer, 2) == 2) { info("%s: display reports serial number 0x%x", Name, *(short *) buffer); } /* read version number */ drv_generic_serial_write("\3766", 2); usleep(100000); if (drv_generic_serial_read(buffer, 1) == 1) { info("%s: display reports firmware version 0x%x", Name, *buffer); } } drv_MO_clear(); drv_generic_serial_write("\376B", 3); /* backlight on */ drv_generic_serial_write("\376K", 2); /* cursor off */ drv_generic_serial_write("\376T", 2); /* blink off */ drv_generic_serial_write("\376D", 2); /* line wrapping off */ drv_generic_serial_write("\376R", 2); /* auto scroll off */ /* set contrast */ if (cfg_number(section, "Contrast", 0, 0, 255, &i) > 0) { drv_MO_contrast(i); } /* set backlight */ if (cfg_number(section, "Backlight", 0, 0, 255, &i) > 0) { drv_MO_backlight(i); } if (!quiet) { if (drv_generic_text_greet(Models[Model].name, "MatrixOrbital")) { sleep(3); drv_MO_clear(); } } return 0; }
int drv_generic_serial_open(const char *section, const char *driver, const unsigned int flags) { int i, fd; pid_t pid; struct termios portset; char *LockPath; char *portName; int lock_len; Section = (char *) section; Driver = (char *) driver; Port = cfg_get(section, "Port", NULL); if (Port == NULL || *Port == '\0') { error("%s: no '%s.Port' entry from %s", Driver, section, cfg_source()); return -1; } if (strncmp(Port, "/dev/", 5) == 0) { portName = Port + 5; } else { portName = Port; } while (*portName == '/') portName++; LockPath = cfg_get(section, "LockPath", NULL); if (LockPath == NULL) { LockPath = strdup(DEFAULT_LOCK_PATH); } lock_len = strlen(LockPath) + strlen("/LCK..") + strlen(portName) + 1; Lock = malloc(lock_len); qprintf(Lock, lock_len, "%s%s%s", LockPath, "/LCK..", portName); free(LockPath); if (cfg_number(section, "Speed", 19200, 1200, 230400, &i) < 0) return -1; switch (i) { case 1200: Speed = B1200; break; case 2400: Speed = B2400; break; case 4800: Speed = B4800; break; case 9600: Speed = B9600; break; case 19200: Speed = B19200; break; case 38400: Speed = B38400; break; case 57600: Speed = B57600; break; case 115200: Speed = B115200; break; #ifdef B230400 case 230400: Speed = B230400; break; #endif default: error("%s: unsupported speed '%d' from %s", Driver, i, cfg_source()); return -1; } info("%s: using port '%s' at %d baud", Driver, Port, i); if ((pid = drv_generic_serial_lock_port(Port)) != 0) { if (pid == -1) error("%s: port %s could not be locked", Driver, Port); else error("%s: port %s is locked by process %d", Driver, Port, pid); return -1; } fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { error("%s: open(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } if (tcgetattr(fd, &portset) == -1) { error("%s: tcgetattr(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } cfmakeraw(&portset); portset.c_cflag |= flags; cfsetispeed(&portset, Speed); cfsetospeed(&portset, Speed); if (tcsetattr(fd, TCSANOW, &portset) == -1) { error("%s: tcsetattr(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } Device = fd; return Device; }
/* start graphic display */ static int drv_PICGraphic_start2(const char *section) { char *s; char cmd[2]; int contrast, status, tick, tack; /* read display size from config */ s = cfg_get(section, "Size", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Size' entry from %s", Name, section, cfg_source()); return -1; } DROWS = -1; DCOLS = -1; if (sscanf(s, "%dx%d", &DCOLS, &DROWS) != 2 || DCOLS < 1 || DROWS < 1) { error("%s: bad Size '%s' from %s", Name, s, cfg_source()); return -1; } 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; } 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; } if (XRES != 6 && YRES != 8) { error("%s: bad Font '%s' from %s (only 6x8 at the moment)", Name, s, cfg_source()); return -1; } /* you surely want to allocate a framebuffer or something... */ fbPG = calloc(DCOLS * DROWS / 8, 1); if (!fbPG) { error("failed to allocate framebuffer"); return -1; } info("allocated framebuffer with size %d", DCOLS * DROWS / 8); if (cfg_number("Variables", "tick", 500, 100, 0, &tick) > 0 && cfg_number("Variables", "tack", 500, 100, 0, &tack) > 0) { info("tick & tack read from config"); timer_add(drv_PICGraphic_delay, 0, min(tick, tack), 0); // } else { info("tick & tack not read from config"); timer_add(drv_PICGraphic_delay, 0, 80, 0); // } /* open communication with the display */ if (drv_PICGraphic_open(section) < 0) { return -1; } /* reset & initialize display */ cmd[0] = 'i'; drv_PICGraphic_send(cmd, 1); usleep(10000); // wait for reception of confirmation code status = drv_PICGraphic_recv(cmd, 2, "fi"); if (!status) { info("received fi from device"); } else { info("did not receive fi from device"); } if (cfg_number(section, "Contrast", 8, 0, 15, &contrast) > 0) { drv_PICGraphic_contrast(contrast); } return 0; }
int drv_generic_serial_open(const char *section, const char *driver, const unsigned int flags) { int i, fd; pid_t pid; struct termios portset; Section = (char *) section; Driver = (char *) driver; Port = cfg_get(section, "Port", NULL); if (Port == NULL || *Port == '\0') { error("%s: no '%s.Port' entry from %s", Driver, section, cfg_source()); return -1; } if (cfg_number(section, "Speed", 19200, 1200, 230400, &i) < 0) return -1; switch (i) { case 1200: Speed = B1200; break; case 2400: Speed = B2400; break; case 4800: Speed = B4800; break; case 9600: Speed = B9600; break; case 19200: Speed = B19200; break; case 38400: Speed = B38400; break; case 57600: Speed = B57600; break; case 115200: Speed = B115200; break; #ifdef B230400 case 230400: Speed = B230400; break; #endif default: error("%s: unsupported speed '%d' from %s", Driver, i, cfg_source()); return -1; } info("%s: using port '%s' at %d baud", Driver, Port, i); if ((pid = drv_generic_serial_lock_port(Port)) != 0) { if (pid == -1) error("%s: port %s could not be locked", Driver, Port); else error("%s: port %s is locked by process %d", Driver, Port, pid); return -1; } fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { error("%s: open(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } if (tcgetattr(fd, &portset) == -1) { error("%s: tcgetattr(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } cfmakeraw(&portset); portset.c_cflag |= flags; cfsetispeed(&portset, Speed); cfsetospeed(&portset, Speed); if (tcsetattr(fd, TCSANOW, &portset) == -1) { error("%s: tcsetattr(%s) failed: %s", Driver, Port, strerror(errno)); drv_generic_serial_unlock_port(Port); return -1; } Device = fd; return Device; }
/* start graphic display */ static int drv_dpf_start(const char *section) { int i; char *dev; char *s; // Check if config is valid // 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; } // 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; } 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; } /* 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; } /* 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; } // 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; else 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; else 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; } // 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; // 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 dpf.minx = 0; dpf.maxx = dpf.pwidth - 1; dpf.miny = 0; dpf.maxy = dpf.pheight - 1; // set the logical width/height for lcd4linux DCOLS = ((!dpf.rotate90) ? dpf.pwidth : dpf.pheight); DROWS = ((!dpf.rotate90) ? dpf.pheight : dpf.pwidth); // Set backlight (brightness) dpf_ax_setbacklight(dpf.dpfh, dpf.backlight); return 0; }
static int configure_mysql(void) { static int configured = 0; char server[256]; int port; char user[128]; char password[256]; char database[256]; char *s; if (configured != 0) return configured; s = cfg_get(Section, "server", "localhost"); if (*s == '\0') { info("[MySQL] empty '%s.server' entry from %s, assuming 'localhost'", Section, cfg_source()); strcpy(server, "localhost"); } else strcpy(server, s); free(s); if (cfg_number(Section, "port", 0, 1, 65536, &port) < 1) { /* using 0 as default port because mysql_real_connect() will convert it to real default one */ info("[MySQL] no '%s.port' entry from %s using MySQL's default", Section, cfg_source()); } s = cfg_get(Section, "user", ""); if (*s == '\0') { /* If user is NULL or the empty string "", the lcd4linux Unix user is assumed. */ info("[MySQL] empty '%s.user' entry from %s, assuming lcd4linux owner", Section, cfg_source()); strcpy(user, ""); } else strcpy(user, s); free(s); s = cfg_get(Section, "password", ""); /* Do not encrypt the password because encryption is handled automatically by the MySQL client API. */ if (*s == '\0') { info("[MySQL] empty '%s.password' entry in %s, assuming none", Section, cfg_source()); strcpy(password, ""); } else strcpy(password, s); free(s); s = cfg_get(Section, "database", ""); if (*s == '\0') { error("[MySQL] no '%s:database' entry from %s, specify one", Section, cfg_source()); free(s); configured = -1; return configured; } strcpy(database, s); free(s); mysql_init(&conex); if (!mysql_real_connect(&conex, server, user, password, database, port, NULL, 0)) { error("[MySQL] conection error: %s", mysql_error(&conex)); configured = -1; return configured; } configured = 1; return configured; }
static int drv_BuE_CT_start(const char *section) { char buffer[16]; char *size; int i, len; if (drv_generic_serial_open(section, Name, 0) < 0) return -1; #if 0 /* restart terminal */ drv_generic_serial_write(ESC "Kr", 3); usleep(10000); #endif /* Fixme: the CT does not return a serial number in byte mode */ /* set parameter mode 'decimal' */ drv_generic_serial_write(ESC "KM\073", 4); /* read version */ drv_generic_serial_write(ESC "?V", 3); usleep(100000); if ((len = drv_generic_serial_read(buffer, -1 * (int) sizeof(buffer))) > 0) { int v, r, s; if (sscanf(buffer, "V:%d.%d,%d;", &v, &r, &s) != 3) { error("%s: error parsing display identification <%*s>", Name, len, buffer); } else { info("%s: display identified as version %d.%d, S/N %d", Name, v, r, s); } } /* set parameter mode 'byte' */ drv_generic_serial_write(ESC "KM\072", 4); /* the CT20x4 can control smaller displays, too */ size = cfg_get(section, "Size", NULL); if (size != NULL && *size != '\0') { int r, c; char cmd[6] = ESC "LArc"; if (sscanf(size, "%dx%d", &c, &r) != 2 || r < 1 || c < 1) { error("%s: bad %s.Size '%s' from %s", Name, section, size, cfg_source()); return -1; } info("%s: display size: %d rows %d columns", Name, r, c); /* set display size */ cmd[3] = (char) r; cmd[4] = (char) c; drv_generic_serial_write(cmd, 5); DCOLS = c; DROWS = r; } /* set contrast */ if (cfg_number(section, "Contrast", 7, 0, 15, &i) > 0) { drv_BuE_CT_contrast(i); } /* set backlight */ if (cfg_number(section, "Backlight", 0, 0, 1, &i) > 0) { drv_BuE_CT_backlight(i); } /* identify modules */ for (i = 0; i < 8; i++) { char cmd[5] = ESC "K?Pn"; cmd[4] = (char) i; drv_generic_serial_write(cmd, 5); /* query I/O port */ usleep(10000); if ((len = drv_generic_serial_read(buffer, 4)) == 4) { char *type = NULL; if (i == 0) { if (buffer[3] == 8) { /* internal port */ type = "CT 20x4 internal port"; } else { error("%s: internal error: port 0 type %d should be type 8", Name, buffer[3]); continue; } } else { switch (buffer[3]) { case 1: /* Key Module */ type = "XM-KEY-2x4-LED"; break; case 8: /* I/O Module */ type = "XM-IO8-T"; break; case 9: /* I/O Module */ type = "XM-IO4-R"; break; case 15: /* nothing */ continue; default: /* unhandled */ type = NULL; break; } } if (type != NULL) { info("%s: Port %d: %s", Name, i, type); } else { error("%s: internal error: port %d unknown type %d", Name, i, cmd[3]); } } else { error("%s: error fetching type of port %d", Name, i); } } return 0; }
static int drv_LL_start(const char *section, const int quiet) { char *s; int rows = -1, cols = -1; int use_busy = 0, bus4bits = 0, commit = 0; struct lcd_parameters buf; /* emit version information */ info("%s: Version %s", Name, LCD_LINUX_VERSION); /* get size from config file */ s = cfg_get(section, "Size", NULL); if (s != NULL || *s != '\0') { if (sscanf(s, "%dx%d", &cols, &rows) != 2 || rows < 1 || cols < 1) { error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source()); free(s); return -1; } } free(s); /* open device */ lcdlinux_fd = open(Device, O_WRONLY); if (lcdlinux_fd == -1) { error("%s: open(%s) failed: %s", Name, Device, strerror(errno)); return -1; } /* get display size */ memset(&buf, 0, sizeof(buf)); if (ioctl(lcdlinux_fd, LCDL_GET_PARAM, &buf) != 0) { error("%s: ioctl(LCDL_GET_PARAM) failed: %s", Name, strerror(errno)); error("%s: Could not query display information!", Name); return -1; } info("%s: %dx%d display with %d controllers, flags=0x%02lx:", Name, buf.cntr_cols, buf.cntr_rows * buf.num_cntr, buf.num_cntr, buf.flags); info("%s: busy-flag checking %sabled", Name, (buf.flags & HD44780_CHECK_BF) ? "en" : "dis"); info("%s: bus width %d bits", Name, (buf.flags & HD44780_4BITS_BUS) ? 4 : 8); info("%s: font size %s", Name, (buf.flags & HD44780_5X10_FONT) ? "5x10" : "5x8"); /* overwrite width size from lcd4linux.conf */ if (buf.vs_rows || buf.vs_cols) { info("%s: disabling virtual screen", Name); buf.vs_rows = 0; buf.vs_cols = 0; commit = 1; } if ((rows > 0 && rows != buf.cntr_rows * buf.num_cntr) || (cols > 0 && cols != buf.cntr_cols)) { info("%s: changing size to %dx%d", Name, cols, rows); buf.cntr_rows = rows / buf.num_cntr; buf.cntr_cols = cols; commit = 1; } DROWS = buf.cntr_rows * buf.num_cntr; DCOLS = buf.cntr_cols; /* overwrite busy-flag checking from lcd4linux.conf */ cfg_number(section, "UseBusy", 0, 0, 1, &use_busy); if (use_busy && !(buf.flags & HD44780_CHECK_BF)) { info("%s: activating busy-flag checking", Name); buf.flags |= HD44780_CHECK_BF; commit = 1; } else if (!use_busy && (buf.flags & HD44780_CHECK_BF)) { info("%s: deactivating busy-flag checking", Name); buf.flags &= ~HD44780_CHECK_BF; commit = 1; } /* overwrite bus length from lcd4linux.conf */ cfg_number(section, "Bus4Bit", 0, 0, 1, &bus4bits); if (bus4bits && !(buf.flags & HD44780_4BITS_BUS)) { info("%s: setting bus length to 4 bits", Name); buf.flags |= HD44780_4BITS_BUS; commit = 1; } else if (!bus4bits && (buf.flags & HD44780_4BITS_BUS)) { info("%s: setting bus length to 8 bits", Name); buf.flags &= ~HD44780_4BITS_BUS; commit = 1; } if (commit && ioctl(lcdlinux_fd, LCDL_SET_PARAM, &buf) != 0) { error("%s: ioctl(LCDL_SET_PARAM) failed: %s", Name, strerror(errno)); return -1; } /* initialize display */ drv_LL_clear(); /* clear display */ /* Disable control characters interpretation. */ /* No return value check since this ioctl cannot fail */ ioctl(lcdlinux_fd, LCDL_RAW_MODE, 1); if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); if (drv_generic_text_greet(buffer, "lcd-linux.sf.net")) { sleep(3); drv_LL_clear(); } } return 0; }
int drv_generic_parport_open(const char *section, const char *driver) { char *s, *e; Section = (char *) section; Driver = (char *) driver; udelay_init(); #ifndef WITH_PPDEV error("The files include/linux/parport.h and/or include/linux/ppdev.h"); error("were missing at compile time. Even if your system supports"); error("ppdev, it will not be used."); error("You *really* should install these files and recompile LCD4linux!"); #endif s = cfg_get(Section, "Port", NULL); if (s == NULL || *s == '\0') { error("%s: no '%s.Port' entry from %s", Driver, Section, cfg_source()); return -1; } PPdev = NULL; if ((Port = strtol(s, &e, 0)) == 0 || *e != '\0') { #ifdef WITH_PPDEV Port = 0; PPdev = s; #else error("%s: bad %s.Port '%s' from %s", Driver, Section, s, cfg_source()); free(s); return -1; #endif } #ifdef WITH_PPDEV if (PPdev) { info("%s: using ppdev %s", Driver, PPdev); PPfd = open(PPdev, O_RDWR); if (PPfd == -1) { error("%s: open(%s) failed: %s", Driver, PPdev, strerror(errno)); return -1; } #if 0 /* PPEXCL fails if someone else uses the port (e.g. lp.ko) */ if (ioctl(PPfd, PPEXCL)) { info("%s: ioctl(%s, PPEXCL) failed: %s", PPdev, Driver, strerror(errno)); info("%s: could not get exclusive access to %s.", Driver, PPdev); } else { info("%s: got exclusive access to %s.", Driver, PPdev); } #endif if (ioctl(PPfd, PPCLAIM)) { error("%s: ioctl(%s, PPCLAIM) failed: %d %s", Driver, PPdev, errno, strerror(errno)); return -1; } } #endif #ifdef WITH_OUTB if (Port) { error("using raw port 0x%x (deprecated!)", Port); error("You *really* should change your setup and use ppdev!"); if ((Port + 3) <= 0x3ff) { if (ioperm(Port, 3, 1) != 0) { error("%s: ioperm(0x%x) failed: %s", Driver, Port, strerror(errno)); return -1; } } else { if (iopl(3) != 0) { error("%s: iopl(1) failed: %s", Driver, strerror(errno)); return -1; } } } #endif return 0; }