2019-12-07 20:53:59 -07:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
|
|
#include <Python.h>
|
|
|
|
#include "scode.h"
|
2019-12-09 13:29:37 -07:00
|
|
|
#include "msg.h"
|
2019-12-07 20:53:59 -07:00
|
|
|
#include "gpio.h"
|
2019-12-09 13:29:37 -07:00
|
|
|
#include "ep_init.h"
|
2019-12-07 20:53:59 -07:00
|
|
|
#include "ep_upiwin.h"
|
2019-12-09 13:29:37 -07:00
|
|
|
#include "ep_util.h"
|
2019-12-10 12:42:58 -07:00
|
|
|
#include "devctxt.h"
|
2019-12-07 20:53:59 -07:00
|
|
|
|
|
|
|
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."},
|
2019-12-09 13:29:37 -07:00
|
|
|
/* 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."},
|
2019-12-07 20:53:59 -07:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyModuleDef DefUPIWIN = {
|
2019-12-07 20:59:18 -07:00
|
|
|
PyModuleDef_HEAD_INIT, /* standard garbage */
|
2019-12-07 21:18:27 -07:00
|
|
|
MOD_NAME_UPIWIN, /* module name */
|
2019-12-07 20:59:18 -07:00
|
|
|
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 */
|
2019-12-07 20:53:59 -07:00
|
|
|
};
|
|
|
|
|
2019-12-09 13:29:37 -07:00
|
|
|
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)
|
2019-12-10 12:42:58 -07:00
|
|
|
/* 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)
|
2019-12-09 13:29:37 -07:00
|
|
|
END_CONSTANT_TABLE
|
|
|
|
|
2019-12-07 20:53:59 -07:00
|
|
|
PyObject *Epython_init_upiwin_module(void)
|
|
|
|
{
|
|
|
|
PyObject *module;
|
|
|
|
PUPIWIN_STATE pstate;
|
|
|
|
|
|
|
|
module = PyModule_Create(&DefUPIWIN);
|
|
|
|
if (!module)
|
|
|
|
return NULL;
|
2019-12-09 13:29:37 -07:00
|
|
|
|
|
|
|
if (FAILED(Epython_register_constants(module, UPIWINConstants)))
|
|
|
|
{
|
|
|
|
Py_DECREF(module);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-12-10 12:42:58 -07:00
|
|
|
|
|
|
|
if (FAILED(Epython_register_devctxt(module)))
|
|
|
|
{
|
|
|
|
Py_DECREF(module);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-12-07 20:53:59 -07:00
|
|
|
|
|
|
|
/* set up the module state */
|
|
|
|
pstate = (PUPIWIN_STATE)PyModule_GetState(module);
|
|
|
|
pstate->backlight_on = TRUE;
|
|
|
|
pstate->backlight_level = GSB_BACKLIGHT_DEFAULT;
|
|
|
|
|
|
|
|
return module;
|
|
|
|
}
|