Skip to content

docs: Add example & info about log.add() exception when full. #2

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

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Functions
Labels previously specified and not present in a call to this function will
be skipped with an empty value in the log row.

:raise OSError: When the log is full this function raises an ``OSError``
exception with error code 28 ``ENOSPC``, which indicates there is no
space left in the device.

Examples
========

Expand Down
22 changes: 16 additions & 6 deletions examples/data-logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,36 @@
# Send each data row to the serial output
log.set_mirroring(True)

continue_logging = True

# This decorator schedules this function to run every 10s 50ms
@run_every(s=10, ms=50)
def log_data():
"""Log the temperature and light level, and display an icon."""
log.add(temp=temperature(), brightness=display.read_light_level())
display.show(Image.SURPRISED)
sleep(500)
global continue_logging
if continue_logging:
display.show(Image.SURPRISED)
try:
log.add(temp=temperature(), brightness=display.read_light_level())
except OSError:
continue_logging = False
display.scroll("Log full")
sleep(500)

while True:
if button_a.is_pressed() and button_b.is_pressed():
display.show(Image.MEH)
display.show(Image.CONFUSED)
# Delete the log file using the "full" options, which takes
# longer but ensures the data is wiped from the device
log.delete(full=True)
continue_logging = True
elif button_a.is_pressed():
display.show(Image.HAPPY)
# Log only the light level, the temp entry will be empty
# Log only the light level, the temp entry will be empty. If the log
# is full this will throw an exception and the programme will stop
log.add({
"brightness": display.read_light_level()
})
else:
display.show(Image.CONFUSED)
display.show(Image.ASLEEP)
sleep(500)