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 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 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 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; }
unsigned long timing(const char *driver, const char *section, const char *name, const int defval, const char *unit) { char sec[256]; int fuzz, val; qprintf(sec, sizeof(sec), "%s.Timing", section); /* fuzz all timings by given factor */ cfg_number(sec, "fuzz", 100, 1, -1, &fuzz); cfg_number(sec, name, defval, 0, -1, &val); val = val * fuzz / 100; if (val != defval) { if (fuzz != 100) { info("%s: timing: %6s = %5d %s (default %d %s, fuzz %d)", driver, name, val, unit, defval, unit, fuzz); } else { info("%s: timing: %6s = %5d %s (default %d %s)", driver, name, val, unit, defval, unit); } } else { info("%s: timing: %6s = %5d %s (default)", driver, name, defval, unit); } return val; }
/* 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; }
/* MUST NOT be declared 'static'! */ int plugin_init_raspi(void) { /* Check if raspi plugin section exists in config file */ if (cfg_number(Section, "enabled", 0, 0, 1, &plugin_enabled) < 1) { plugin_enabled = 0; } /* Disable plugin unless it is explicitly enabled */ if (plugin_enabled != 1) { info("[raspi] WARNING: Plugin is not enabled! (set 'enabled 1' to enable this plugin)"); return 0; } 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); } snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_TEMP_PATH, RASPI_TEMP_VALUE); if (0 == access(checkFile, R_OK)) { AddFunction("raspi::cputemp", 0, my_cputemp); } else { 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); } snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_FREQ_PATH, RASPI_FREQ_VALUE); if (0 == access(checkFile, R_OK)) { AddFunction("raspi::cpufreq", 0, my_cpufreq); } else { error("Error: File '%s' not readable, no frequency sensor found", checkFile); } 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; }
int drv_generic_graphic_init(const char *section, const char *driver) { int i, l; char *color; WIDGET_CLASS wc; Section = (char *) section; Driver = (char *) driver; /* init layout framebuffer */ LROWS = 0; LCOLS = 0; for (l = 0; l < LAYERS; l++) drv_generic_graphic_FB[l] = NULL; drv_generic_graphic_resizeFB(DROWS, DCOLS); /* sanity check */ for (l = 0; l < LAYERS; l++) { if (drv_generic_graphic_FB[l] == NULL) { error("%s: framebuffer could not be allocated: malloc() failed", Driver); return -1; } } /* init generic driver & register plugins */ drv_generic_init(); /* set default colors */ color = cfg_get(Section, "foreground", "000000ff"); if (color2RGBA(color, &FG_COL) < 0) { error("%s: ignoring illegal color '%s'", Driver, color); } if (color) free(color); color = cfg_get(Section, "background", "ffffff00"); if (color2RGBA(color, &BG_COL) < 0) { error("%s: ignoring illegal color '%s'", Driver, color); } if (color) free(color); color = cfg_get(Section, "basecolor", "ffffff"); if (color2RGBA(color, &BL_COL) < 0) { error("%s: ignoring illegal color '%s'", Driver, color); } if (color) free(color); /* inverted display? */ cfg_number(section, "inverted", 0, 0, 1, &INVERTED); /* register text widget */ wc = Widget_Text; wc.draw = drv_generic_graphic_draw; widget_register(&wc); /* register icon widget */ wc = Widget_Icon; wc.draw = drv_generic_graphic_icon_draw; widget_register(&wc); /* register bar widget */ wc = Widget_Bar; wc.draw = drv_generic_graphic_bar_draw; widget_register(&wc); /* register image widget */ #ifdef WITH_IMAGE wc = Widget_Image; wc.draw = drv_generic_graphic_image_draw; widget_register(&wc); #endif /* clear framebuffer but do not blit to display */ for (l = 0; l < LAYERS; l++) for (i = 0; i < LCOLS * LROWS; i++) drv_generic_graphic_FB[l][i] = NO_COL; 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; }
/* initialize driver & display */ int drv_LL_init(const char *section, const int quiet) { WIDGET_CLASS wc; int asc255bug; int ret; info("%s: %s", Name, "$Rev$"); /* display preferences */ XRES = 5; /* pixel width of one char */ YRES = 8; /* pixel height of one char */ CHARS = 8; /* number of user-defineable characters */ CHAR0 = 0; /* ASCII of first user-defineable char */ GOTO_COST = -1; /* number of bytes a goto command requires */ /* real worker functions */ drv_generic_text_real_write = drv_LL_write; drv_generic_text_real_defchar = drv_LL_defchar; /* start display */ if ((ret = drv_LL_start(section, quiet)) != 0) return ret; /* initialize generic text driver */ if ((ret = drv_generic_text_init(section, Name)) != 0) return ret; /* initialize generic icon driver */ if ((ret = drv_generic_text_icon_init()) != 0) return ret; /* initialize generic bar driver */ if ((ret = drv_generic_text_bar_init(0)) != 0) return ret; /* add fixed chars to the bar driver */ /* most displays have a full block on ascii 255, but some have kind of */ /* an 'inverted P'. If you specify 'asc255bug 1 in the config, this */ /* char will not be used, but rendered by the bar driver */ cfg_number(section, "asc255bug", 0, 0, 1, &asc255bug); drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */ if (!asc255bug) drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */ /* register text widget */ wc = Widget_Text; wc.draw = drv_generic_text_draw; widget_register(&wc); /* register icon widget */ wc = Widget_Icon; wc.draw = drv_generic_text_icon_draw; widget_register(&wc); /* register bar widget */ wc = Widget_Bar; wc.draw = drv_generic_text_bar_draw; widget_register(&wc); /* register plugins */ /* none */ 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; }
/* 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 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; }
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; }
/* 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; }