Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Clue Terminal and Context Fixes #290

Merged
merged 22 commits into from
Apr 2, 2020
Merged

Clue Terminal and Context Fixes #290

merged 22 commits into from
Apr 2, 2020

Conversation

andreamah
Copy link
Contributor

@andreamah andreamah commented Apr 1, 2020

Description:

Hi everyone! :)

New features:

_ClueSimpleTextDisplay.show_terminal() now works! Since its original purpose was to reference to a general terminal built in the firmware, I put the new files in base_circuitpython. I also added code in process_user_code.py that shows the default opening & closing print statements. This file also takes care of capturing print statements and sending them to the clue terminal.

Bug fixes:

  • After looking more into clue behavior, it turns out that I misunderstood the board.DISPLAY.show(group) call. I initially thought that it was called to show the group, but actually, this is a command to "context-switch" to show a specific group. Only one group can be shown at once, and board.DISPLAY.show(curr_group) will change the group on the screen to curr_group. Any further modifications to the active group will be actively changed on the screen. If modifications are made to the group before calling board.DISPLAY.show(), all changes should be present when board.DISPLAY.show() is called.
    • I added support for this within board.py.
  • The screen wasn't properly refreshing (partially due to the lapse in understanding above)
    • group.py now always starts with an all-black image every time draw() is called.

File notes:

  • base_circuitpython/terminal_handler.py: the custom-made terminal class that:
    • always handles the current strings, even when the terminal is not active
    • shows the terminal updating if the active group.
  • base_circuitpython/tests/terminal_handler_test.py: tests for terminal_handler.py
  • board.py: not new, but has major changes. It now keeps track of the active group. Groups will check with this active_group value before sending anything to the frontend.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Testing:

I made a mega-test that goes as follows:

NOTE: this test needs some slideshow bmp photos in the current working directory!

from adafruit_bitmap_font import bitmap_font

from adafruit_clue import clue
from datetime import datetime
import time

from adafruit_slideshow import SlideShow, PlayBackDirection, PlayBackOrder
import board

# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(
    board.DISPLAY,
    dwell=1,
    folder=".",
    loop=True,
    fade_effect=False,
    auto_advance=True,
    order=PlayBackOrder.ALPHABETICAL,
    direction=PlayBackDirection.FORWARD,
)

for i in range(2):
    slideshow.advance()

clue_data = clue.simple_text_display(title="Clue Sensor Data!", title_scale=2,)

val = 100
for i in range(12):
    val += 1
    clue_data.show_terminal()
    time.sleep(0.5)
    print(val)
    print(f"time {datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]}")

for i in range(10):
    val += 1
    clue_data[0].text = "Accelerometer:"
    clue_data[1].text = "Gyro:"
    clue_data[2].text = "Magnetic:"
    clue_data[3].text = "Pressure: {:.3f} hPa".format(val)
    clue_data[4].text = "Altitude: {:.1f} m".format(val)
    clue_data[5].text = "Temperature: {:.1f} C".format(val)
    clue_data[6].text = "Humidity: {:.1f} %".format(val)
    clue_data[7].text = "Proximity: {}".format(val)
    clue_data[8].text = "Gesture: {}".format("flip")
    clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(100, 100, 100, 100)
    clue_data[10].text = "Button A: {}".format(False)
    clue_data[11].text = "Button B: {}".format(False)
    clue_data[12].text = "Touch 0: {}".format(False)
    clue_data[13].text = "Touch 1: {}".format(False)
    clue_data[14].text = "Touch 2: {}".format(False)
    clue_data.show()
    print("shouldn't show until the end")
    time.sleep(0.5)

# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(
    board.DISPLAY,
    dwell=1,
    folder=".",
    loop=True,
    fade_effect=False,
    auto_advance=True,
    order=PlayBackOrder.ALPHABETICAL,
    direction=PlayBackDirection.FORWARD,
)

for i in range(2):
    slideshow.advance()

clue_data.show_terminal()

This tests the terminal, screen refreshing, and group context switching. Try it out :')

Checklist:

  • My code follows the style guidelines of this project
  • My code has been formatted with npm run format and passes the checks in npm run check
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@nasadigital
Copy link

nasadigital commented Apr 2, 2020

The test does not work for me. Stack trace:

[ERROR] No valid images 
	Traceback of code execution : 
	  File "d:\microbit\python_test\Untitled-1.py", line 19, in <module>
    direction=PlayBackDirection.FORWARD,
	  File "c:\Users\daseramo\.vscode\extensions\vscode-python-devicesimulator\out\CLUE\adafruit_slideshow.py", line 114, in __init__
    self._load_images()
	  File "c:\Users\daseramo\.vscode\extensions\vscode-python-devicesimulator\out\CLUE\adafruit_slideshow.py", line 187, in _load_images
    raise RuntimeError(CONSTANTS.NO_VALID_IMGS_ERR)

Edit: To be more clear, the display actually prints out the stack trace (awesome job!), but doesn't show a slideshow.

@andreamah
Copy link
Contributor Author

The test does not work for me. Stack trace:

[ERROR] No valid images 
	Traceback of code execution : 
	  File "d:\microbit\python_test\Untitled-1.py", line 19, in <module>
    direction=PlayBackDirection.FORWARD,
	  File "c:\Users\daseramo\.vscode\extensions\vscode-python-devicesimulator\out\CLUE\adafruit_slideshow.py", line 114, in __init__
    self._load_images()
	  File "c:\Users\daseramo\.vscode\extensions\vscode-python-devicesimulator\out\CLUE\adafruit_slideshow.py", line 187, in _load_images
    raise RuntimeError(CONSTANTS.NO_VALID_IMGS_ERR)

Edit: To be more clear, the display actually prints out the stack trace (awesome job!), but doesn't show a slideshow.

Does the directory that you're pointing to have some images to show? In my example, I pointed to the current working directory-> "."

@nasadigital
Copy link

Does the directory that you're pointing to have some images to show? In my example, I pointed to the current working directory-> "."

No pictures in the pointed directory.

@andreamah
Copy link
Contributor Author

Does the directory that you're pointing to have some images to show? In my example, I pointed to the current working directory-> "."

No pictures in the pointed directory.

The test needs some images in that directory :(. It's the same on the device too (I tried to replicate the wording of the runtime error)

Sorry, I forgot to point that out! I'll edit the top comment right away

@nasadigital
Copy link

No pictures in the pointed directory.

The test needs some images in that directory :(. It's the same on the device too (I tried to replicate the wording of the runtime error)

Sorry, I forgot to point that out! I'll edit the top comment right away

Thanks for addressing the comment and updating the testing instructions!
Unfortunately, I still get the same error. I added some bmp in the directory with the file, are there any additional restrictions (maybe resolution)? Do you think you could provide some uncopyrighted examples?

Copy link

@nasadigital nasadigital 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 pretty tricky, great job on documenting everything and adding tests 👍
LGTM.

src/base_circuitpython/displayio/group.py Outdated Show resolved Hide resolved
src/base_circuitpython/displayio/group.py Outdated Show resolved Hide resolved

self.__lock.release()

def configure(self, no_verif=False):

Choose a reason for hiding this comment

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

This method name is a bit confusing. Judging from the name configure, I wouldn't expect it to also draw things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll look into changing it c:

@andreamah
Copy link
Contributor Author

No pictures in the pointed directory.

The test needs some images in that directory :(. It's the same on the device too (I tried to replicate the wording of the runtime error)
Sorry, I forgot to point that out! I'll edit the top comment right away

Thanks for addressing the comment and updating the testing instructions!
Unfortunately, I still get the same error. I added some bmp in the directory with the file, are there any additional restrictions (maybe resolution)? Do you think you could provide some uncopyrighted examples?

PM'd you some photos that I used 😁

@nasadigital
Copy link

PM'd you some photos that I used 😁

if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING:

This line does a case sensitive check. Since the bitmaps I tried ended with .BMP it didn't find them. How is the behavior in this case on the device?

@andreamah
Copy link
Contributor Author

PM'd you some photos that I used 😁

if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING:

This line does a case sensitive check. Since the bitmaps I tried ended with .BMP it didn't find them. How is the behavior in this case on the device?

Could you send over some .BMP images? All of the bmp I could find were .bmp :(

@andreamah
Copy link
Contributor Author

PM'd you some photos that I used 😁

if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING:

This line does a case sensitive check. Since the bitmaps I tried ended with .BMP it didn't find them. How is the behavior in this case on the device?

Could you send over some .BMP images? All of the bmp I could find were .bmp :(

I tried .BMP on the actual device and it seems like it doesn't work either :O. In their library, they also just check for ".bmp".

https://github.com/adafruit/Adafruit_CircuitPython_Slideshow/blob/283b42ac4061259c595229832947519946326fb1/adafruit_slideshow.py#L191

@nasadigital
Copy link

I tried .BMP on the actual device and it seems like it doesn't work either :O. In their library, they also just check for ".bmp".

https://github.com/adafruit/Adafruit_CircuitPython_Slideshow/blob/283b42ac4061259c595229832947519946326fb1/adafruit_slideshow.py#L191

Thanks for confirming!
We should keep this way in that case.

@andreamah andreamah merged commit 9d569da into dev Apr 2, 2020
@andreamah andreamah deleted the users/t-anmah/clue-terminal branch April 2, 2020 19:11
@nasadigital nasadigital mentioned this pull request Apr 3, 2020
@andreamah andreamah mentioned this pull request Apr 8, 2020
11 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants