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

Moved memory usage exception to validator method #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ Found 2247 frames, step time of 20 ms for a total duration of 0:00:44.940000.
Used 16.45% of the available memory
```

Errors in the sequence will be highlighted & prepended with a Validation Error message:
```
> python3 validator.py invalidlightshow.fseq
WARNING: FSEQ file should be renamed to 'lightshow.fseq' before playing in a Tesla
VALIDATION ERROR: Expected file format to be V2 Uncompressed
```

## Boolean Light Channels
Most lights available on the vehicle can only turn on or off instantly, which corresponds to 0% or 100% brightness of an 'Effect' in xLights.
- For off, use blank space in the xLights timeline
Expand Down Expand Up @@ -292,4 +299,4 @@ To command a closure to move in a particular manner, add an 'On' effect and adju
- Vehicles without rear fog lights will not use any other light in place of rear fog lights.

#### Tail lights and License Plate Lights
- On Model 3 built before October 2020: left tail, right tail, and license plate lights operate together. They will activate during ```(Left tail || Right tail)``` requests from xLights - note that the license plate lights xLights channel will have no effect on these vehicles.
- On Model 3 built before October 2020: left tail, right tail, and license plate lights operate together. They will activate during ```(Left tail || Right tail)``` requests from xLights - note that the license plate lights xLights channel will have no effect on these vehicles.
21 changes: 17 additions & 4 deletions validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
import sys
import argparse
import datetime
from pathlib import Path

MEMORY_LIMIT = 681


class ValidationError(Exception):
pass
def __init__(self, message):
super(ValidationError, self).__init__(f"VALIDATION ERROR: {message}")


@dataclasses.dataclass
class ValidationResults:
frame_count: int
step_time: int
duration_s: int
memory_usage: float
command_count: int

def validate(file):
file_name = Path(file.name).name
if file_name != "lightshow.fseq":
print(f"WARNING: FSEQ file should be renamed to 'lightshow.fseq' before playing in a Tesla.")

"""Calculates the memory usage of the provided .fseq file"""
magic = file.read(4)
start, minor, major = struct.unpack("<HBB", file.read(4))
Expand Down Expand Up @@ -66,7 +75,13 @@ def validate(file):
prev_closure_2 = closure_state[10:]
count += 1

return ValidationResults(frame_count, step_time, duration_s, count / MEMORY_LIMIT)
memory_usage = count / MEMORY_LIMIT

if memory_usage > 1:
raise ValidationError(f"Sequence uses {count} commands. The maximum allowed is {MEMORY_LIMIT}.")

return ValidationResults(frame_count, step_time, duration_s, memory_usage, count)


if __name__ == "__main__":
# Expected usage: python3 validator.py lightshow.fseq
Expand All @@ -83,5 +98,3 @@ def validate(file):

print(f"Found {results.frame_count} frames, step time of {results.step_time} ms for a total duration of {datetime.timedelta(seconds=results.duration_s)}.")
bendudz marked this conversation as resolved.
Show resolved Hide resolved
print(f"Used {results.memory_usage*100:.2f}% of the available memory")
if results.memory_usage > 1:
sys.exit(1)