zerowriter / zerowriter1

126 stars 20 forks source link

Refactor to class-based approach #4

Closed jacobsmith closed 4 months ago

jacobsmith commented 6 months ago

:wave: I'm opening this PR as it is in a draft state to get feedback and see if it is something you would want to merge in. If this general approach is desirable, I can polish up the code itself a bit more before actually merging it in.

At a high level, this PR:

Refactors main.py to zerowriter.py and introduces a class to help maintain variables. It is still a "god" level object, with very intimate knowledge of almost everything. The class was largely copy/pasted and moved from global var to self.var syntax. This was helpful as it lead to:

Adds the ability to write tests or interact with zerowriter on a laptop instead of having to connect wirelessly to the raspi.

Introduces a simple menu system to save files, load files, check for new updates from GitHub, etc.

An experimental QR-code to extract data from the device without using networking. I'm hoping to potentially use this to take notes during meetings at work (I'm a developer; they're used to me bringing in odd devices to test out 😂 ) but I don't want to deal with corporate wifi. I've also thought about in the menu being able to set the Pi to broadcast its own AP and serve the data folder that way as another easy way to exfiltrate data from the device.

Also begins to update the code in such a way that multiple different screens could be used. The 4in2_V2 display that I picked up (not realizing it wasn't the original one used :\ ) is still more or less good for me as someone who touch-types and doesn't need to reference the screen terribly often. I've also added a ctrl+r key to force screen updates for those of us with slower-updating screens (:

The code still needs to be tested a bit more thoroughly on my own device, but I wanted to share the PR for comments or feedback along the way.

Also: I'm a professional developer, but I don't use Python regularly. Some of the code was modified or written using aider, a tool that wraps chat-gpt and is able to edit files in-place. Just wanted to call that out explicitly as I know some people/organizations have different levels of comfort with AI-generated code. I have read every line it has written and feel comfortable with it; I mainly guided it with comments of what I wanted and let it do the how in a way that is idiomatic to python instead of forcing other paradigms I'm more comfortable with.

zerowriter commented 6 months ago

Hey, this looks good. I was actually just working on a menu system, but your implementation is better and more flexible. Thanks for the simple file system. Oh, and in particular, I like the QR code -- one of the neat features of the DM30. I was toying with other quality of life stuff -- font sizes, wifi settings, disabling non-essential services, etc.

I haven't tried the tkinter stuff -- won't comment on that.

I have just ported it over to my unit this morning and swapped the code to my original new4in2part driver -- just have to tweak a few things now to get it to run partial updates properly. I have never checked out waveshare's 4in2_v2 code, it looks like the setup and the LUT are completely different. Have you dug into that epd4in2_V2.py much yet? Bummer. I do see some partial update options there, atleast... but I imagine they are quite slow.

I'll toy around with it a bit and share my thoughts. But I'd say for sure, keep developing this if you are enjoying it! Seems much cleaner, and structured.

If you continue, I'd say get your hands on a v1 panel if you can find it..

edit: and I'm no developer, I'm a hobbyist -- and AI tools are useful tools, no issues there for me. This project would never have happened if I didn't have access to AI to learn how to get going in python.

zerowriter commented 6 months ago

I have the same v2 4.2" display now -- I have configured it on another unit and it is running decently with a few modifications. I'll merge this and add my updates as well over the weekend.

Waveshare confirmed with me over email that the v1 display I received half a year ago is no longer being produced -- so best we just move the project over to the v2 entirely, i think.

holmesha commented 5 months ago

Been testing the refactor code on a V2 for a few days. Functionality is pretty good, love the menu and auto update feature! The main issue seems to be the refresh rate as compared to V1 / partial refresh. It sometimes appears to lose text I typed due to the delay.

I wish I were better with Python to help more, but do you think there is a way to add arrow key functionality as well?

zerowriter commented 5 months ago

Been testing the refactor code on a V2 for a few days. Functionality is pretty good, love the menu and auto update feature! The main issue seems to be the refresh rate as compared to V1 / partial refresh. It sometimes appears to lose text I typed due to the delay.

I wish I were better with Python to help more, but do you think there is a way to add arrow key functionality as well?

I have worked on the v2 drivers a bit and have them within a reasonably spot, similar to the v1 i used originally. V1 is definitely faster, but I think with the new code you'll be in a good spot.

I will commit my changes and push it all to the github this week -- been unusually busy with work.

regarding arrow keys: do you mean a cursor / editing support? it could be done, but I have left it out intentionally and it probably would not perform very well on the 4.2" panel anyway. I may add it myself down the line (probably with a toggle on/off in the menu) especially if I get a 6" version working with a pi4 and a 60% keyboard.

holmesha commented 5 months ago

Awesome! Makes total sense on the cursor. Excited to see this come together, thank you!

zerowriter commented 4 months ago

closing this as I have merged your code to a new codebase in this branch: https://github.com/zerowriter/zerowriter1/tree/waveshare_2.2

sorry, i don't really know github very well so wasn't sure how to do this.