/* Copyright 2006 iTuner Corporation */ /* npavel@ituner.com */ #include // #include #include #include #include #include #include "usblcd.h" #include "widgets.h" #include "usblcd_util.h" static usblcd_operations *mylcd; static PyObject * usblcd_open(PyObject *self, PyObject *args) { /* init hid device and usblcd_operations structure */ mylcd = new_usblcd_operations(); /* set hid debug level */ mylcd->hid->debug(0); /* set usblcd debug level */ mylcd->debug(0); /* init the USB LCD */ mylcd->init(mylcd); /* set default cursor */ mylcd->set_cursor(mylcd, 0); /* set default non blink cursor */ mylcd->set_cursor_blink(mylcd, 0); return Py_BuildValue("i", 0); } static PyObject * usblcd_close(PyObject *self, PyObject *args) { mylcd->close(mylcd); return Py_BuildValue("i", 0); } static PyObject * usblcd_backlight(PyObject *self, PyObject *args) { int value; if (!PyArg_ParseTuple(args, "i", &value)) return NULL; mylcd->backlight(mylcd, value); return Py_BuildValue("i", 0); } static PyObject * usblcd_contrast(PyObject *self, PyObject *args) { int value; if (!PyArg_ParseTuple(args, "i", &value)) return NULL; mylcd->contrast(mylcd, value); return Py_BuildValue("i", 0); } static PyObject * usblcd_text(PyObject *self, PyObject *args) { int row; int column; char *text; if (!PyArg_ParseTuple(args, "iis", &row, &column, &text)) return NULL; mylcd->settext(mylcd, row, column, text); return Py_BuildValue("i", 0); } static PyObject * usblcd_led(PyObject *self, PyObject *args) { int led; int state; if (!PyArg_ParseTuple(args, "ii", &led, &state)) return NULL; mylcd->setled(mylcd, led, state); return Py_BuildValue("i", 0); } static PyObject * usblcd_clear(PyObject *self, PyObject *args) { mylcd->clear(mylcd); return Py_BuildValue("i", 0); } static PyObject * usblcd_read(PyObject *self, PyObject *args) { unsigned int key =0; unsigned int state; mylcd->keyevents(mylcd, &key, &state); return Py_BuildValue("i", key); } /* if (strncmp(s, "histo", 5) == 0) { histo_opts options; int values[64],i; srand((unsigned)time(0)); // left to right histo with text options.width = 20; options.height = 2; options.orientation = 0; options.valuetype = 0; options.barwidth = 5; options.barspacing = 0; for (i=0;i<64;i++) values[i] = (int)(16*(rand()/(RAND_MAX+1.0))); histo(mylcd, 0, 0, options, 20, values); } if (strncmp(s, "smallhisto", 10) == 0) { histo_opts options; int values[64],i; srand((unsigned)time(0)); // left to right histo with text options.width = 4; options.height = 2; options.orientation = 0; options.valuetype = 0; options.barwidth = 1; options.barspacing = 0; for (i=0;i<64;i++) values[i] = (int)(16*(rand()/(RAND_MAX+1.0))); histo(mylcd, 0, 0, options, 20, values); } arg++; } // mylcd->setchar(mylcd, 0, 1, 255); mylcd->setfont(mylcd,"../doc/examples/bigfonts/mail.fnt"); mylcd->setchar(mylcd, 0, 0, 0); mylcd->setchar(mylcd, 1, 0, 1); mylcd->setchar(mylcd, 0, 1, 2); mylcd->setchar(mylcd, 1, 1, 3); mylcd->setchar(mylcd, 0, 2, 4); mylcd->setchar(mylcd, 1, 2, 5); mylcd->setchar(mylcd, 0, 3, 6); mylcd->setchar(mylcd, 1, 3, 7); */ static PyMethodDef usblcdMethods[] = { {"open", usblcd_open, METH_VARARGS, "Open usb connection."}, {"close", usblcd_close, METH_VARARGS, "Close usb connection."}, {"backlight", usblcd_backlight, METH_VARARGS, "Set backlight status."}, {"contrast", usblcd_contrast, METH_VARARGS, "Set display contrast."}, {"text", usblcd_text, METH_VARARGS, "Set display text."}, {"led", usblcd_led, METH_VARARGS, "Set LED status."}, {"clear", usblcd_clear, METH_VARARGS, "Clear display."}, {"read", usblcd_read, METH_VARARGS, "Read button status."}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC initusblcd(void) { (void) Py_InitModule("usblcd", usblcdMethods); }