]> sigrok.org Git - libsigrokdecode.git/blobdiff - module_sigrokdecode.c
expose SRD_OUTPUT_* as symbols in the sigrokdecode module.
[libsigrokdecode.git] / module_sigrokdecode.c
index d4af5c344a4f40cba32b54156d759372bfe1fde8..9c8c72ef1c9f239e0687b96e1d0c797c5723303a 100644 (file)
@@ -128,7 +128,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
        case SRD_OUTPUT_PROTOCOL:
 
                /* TODO: SRD_OUTPUT_PROTOCOL should go up the PD stack. */
-               printf("%s protocol data: ", pdo->decoder->name);
+               printf("%s protocol data: ", pdo->protocol_id);
                PyObject_Print(data, stdout, Py_PRINT_RAW);
                puts("");
                break;
@@ -143,7 +143,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
 }
 
 
-static PyObject *Decoder_output_new(PyObject *self, PyObject *py_output_type)
+static PyObject *Decoder_output_new(PyObject *self, PyObject *args)
 {
        PyObject *ret;
        struct srd_decoder_instance *di;
@@ -155,11 +155,9 @@ static PyObject *Decoder_output_new(PyObject *self, PyObject *py_output_type)
 
        printf("output_new di %s\n", di->decoder->name);
 
-       if (!PyArg_ParseTuple(py_output_type, "i:output_type", &output_type))
+       if (!PyArg_ParseTuple(args, "is", &output_type, &protocol_id))
                return NULL;
 
-       /* TODO: take protocol_id from python */
-       protocol_id = "i2c";
        pdo_id = pd_output_new(di, output_type, protocol_id);
        if (pdo_id < 0)
                Py_RETURN_NONE;
@@ -222,6 +220,17 @@ PyMODINIT_FUNC PyInit_sigrokdecode(void)
        if (PyModule_AddObject(mod, "srd_logic", (PyObject *)&srd_logic_type) == -1)
                return NULL;
 
+       /* expose output types as symbols in the sigrokdecode module */
+       if(PyModule_AddObject(mod, "SRD_OUTPUT_ANNOTATION",
+                       PyLong_FromLong(SRD_OUTPUT_ANNOTATION)) == -1)
+               return NULL;
+       if(PyModule_AddObject(mod, "SRD_OUTPUT_PROTOCOL",
+                       PyLong_FromLong(SRD_OUTPUT_PROTOCOL)) == -1)
+               return NULL;
+       if(PyModule_AddObject(mod, "SRD_OUTPUT_BINARY",
+                       PyLong_FromLong(SRD_OUTPUT_BINARY)) == -1)
+               return NULL;
+
        return mod;
 }