Metadata-Version: 2.4
Name: keyhole-comm
Version: 1.14.0
Summary: Low-effort serial/pipe communication, e.g. for talking to devices that use the Arduino-IDE Keyhole library, or to other processes via stdin/stdout
Home-page: https://bitbucket.org/jezhill/Keyhole
Author: Jeremy Hill
Author-email: jezhill@gmail.com
License: CC0
Description-Content-Type: text/x-rst
License-File: LICENSE.txt
Provides-Extra: serial
Requires-Dist: pyserial; extra == "serial"
Provides-Extra: pipe
Requires-Dist: LineDance; extra == "pipe"
Provides-Extra: all
Requires-Dist: pyserial; extra == "all"
Requires-Dist: LineDance; extra == "all"
Dynamic: author
Dynamic: author-email
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: summary

This module provides the Keyhole class, which allows easy line-by-line text communication
over a serial port, or through a stdin/stdout pipe. It is particularly useful for
implementing the computer's side of the interaction when talking to a microcontroller that
has been programmed using the Arduino-IDE Keyhole library. In that case, exposed sketch
variables can be accessed as attributes of a Keyhole instance in Python.

The Arduino side::

    #include "Keyhole.h"
    Keyhole k;
    
    void setup()
    {
        Serial.begin(9600);
    }
    void loop()
    {
        static float foo = 1.23;
        static String bar = "hello";
        
        // insert main sketch logic here (use foo and bar to do whatever is so important)
        
        if(k.begin()) // expose the variables
        {
            k.variable("foo", foo);
            k.variable("bar", bar);
            k.end();
        }
    }

The Python side::

    from keyhole import Keyhole
    
    # k = Keyhole('COM4')                 # windows example
    k = Keyhole('/dev/cu.usbmodem[0-9]*') # macos example (globbing is OK if the match is unique)
    
    print( k.bar ) # queries an exposed sketch variable
    k.foo = 4.56   # assigns to an exposed sketch variable and makes the .variable() call return true
    
    print( k() )  # get all exposed variables

In Python, you can also communicate similarly with a process on the local computer,
exchanging messages in the same format over stdin/stdout. To do this, initialize your
`Keyhole` instance via the `pipe` argument instead of the `port` argument::

    from keyhole import Keyhole
    
    k = Keyhole( pipe='python -m keyhole.pipe' ) # running the `keyhole.pipe` submodule
                                                 # provides a toy example
    print( k.spam )
    k.eggs = 12
    print( k() )
