Ejemplo n.º 1
0
static int drv_MO_backlight(int backlight)
{
    static unsigned char Backlight = 0;
    char cmd[3] = "\376Bn";

    /* -1 is used to query the current backlight */
    if (backlight == -1)
	return Backlight;

    if (backlight < 0)
	backlight = 0;
    if (backlight > 255)
	backlight = 255;
    Backlight = backlight;

    if (backlight <= 0) {
	/* backlight off */
	drv_generic_serial_write("\376F", 2);
    } else {
	/* backlight on for n minutes */
	cmd[2] = Backlight;
	drv_generic_serial_write(cmd, 3);
    }

    return Backlight;
}
Ejemplo n.º 2
0
static void drv_BuE_CT_write(const int row, const int col, const char *data, const int len)
{
    char cmd[] = ESC "LCzs\001";
    cmd[3] = (char) row + 1;
    cmd[4] = (char) col + 1;

    drv_generic_serial_write(cmd, 6);
    drv_generic_serial_write(data, len);

}
Ejemplo n.º 3
0
static void drv_BuE_MT_write(const int row, const int col, const char *data, const int len)
{
    char cmd[] = ESC "[y;xH";

    cmd[2] = (char) row;
    cmd[4] = (char) col;

    drv_generic_serial_write(cmd, 6);
    drv_generic_serial_write(data, len);
}
Ejemplo n.º 4
0
static void drv_BuE_clear(void)
{
    switch (Protocol) {
    case 1:
	drv_generic_serial_write(ESC "&#", 3);	/* clear display */
	break;
    case 2:
	drv_generic_serial_write(ESC "LL", 3);	/* clear display */
	break;
    }
}
Ejemplo n.º 5
0
static int drv_BuE_MT_start(const char *section)
{
    char cmd[] = ESC "&sX";

    /* CSTOPB: 2 stop bits */
    if (drv_generic_serial_open(section, Name, CSTOPB) < 0)
	return -1;

    cmd[4] = Models[Model].type;
    drv_generic_serial_write(cmd, 4);	/* select display type */
    drv_generic_serial_write(ESC "&D", 3);	/* cursor off */

    return 0;
}
Ejemplo n.º 6
0
static void drv_LT_clear(void)
{
    char cmd[1];

    cmd[0] = LCD_CLEAR;		/* clear display */
    drv_generic_serial_write(cmd, 1);	/* clear screen */
}
Ejemplo n.º 7
0
static int drv_BuE_CT_gpo(int num, int val)
{
    static int GPO[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
    char cmd[4] = ESC "Pnx";

    if (num < 0)
	num = 0;
    if (num > 7)
	num = 7;

    /* -1 is used to query the current GPO */
    if (val == -1)
	return GPO[num];

    if (val < 0)
	val = 0;
    if (val > 255)
	val = 255;
    GPO[num] = val;

    cmd[2] = (char) num;
    cmd[3] = (char) val;

    drv_generic_serial_write(cmd, 4);

    return GPO[num];
}
Ejemplo n.º 8
0
static void drv_MO_write(const int row, const int col, const char *data, const int len)
{
    char cmd[5] = "\376Gyx";

    if (Models[Model].protocol == 3) {	// Sure electronics USB LCD board - full line output
	cmd[2] = (char) 1;
	cmd[3] = (char) row + 1;
	strncpy(&(dispBuffer[row][col]), data, len);
	drv_generic_serial_write(cmd, 4);
	drv_generic_serial_write(dispBuffer[row], Models[Model].cols);
    } else {
	cmd[2] = (char) col + 1;
	cmd[3] = (char) row + 1;
	drv_generic_serial_write(cmd, 4);
	drv_generic_serial_write(data, len);
    }
}
Ejemplo n.º 9
0
static void drv_FW8888_send_cmd(const unsigned int cmd)
{
    char cmd_str[2];

    cmd_str[0] = 0x10;
    cmd_str[1] = cmd;
    drv_generic_serial_write(cmd_str, 2);
}
Ejemplo n.º 10
0
static int drv_MO_GPO(const int num, const int val)
{
    int v = 0;
    char cmd[4];

    switch (Protocol) {
    case 1:
	if (num == 0) {
	    if (val > 0) {
		v = 1;
		drv_generic_serial_write("\376W", 2);	/* GPO on */
	    } else {
		v = 0;
		drv_generic_serial_write("\376V", 2);	/* GPO off */
	    }
	}
	break;

    case 2:
	if (val <= 0) {
	    v = 0;
	    cmd[0] = '\376';
	    cmd[1] = 'V';	/* GPO off */
	    cmd[2] = (char) num + 1;
	    drv_generic_serial_write(cmd, 3);
	} else if (val >= 255) {
	    v = 255;
	    cmd[0] = '\376';
	    cmd[1] = 'W';	/* GPO on */
	    cmd[2] = (char) num + 1;
	    drv_generic_serial_write(cmd, 3);
	} else {
	    v = val;
	    cmd[0] = '\376';
	    cmd[1] = '\300';	/* PWM control */
	    cmd[2] = (char) num + 1;
	    cmd[3] = (char) v;
	    drv_generic_serial_write(cmd, 4);
	}
	break;
    }

    return v;
}
Ejemplo n.º 11
0
static int drv_LT_send(const char request, const char value)
{
    char buf[2];

    buf[0] = request;
    buf[1] = value;
    drv_generic_serial_write(buf, 2);

    return 0;
}
Ejemplo n.º 12
0
static void drv_MO_defchar(const int ascii, const unsigned char *matrix)
{
    int i;
    char cmd[11] = "\376N";

    cmd[2] = (char) ascii;
    for (i = 0; i < 8; i++) {
	cmd[i + 3] = matrix[i] & 0x1f;
    }
    drv_generic_serial_write(cmd, 11);
}
Ejemplo n.º 13
0
static void drv_FW8888_send_text(const char *text, const unsigned int len)
{
    unsigned int i;
    char cmd_str[2];

    cmd_str[0] = 0x12;

    for (i = 0; i < len; i++) {
	cmd_str[1] = text[i];
	drv_generic_serial_write(cmd_str, 2);
    }
}
Ejemplo n.º 14
0
static void drv_Pertelian_send(const char *data, const unsigned int len)
{
    unsigned int i;

    /* Pertelian interface seems to offer no buffering at all
       so we have to slow things down a tad yes 1usec is enough  */

    for (i = 0; i < len; i++) {
	drv_generic_serial_write(&data[i], 1);
	usleep(100);
    }
}
Ejemplo n.º 15
0
static void drv_PICGraphic_send(const char *data, const unsigned int len)
{
    unsigned int i;
    char hexDigits[3];
    hexDigits[2] = 0;
    drv_generic_serial_write(data, len);
    info("sending %d bytes: ", len);
    for (i = 0; i < min(10, len); i++) {	// min(10, len)
	convert2ASCII(data[i], hexDigits);
	debug("0x%s (%c)", hexDigits, data[i]);
    }
}
Ejemplo n.º 16
0
static void drv_MO_clear(void)
{
    int i, j;

    switch (Protocol) {
    case 1:
	drv_generic_serial_write("\014", 1);	/* Clear Screen */
	break;
    case 2:
	drv_generic_serial_write("\376\130", 2);	/* Clear Screen */
	break;

    case 3:
	/* Sure electronics USB LCD board - clear buffer */
	for (i = 0; i < Models[Model].rows; i++) {
	    for (j = 0; j < Models[Model].cols; j++) {
		dispBuffer[i][j] = ' ';
	    }
	    drv_MO_write(1, i + 1, dispBuffer[i], Models[Model].cols);
	}
	break;
    }
}
Ejemplo n.º 17
0
static void drv_BuE_MT_defchar(const int ascii, const unsigned char *matrix)
{
    int i;
    char cmd[22] = ESC "&T";	/* enter transparent mode */

    cmd[3] = '\0';		/* write cmd */
    cmd[4] = 0x40 | 8 * ascii;	/* write CGRAM */

    for (i = 0; i < 8; i++) {
	cmd[2 * i + 5] = '\1';	/* write data */
	cmd[2 * i + 6] = matrix[i] & 0x1f;	/* character bitmap */
    }
    cmd[21] = '\377';		/* leave transparent mode */

    drv_generic_serial_write(cmd, 22);
}
Ejemplo n.º 18
0
void drv_generic_serial_write_rts(const char *string, const int len)
{
    int serial, p, tocnt;

    for (p = 0; p < len; p++) {	/* Send Byte-by-Byte checking RTS-Line */
	/* Timeout is 500ms */
	tocnt = 250;		/* 250 * 2 */
	ioctl(Device, TIOCMGET, &serial);	/* Get status of Control Lines */
	while (!(serial & TIOCM_RTS) && tocnt) {	/* Wait until RTS is set or timeout */
	    tocnt--;		/* decrease timeout counter */
	    usleep(2000);	/* Wait two milliseconds */
	    ioctl(Device, TIOCMGET, &serial);
	}
	drv_generic_serial_write(&string[p], 1);	/* Actually send one byte */
    }
}
Ejemplo n.º 19
0
static void drv_BuE_CT_defchar(const int ascii, const unsigned char *matrix)
{
    int i;
    char cmd[13] = ESC "LZ";	/* set custom char */

    /* number of user-defined char (0..7) */
    cmd[3] = (char) ascii - CHAR0;

    /* ASCII code to replace */
    cmd[4] = (char) ascii;

    for (i = 0; i < 8; i++) {
	cmd[i + 5] = matrix[i] & 0x1f;
    }

    drv_generic_serial_write(cmd, 13);
}
Ejemplo n.º 20
0
static int drv_BuE_CT_adc(void)
{
    char buffer[4];

    drv_generic_serial_write(ESC "?A", 3);

    usleep(10000);

    if ((drv_generic_serial_read(buffer, 4) != 4) || (buffer[0] != 'A') || (buffer[1] != ':')
	) {
	error("%s: error reading ADC", Name);
	return -1;
    }

    /* 10 bit value: 8 bit high, 2 bit low */
    return 4 * (unsigned char) buffer[2] + (unsigned char) buffer[3];
}
Ejemplo n.º 21
0
static int drv_MO_contrast(int contrast)
{
    static unsigned char Contrast = 0;
    char cmd[3] = "\376Pn";

    /* -1 is used to query the current contrast */
    if (contrast == -1)
	return Contrast;

    if (contrast < 0)
	contrast = 0;
    if (contrast > 255)
	contrast = 255;
    Contrast = contrast;

    cmd[2] = Contrast;

    drv_generic_serial_write(cmd, 3);

    return Contrast;
}
Ejemplo n.º 22
0
static int drv_BuE_CT_contrast(int contrast)
{
    static char Contrast = 7;
    char cmd[4] = ESC "LKn";

    /* -1 is used to query the current contrast */
    if (contrast == -1)
	return Contrast;

    if (contrast < 0)
	contrast = 0;
    if (contrast > 15)
	contrast = 15;
    Contrast = contrast;

    cmd[3] = Contrast;

    drv_generic_serial_write(cmd, 4);

    return Contrast;
}
Ejemplo n.º 23
0
static int drv_BuE_CT_backlight(int backlight)
{
    static char Backlight = 0;
    char cmd[4] = ESC "LBn";

    /* -1 is used to query the current backlight */
    if (backlight == -1)
	return Backlight;

    if (backlight < 0)
	backlight = 0;
    if (backlight > 1)
	backlight = 1;
    Backlight = backlight;

    cmd[3] = Backlight;

    drv_generic_serial_write(cmd, 4);

    return Backlight;
}
Ejemplo n.º 24
0
static int drv_BuE_CT_pwm(int val)
{
    static int PWM = -1;
    char cmd[4] = ESC "Adm";

    /* -1 is used to query the current PWM */
    if (val == -1)
	return PWM;

    if (val < 0)
	val = 0;
    if (val > 255)
	val = 255;
    PWM = val;

    cmd[2] = (char) val;
    cmd[3] = val == 0 ? 1 : 2;
    drv_generic_serial_write(cmd, 4);

    return val;
}
Ejemplo n.º 25
0
static int drv_BuE_CT_gpi(int num)
{
    char cmd[4] = ESC "?Pn";
    char buffer[4];

    if (num < 0)
	num = 0;
    if (num > 7)
	num = 7;

    cmd[3] = (char) num;
    drv_generic_serial_write(cmd, 4);

    usleep(10000);

    if (drv_generic_serial_read(buffer, 4) != 4) {
	error("%s: error reading port %d", Name, num);
	return -1;
    }

    return buffer[3];
}
Ejemplo n.º 26
0
static int drv_MO_GPI(const int num)
{
    static int GPI[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
    static time_t T[8], now;


    if (num < 0 || num > 7) {
	return 0;
    }

    /* read RPM every two seconds */
    if (time(&now) - T[num] >= 2) {

	char cmd[3];
	unsigned char ans[7];

	T[num] = now;

	cmd[0] = '\376';
	cmd[1] = '\301';
	cmd[2] = (char) num + 1;
	drv_generic_serial_write(cmd, 3);
	usleep(100000);

	if (drv_generic_serial_read((char *) ans, 7) == 7) {
	    if (ans[0] == 0x23 && ans[1] == 0x2a && ans[2] == 0x03 && ans[3] == 0x52 && ans[4] == num + 1) {
		GPI[num] = 18750000 / (256 * ans[5] + ans[6]);
	    } else {
		error("%s: strange answer %02x %02x %02x %02x %02x %02x %02x", Name, ans[0], ans[1], ans[2], ans[3],
		      ans[4], ans[5], ans[6]);
	    }
	}
    }

    return GPI[num];
}
Ejemplo n.º 27
0
/* dummy function that sends something to the display */
static void drv_LW_ABP_send(const char *data, const unsigned int len)
{
    /* send data to the serial port is easy... */
    drv_generic_serial_write(data, len);
}
Ejemplo n.º 28
0
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;
}
Ejemplo n.º 29
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;
}
Ejemplo n.º 30
0
/* write data to the display */
static void drv_EA232graphic_send(const char *data, const int len)
{
    drv_generic_serial_write(data, len);
}