williamfzc / pyminitouch

python wrapper of minitouch, for better experience
https://pyminitouch.readthedocs.io
MIT License
125 stars 25 forks source link

add: lower level API #4

Closed F6 closed 5 years ago

F6 commented 5 years ago

3

I have slightly modified your source code to use it in my project, see commit 15e768a

williamfzc commented 5 years ago

wow... really high efficiency :+1: I like your idea. For further usage, I prefer to send command via CommandBuilder, rather than raw string :) But don't worry about that, I will edit and merge it these days. Thanks for your PR!

williamfzc commented 5 years ago

@F6 hi,

You can apply your complicate actions like this:

    with safe_connection(_DEVICE_ID) as d:
        builder = CommandBuilder()
        builder.press(0, 400, 400, 50)
        builder.commit()
        builder.move(0, 500, 500, 50)
        builder.commit()
        builder.move(0, 800, 400, 50)
        builder.commit()
        builder.release(0)
        builder.commit()
        builder.publish(d)

    with safe_device(_DEVICE_ID) as d:
        builder = CommandBuilder()
        builder.press(0, 400, 400, 50)
        builder.commit()
        builder.move(0, 500, 500, 50)
        builder.commit()
        builder.move(0, 800, 400, 50)
        builder.commit()
        builder.release(0)
        builder.commit()
        builder.publish(d.connection)

But I don't know if it is a good way. Any suggestions?

Of course, use it without with:

d = MNTDevice(_DEVICE_ID)
builder = CommandBuilder()
builder.press(0, 400, 400, 50)
builder.commit()
builder.move(0, 500, 500, 50)
builder.commit()
builder.move(0, 800, 400, 50)
builder.commit()
builder.release(0)
builder.commit()
builder.publish(d.connection)

# do not forget to stop it
d.stop()
F6 commented 5 years ago

got your idea, thanks. I previously thought that CommandBuilder is only intended for internal use.

I think your idea is great, a small suggestion is that we can use a consistent naming convention with minitouch, e.g. maybe "down" instead of "press", "up" instead of "release"?

williamfzc commented 5 years ago

https://github.com/williamfzc/pyminitouch/pull/5 based on this PR was created. Closed.