upiwin/src/ep_upiwin.c
2019-12-10 12:42:58 -07:00

97 lines
3.0 KiB
C

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "scode.h"
#include "msg.h"
#include "gpio.h"
#include "ep_init.h"
#include "ep_upiwin.h"
#include "ep_util.h"
#include "devctxt.h"
static PyMethodDef UPIWINMethods[] = {
/* Backlight control functions */
{"get_backlight", Epython_get_backlight, METH_VARARGS,
"Returns the current status of the backlight (True=on, False=off)."},
{"set_backlight", Epython_set_backlight, METH_VARARGS,
"Sets the current status of the backlight (True=on, False=off). Returns a SCODE."},
{"get_backlight_level", Epython_get_backlight_level, METH_VARARGS,
"Returns the current intensity level of the backlight."},
{"set_backlight_level", Epython_set_backlight_level, METH_VARARGS,
"Sets the current intensity level of the backlight. Returns a SCODE."},
/* Message functions */
{"get_message", Epython_get_message, METH_VARARGS,
"Retrieves a message from the message queue, blocking if necessary."},
{"post_quit_message", Epython_post_quit_message, METH_VARARGS,
"Posts a WM_QUIT message to the message queue, with an exit code."},
{NULL, NULL, 0, NULL}
};
static PyModuleDef DefUPIWIN = {
PyModuleDef_HEAD_INIT, /* standard garbage */
MOD_NAME_UPIWIN, /* module name */
NULL, /* no doc string */
sizeof(UPIWIN_STATE), /* per-module memory */
UPIWINMethods, /* method defs */
NULL, /* no slots for multi-phase init */
NULL, /* no traversal proc */
NULL, /* no clear function */
NULL /* no free function */
};
BEGIN_CONSTANT_TABLE(UPIWINConstants)
/* Message constants */
CONSTANT_INT_MACRO(WM_NULL)
CONSTANT_INT_MACRO(WM_QUIT)
CONSTANT_INT_MACRO(WM_HWBUTTONDOWN)
CONSTANT_INT_MACRO(WM_HWBUTTONUP)
CONSTANT_INT_MACRO(WM_TOUCHDOWN)
CONSTANT_INT_MACRO(WM_TOUCHMOVE)
CONSTANT_INT_MACRO(WM_TOUCHUP)
/* Raster op constants */
CONSTANT_INT_MACRO(R2_BLACK)
CONSTANT_INT_MACRO(R2_NOTMERGEPEN)
CONSTANT_INT_MACRO(R2_MASKNOTPEN)
CONSTANT_INT_MACRO(R2_NOTCOPYPEN)
CONSTANT_INT_MACRO(R2_MASKPENNOT)
CONSTANT_INT_MACRO(R2_NOT)
CONSTANT_INT_MACRO(R2_XORPEN)
CONSTANT_INT_MACRO(R2_NOTMASKPEN)
CONSTANT_INT_MACRO(R2_MASKPEN)
CONSTANT_INT_MACRO(R2_NOTXORPEN)
CONSTANT_INT_MACRO(R2_NOP)
CONSTANT_INT_MACRO(R2_MERGENOTPEN)
CONSTANT_INT_MACRO(R2_COPYPEN)
CONSTANT_INT_MACRO(R2_MERGEPENNOT)
CONSTANT_INT_MACRO(R2_MERGEPEN)
CONSTANT_INT_MACRO(R2_WHITE)
END_CONSTANT_TABLE
PyObject *Epython_init_upiwin_module(void)
{
PyObject *module;
PUPIWIN_STATE pstate;
module = PyModule_Create(&DefUPIWIN);
if (!module)
return NULL;
if (FAILED(Epython_register_constants(module, UPIWINConstants)))
{
Py_DECREF(module);
return NULL;
}
if (FAILED(Epython_register_devctxt(module)))
{
Py_DECREF(module);
return NULL;
}
/* set up the module state */
pstate = (PUPIWIN_STATE)PyModule_GetState(module);
pstate->backlight_on = TRUE;
pstate->backlight_level = GSB_BACKLIGHT_DEFAULT;
return module;
}