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

Eink status #719

Merged
merged 1 commit into from
May 29, 2024
Merged

Eink status #719

merged 1 commit into from
May 29, 2024

Conversation

mjustian
Copy link
Contributor

@mjustian mjustian commented May 15, 2024

What does this change intend to accomplish?

This adds two new pieces of text to the e-ink display: Serial Number and Status. The serial number is taken off of the EEPROM. The status defaults to showing whether the AmpliPi is playing or not, but a custom status can be sent using a function as well. A numerical status is interpreted as an error code.

Checklist

  • Have you tested your changes and ensured they work?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • If applicable, have you updated the documentation/manual?
  • If applicable, have you updated the CHANGELOG?
  • Does your submission pass linting & tests? You can test on localhost using ./scripts/test

Copy link
Contributor

@rtertiaer rtertiaer left a comment

Choose a reason for hiding this comment

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

I think my requests are entirely nitpicks, besides the early-return if statement stuff I'd like to see change into an elif structure in ctrl.py as we talked about in person. Also tbf my eyes glaze over a little bit with the eeprom changes, but they looked fine; I also tend to trust these changes if @Lohrer had a hand in it.

amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/display/einkinterface.py Outdated Show resolved Hide resolved
@Lohrer
Copy link
Collaborator

Lohrer commented May 21, 2024

Before I review this, can you confirm that:

  • The TFT display on older units still functions properly.
  • An AmpliPro/Streamer with an unprogrammed EEPROM (all 1's) shows an error
  • The Streamer EEPROM can still be programmed with hw/tests/config_streamer.bash
  • Tests for any API changes are added (I believe tests/test_rest.py is the correct spot)

amplipi/ctrl.py Outdated
def get_state(self) -> models.Status:
""" get the system state """
self._update_sys_info()
self._update_serial()
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it is called every get(). I realize that internally the serial number is cached so that isn't actually what happens. Why isn't this called in reinit instead? That is where we read a similar property set, the firmware versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It didn't work in reinit since other things were trying to reach the EEPROM at the same time

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not true, it didn't work in reinit at first because you put it before the preamp's micro was assigned an I2C address, so it couldn't communicate. We didn't realize that until after you had already moved the serial reading to here. There's no reason you couldn't move it back, it just needs to be after the line that calls rt.Rpi() to setup the micro/firmware.

Copy link
Contributor Author

@mjustian mjustian May 22, 2024

Choose a reason for hiding this comment

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

I tried moving it back to reinit where the firmware version is and it stopped working on the regular sized amplipi


SysInfo = namedtuple('SysInfo', ['hostname', 'password', 'ip'])

SysInfo = namedtuple('SysInfo', ['hostname', 'password', 'ip', 'status_code', "serial_number", "ext_count"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Yiou could turn the SysInfo(None, None, None...) into SysInfo() if you use this initialization:

Suggested change
SysInfo = namedtuple('SysInfo', ['hostname', 'password', 'ip', 'status_code', "serial_number", "ext_count"])
_info_fields = ['hostname', 'password', 'ip', 'status_code', "serial_number", "ext_count"]
SysInfo = namedtuple('SysInfo', _info_fields, (None,) * len(_info_fields))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mypy does not like this for whatever reason

amplipi/eeprom.py Outdated Show resolved Hide resolved
"""Read data from address in EEPROM."""
try:
return self._i2c.read_i2c_block_data(self._address, address, length)
if self._bus() == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add an enumeration for the different i2c bus #'s?

self.get_board_type(),
self.get_board_rev())

# TODO: Do we need this? If so implement like the _read() function above. If not remove.
Copy link
Contributor

Choose a reason for hiding this comment

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

If we remove this, it probably makes sense to keep this pretty comment somewhere

@linknum23
Copy link
Contributor

As discussed: In the future we may want to add a slim barcode that can be scanned to quickly link to our troubleshooting guide when there is an error.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 21.95846% with 263 lines in your changes are missing coverage. Please review.

Project coverage is 49.81%. Comparing base (b516bb7) to head (9230ff9).
Report is 45 commits behind head on main.

Files Patch % Lines
amplipi/display/einkdisplay.py 0.00% 168 Missing ⚠️
amplipi/eeprom.py 45.29% 64 Missing ⚠️
amplipi/ctrl.py 44.11% 19 Missing ⚠️
amplipi/display/einkinterface.py 0.00% 11 Missing ⚠️
amplipi/display/__init__.py 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #719      +/-   ##
==========================================
- Coverage   50.90%   49.81%   -1.10%     
==========================================
  Files          25       26       +1     
  Lines        5838     6299     +461     
==========================================
+ Hits         2972     3138     +166     
- Misses       2866     3161     +295     
Flag Coverage Δ
unittests 49.81% <21.95%> (-1.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

amplipi/display/einkinterface.py Outdated Show resolved Hide resolved
amplipi/display/einkinterface.py Outdated Show resolved Hide resolved
amplipi/display/einkinterface.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
docs/manual/EINK_ERROR_CODES.md Outdated Show resolved Hide resolved
amplipi/ctrl.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/display/einkdisplay.py Outdated Show resolved Hide resolved
amplipi/eeprom.py Outdated Show resolved Hide resolved
return font
except Exception as exc:
raise Exception(f'Failed to load {self.fontname} font') from exc
return ImageFont.truetype(self.fontname, 10)


def get_info(iface, default_pass) -> SysInfo:
def update_logs(status) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of this? It looks like you're reinventing logging here. All the rest of our logs are captured by journald (it's just capturing stdout and stderr, nothing fancy) and are viewable with journalctl -f or by going to Settings->About->Logs in the AmpliPi web UI which pulls from the same journal service.

Also I tested it and the only log message I'm seeing in display-logs.json is "Starting Up". I tried changing the status and no other statuses show in that log file.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was one possible path I mentioned on day 2 as a persistent store of statuses to display. It may be vestigial now, particularly if we don't have external things reading or writing status, to this file or elsewhere - everything is simply represented as a state from the API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would make a lot more sense to move the log file's information to the actual logs. I'm making that change now.

@rtertiaer
Copy link
Contributor

One ask here would be to surface these same statuses on the TFT display; you can borrow the unit on my desk for this if you'd like.

Copy link
Collaborator

@Lohrer Lohrer left a comment

Choose a reason for hiding this comment

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

Much better! One last request would be to add display-status.txt to the .gitignore file so that git doesn't try to track it.

I think it would be awesome in the future to define these error codes as a {Short Name, Description} instead of just a number. That way we can display the short name on the display and the description in the logs and maybe webUI?

@@ -0,0 +1,14 @@
# AmpliPro E-Ink Display Error Codes

The following numerical codes are displayed on the AmpliPro's E-Ink Display when the corresponding error occurs. Note that these codes do not appear on older AmpliPi/AmpliPro devices that use TFT touchscreen displays.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this can be changed since it shows on all displays now? Also there are other references in this doc to just E-Ink displays that should be generalized.

Suggested change
The following numerical codes are displayed on the AmpliPro's E-Ink Display when the corresponding error occurs. Note that these codes do not appear on older AmpliPi/AmpliPro devices that use TFT touchscreen displays.
The following numerical codes are displayed on the AmpliPro's Display when the corresponding error occurs.

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""E-Ink Display Interface"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""E-Ink Display Interface"""
"""Display Status Interface"""

Or something similar, since this shows on all displays now.

Copy link
Contributor

@rtertiaer rtertiaer left a comment

Choose a reason for hiding this comment

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

two nitpicks, but otherwise heck yes 😎


import netifaces as ni

from loguru import logger as log
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use logging pls?


import netifaces as ni

from loguru import logger as log
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from loguru import logger as log
import logging as log

Comment on lines +13 to +14
BOARD_REV_RE = re.compile(r"(\d+)([A-z])") # accept lower or upper case change designator
# we will uppercase later
Copy link
Contributor

Choose a reason for hiding this comment

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

for future reference, it's normally less than ideal to obscure git history through changes like this that only address stylistic concerns.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, what do you feel this is obscuring? I suggested this change in the first place so I'd like to know for my own future reference. I felt that since we were already making changes in this area of the file, since the auto-formatter added a space on this line already, and since in the commit you can clearly see it's just a change in the comment, that it was worth fixing the typo now.

@mjustian mjustian merged commit aaa3b4d into main May 29, 2024
3 checks passed
@mjustian mjustian deleted the eink-status branch May 29, 2024 15:33
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.

None yet

5 participants