I'm not 100% sure where to put this. I need some way to grab a screenshot from my TI 84+CE from the terminal. I am trying to make a "calculator printer." I am planning on using a raspberry pi zero and a thermal printer. The only problem is TILP seems to only be able to grab screenshots from the gui. I'd like to be able to just plug in the calculator and press a button to spit it out. Is there some way I can directly get a screenshot through TILP in the terminal, just talk directly to the calculator, or is there another program I can use? Thanks!
Unsure what you've found already, so just reporting the results of my own exploration (reading the source):

If you specify one or more filenames on the command line it runs in a non-interactive mode, determining what exactly to do based on filenames. For most kinds of files it attempts to send them to the calculator, which isn't very helpful to you.

From there I guess we want to figure out how TiLP gets screenshots, and that's pretty easy- it's all in the screen_capture function, where the heavy lifting is in libticalcs: ticalc_calc_recv_screen.

So your options are probably either to hack TiLP to support non-interactive functions beyond sending files, or write a program that does exactly what you want with libticalcs directly. I'd lean toward the latter. In a quick search I found somebody's Python bindings that might make throwing something together rather easier than writing a pile of C.
Tari:
I agree that CITI looks to be my best option. I am having problems finding much documentation at all on it though. I wasn't sure where to start with trying it. From the readme I found I needed

Code:
import cyti
calculator = cyti.connect()

at the beginning of my python script. I then tried adding

Code:
calculator.screen_capture()
and
Code:
calculator.recv_screen
Neither one worked returning

Code:
Traceback (most recent call last):
  File "screengrab.py", line 4, in <module>
    calculator.screen_capture()
AttributeError: 'cyti.core.Calculator' object has no attribute 'screen_capture'

I am not sure how to get CITI to get a screenshot. A quick search of core.pyx didn't seem to show anything. Do you have any ideas?
cyti doesn't appear to support screenshots as-is. I've never written any Cython before, but this function (to become a member on the Calculator type) might do the job:

Code:
cdef get_screenshot():
    cdef ticalcs.CalcScreenCoord sc
    sc.format = ticalcs.SCREEN_FULL
    sc.pixel_format = ticalcs.CALC_PIXFMT_RGB_565_LE

    cdef uint8_t *bitmap
    err = ticalcs.ticalcs_calc_recv_screen(self.calc_handle, &sc, &bitmap)
    if err:
        raise IOError("Failed to get screenshot: %i" % err)

    try:
        cdef array.array bitmap_out = array.array('H', [])
        array.extend_buffer(bitmap_out, bitmap, sc.width * sc.height * 2)
        return (sc.width, sc.height, bitmap_out)
    finally:
        free(bitmap)
Returns a 3-tuple of the screenshot width, height and an array of 16-bit numbers that are the screen image (I assume row-major ordering).
So where do I put that code?
You patch it into cyti.
I haven't done much python coding, and never tried modifying any modules, so please forgive me.
I tried putting your code under [mono]cdef class Calculator[code/]. Looking at the rest of the module, I guessed I should change your cdef to just def. here is the "patched" core.pyx. https://drive.google.com/file/d/1E7TxPt6RRicAM3VYQjcTUnKs8wcKsq58/view?usp=sharing
My python code is just a couple lines to try and get it working.

Code:
import cyti
calculator = cyti.connect()
calculator.get_screenshot()


Again, thanks for your help!
Your modified file looks fine. Have you tried building the modified module and using it?
So I just tried running the python3 setup.py build_ext -i and it returns:

Code:
cyti/core.pyx: cannot find cimported module 'cyti.clibs'
./cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
cyti/types/core.pyx: cannot find cimported module 'cyti.clibs'
cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
Compiling cyti/core.pyx because it changed.
[1/1] Cythonizing cyti/core.pyx

Error compiling Cython file:
------------------------------------------------------------
...
        err = ticalcs.ticalcs_calc_recv_screen(self.calc_handle, &sc, &bitmap)
        if err:
            raise IOError("Failed to get screenshot: %i" % err)

        try:
            cdef array.array bitmap_out = array.array('H', [])
                ^
------------------------------------------------------------

cyti/core.pyx:241:17: cdef statement not allowed here
Traceback (most recent call last):
  File "setup.py", line 52, in <module>
    library_dirs=module_library_dirs)
  File "/usr/lib/python3/dist-packages/Cython/Build/Dependencies.py", line 1027, in cythonize
    cythonize_one(*args)
  File "/usr/lib/python3/dist-packages/Cython/Build/Dependencies.py", line 1149, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: cyti/core.pyx
Apparently cdef statements are only valid at function scope, so I'd hoist that declaration outside the try block (but keep initialization inside, since I think that can fail if there's not enough memory).
So I tried putting the cdef just under the cdef for get_screenshot. I think the drive link I posted earlier should show the updated file. This time when making the module it sort of blows up...

Code:
./cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
cyti/types/core.pyx: cannot find cimported module 'cyti.clibs'
cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
Compiling cyti/core.pyx because it changed.
[1/1] Cythonizing cyti/core.pyx

Error compiling Cython file:
------------------------------------------------------------
...

        result = self._send_variable(var)
        return result == 0


    def get_screenshot():
   ^
------------------------------------------------------------

cyti/core.pyx:230:4: Method get_screenshot has wrong number of arguments (0 declared, 1 or more expected)

Error compiling Cython file:
------------------------------------------------------------
...
        result = self._send_variable(var)
        return result == 0


    def get_screenshot():
        cdef ticalcs.CalcScreenCoord sc
            ^
------------------------------------------------------------

cyti/core.pyx:231:13: 'CalcScreenCoord' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
        return result == 0


    def get_screenshot():
        cdef ticalcs.CalcScreenCoord sc
        cdef array.array bitmap_out = array.array('H', [])
            ^
------------------------------------------------------------

cyti/core.pyx:232:13: 'array' is not declared

Error compiling Cython file:
------------------------------------------------------------
...
        cdef array.array bitmap_out = array.array('H', [])
        sc.format = ticalcs.SCREEN_FULL
        sc.pixel_format = ticalcs.CALC_PIXFMT_RGB_565_LE

        cdef uint8_t *bitmap
        err = ticalcs.ticalcs_calc_recv_screen(self.calc_handle, &sc, &bitmap)
                    ^
------------------------------------------------------------

cyti/core.pyx:237:21: cimported module has no attribute 'ticalcs_calc_recv_screen'

Error compiling Cython file:
------------------------------------------------------------
...
        cdef array.array bitmap_out = array.array('H', [])
        sc.format = ticalcs.SCREEN_FULL
        sc.pixel_format = ticalcs.CALC_PIXFMT_RGB_565_LE

        cdef uint8_t *bitmap
        err = ticalcs.ticalcs_calc_recv_screen(self.calc_handle, &sc, &bitmap)
                    ^
------------------------------------------------------------

cyti/core.pyx:237:21: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(core.pyx:20:0)
StatListNode.stats[15] = StatListNode(core.pyx:84:5)
StatListNode.stats[0] = CClassDefNode(core.pyx:84:5,
    as_name = 'Calculator',
    class_name = 'Calculator',
    module_name = '',
    visibility = 'private')
CClassDefNode.body = StatListNode(core.pyx:85:4)
StatListNode.stats[12] = DefNode(core.pyx:230:4,
    modifiers = [...]/0,
    name = 'get_screenshot',
    np_args_idx = [...]/0,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
File 'ExprNodes.py', line 5084, in infer_type: SimpleCallNode(core.pyx:237:46,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6485, in infer_type: AttributeNode(core.pyx:237:21,
    attribute = 'ticalcs_calc_recv_screen',
    is_attribute = 1,
    needs_none_check = True,
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/usr/lib/python3/dist-packages/Cython/Compiler/ExprNodes.py", line 6485, in infer_type
    return node.entry.type
AttributeError: 'NoneType' object has no attribute 'type'
Traceback (most recent call last):
  File "setup.py", line 52, in <module>
    library_dirs=module_library_dirs)
  File "/usr/lib/python3/dist-packages/Cython/Build/Dependencies.py", line 1027, in cythonize
    cythonize_one(*args)
  File "/usr/lib/python3/dist-packages/Cython/Build/Dependencies.py", line 1149, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: cyti/core.pyx
Turns out there was a lot wrong with my code, so I actually tried to build it and fixed the problems. Code here: https://github.com/tari/cyti/commit/ad872e2d647efd3f1211f317924fc85e99ff0552
I got back to working on this, and pulled your edited file. When building with python3 setup.py build_ext -i I get this back from the terminal.

Code:
cyti/core.pyx: cannot find cimported module 'cyti.clibs'
./cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
cyti/types/core.pyx: cannot find cimported module 'cyti.clibs'
cyti/types/core.pxd: cannot find cimported module 'cyti.clibs'
running build_ext
building 'cyti.core' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/cyti
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I. -I/usr/include/tilp2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/python3.6m -c cyti/core.c -o build/temp.linux-x86_64-3.6/cyti/core.o
cyti/core.c: In function ‘__pyx_f_4cyti_4core_10Calculator_get_screenshot’:
cyti/core.c:6162:14: error: ‘CalcScreenCoord {aka struct <anonymous>}’ has no member named ‘pixel_format’; did you mean ‘format’?
   __pyx_v_sc.pixel_format = CALC_PIXFMT_RGB_565_LE;
              ^~~~~~~~~~~~
              format
cyti/core.c:6162:29: error: ‘CALC_PIXFMT_RGB_565_LE’ undeclared (first use in this function)
   __pyx_v_sc.pixel_format = CALC_PIXFMT_RGB_565_LE;
                             ^~~~~~~~~~~~~~~~~~~~~~
cyti/core.c:6162:29: note: each undeclared identifier is reported only once for each function it appears in
cyti/core.c: In function ‘__pyx_pf_4cyti_4core_2library_versions’:
cyti/core.c:7334:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   __pyx_t_2 = ticables_version_get();
             ^
cyti/core.c:7347:13: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   __pyx_t_2 = ticalcs_version_get();
             ^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
You may have an old library version that doesn't understand color calculators? It compiled on my system, but I have libticalcs 1.1.9 (installed from source).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement