Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video support! #348

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Video support! #348

wants to merge 7 commits into from

Conversation

gwendal-h
Copy link
Contributor

@gwendal-h gwendal-h commented Oct 3, 2023

New features supported for the 5 inch Turing screen:

  • File upload
  • Delete file
  • List files and directories (internal storage and SD card)
  • Start/stop a video
  • Draw image / texts / progress bar on the video
  • 1 small fix:
  • Fix the UPDATE_BITMAP command when drawing a big image (image size > 65535)

Fix the UPDATE_BITMAP command when drawing a big image (image size > 65535)

This bug happened when trying to draw a long text with a big font size.
New features supported for the 5 inch Turing screen:

- File upload
- Delete file
- List files and directories (internal storage and SD card)
- Start/stop a video
- Draw image / texts / progress bar on the video
@gwendal-h gwendal-h changed the title Fix UPDATE_BITMAP when image_size > 65535 Video support! Oct 3, 2023
@gwendal-h gwendal-h mentioned this pull request Oct 3, 2023
@gwendal-h
Copy link
Contributor Author

Sample code file "test_new_features.py" is provided to demontrate the new features.
New sample code file "simple-program-video-mode.py" is basically "simple-program.py" but in video mode.

Video dimensions must be 480 * 800. I added some sample videos as an example.

I still have to improve the performance: the refresh is a bit slow and it takes too much CPU.

@mathoudebine
Copy link
Owner

Nice job! I'm looking forward to testing it this week-end when I got some time 🚀

@mathoudebine
Copy link
Owner

My Turing 5" just broke 😞 I was testing your code and everything was working fine but suddenly my computer restarted and I think it broke the screen, now it connects/disconnects in loop and won't respond to commands, I need to order a new one...

Fix update image payload:
last 250 bytes packet must not end with 0xef 0x69.
and last 250 bytes packet must not be "0x69 0x0000..." nor "0xef 0x69 0x0000..."
Improved refresh rate with JIT compiling the function _get_visible_segments with numba
@gwendal-h
Copy link
Contributor Author

My Turing 5" just broke 😞 I was testing your code and everything was working fine but suddenly my computer restarted and I think it broke the screen, now it connects/disconnects in loop and won't respond to commands, I need to order a new one...

Oh no! what happened ? Was it like a micro power outage that broke it ? You could try pluging the screen with the other cable (There's the USB-C cable and the 4-wire cable that you can connect to your mother board directly.)

@gwendal-h
Copy link
Contributor Author

So this week-end I was able to fix the last remaining issue: sometimes the resfresh would freeze and the status reply was "NeedReSend = 1" ...

Turns out the last 250 bytes packet of the image payload can not end with 0xEF69.
And the last 250 bytes packet can not be 0x69000000... or 0xEF69000000...

So in that case I add a "dummy" visible pixel field to fix the image payload format.

Now the script "simple-program-video-mode.py" is running smoothly.

But man that was time consuming to find this one :).

@gwendal-h
Copy link
Contributor Author

I also tried to improve the refresh time to the best i could.
I ended up using numba to just-in-time compile the function _get_visible_pixels. (Python was quite slow in those loops)

On my computer the average refresh time went from 0.056 s down to 0.016 s ! (so much less CPU consumption in real application!)

Without numba :

refresh_without_numba.mp4

With numba :

refresh_with_numba.mp4

@n-i-x
Copy link

n-i-x commented Jan 7, 2024

Fixes #439

@mathoudebine mathoudebine linked an issue Jan 10, 2024 that may be closed by this pull request
@mathoudebine
Copy link
Owner

Hi, sorry I did not find time to review your PR before but I will try to do it as soon as possible!

Copy link

@n-i-x n-i-x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is excellent work and it works great with my 5" Turing display.

Have you figured out a way to copy files FROM the device locally? I'd like to backup the stock videos off my device.

# Set your COM port e.g. COM3 for Windows, /dev/ttyACM0 for Linux, etc. or "AUTO" for auto-discovery
# COM_PORT = "/dev/ttyACM0"
# COM_PORT = "COM5"
COM_PORT = "COM4"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "AUTO"

# - SIMU for 3.5" simulated LCD (image written in screencap.png)
# - SIMU5 for 5" simulated LCD
# To identify your smart screen: https://github.com/mathoudebine/turing-smart-screen-python/wiki/Hardware-revisions
REVISION = "C"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "A"


def ListFiles(self, dir_path : str):
pyd = bytearray()
pyd.extend(len(dir_path).to_bytes(1))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyd.extend(len(dir_path).to_bytes(1, 'big'))

Fix throughout

lcd_comm.SetBrightness(level=50)

# Check if video is loaded and upload video if needed.
video_size = lcd_comm.GetFileSize("/mnt/SDCARD/video/particle_wave.mp4")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My device doesn't have an SDCard, but there are plenty of videos on internal storage. Maybe check if there are any internal videos and randomly select one instead of trying to upload a video to the SDCARD which may not exist?

Or, split these examples out into an sdcard and an internal storage version? There may even be space available on internal storage to push the videos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mine had nothing on internal storage.

You can upload a video on internal storage, with the "UploadFile" function by setting the argument "destination_path".

For example: destination_path = "/root/video/video.mp4"

I don't know if it's possible to download video from the device's internal storage. The software provided by the manufacturer doesn't have that feature.

@peterng1618
Copy link

@gwendal-h Would you please update this to the latest release? 🙏

@gwendal-h
Copy link
Contributor Author

@mathoudebine Could you merge my pull request to the main branch ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding long string of text fails
4 participants