Skip to content

Commit

Permalink
fixed read file and some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wh00hw committed Jul 24, 2022
1 parent 874c54e commit 52c1642
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ ext_tree = flipper.storage.tree('/ext')
file_info = flipper.storage.stat("/ext/foo/bar.txt")

#Make directory
file_info = flipper.storage.mkdir("/ext/foo")
flipper.storage.mkdir("/ext/foo")
```
#### Files

```python
#Read file
file_info = flipper.storage.read("/ext/foo/bar.txt")
file= flipper.storage.read("/ext/foo/bar.txt")

#Read file chunks
file_info = flipper.storage.read("/ext/foo/bar.txt", 42)
file = flipper.storage.read("/ext/foo/bar.txt", 42)

#Remove file
flipper.storage.remove("/ext/foo/bar.txt")
Expand Down Expand Up @@ -215,10 +215,20 @@ flipper.gpio.mode(PIN_NAME, 1)
#Play song in RTTTL format
rttl_song = "Littleroot Town - Pokemon:d=4,o=5,b=100:8c5,8f5,8g5,4a5,8p,8g5,8a5,8g5,8a5,8a#5,8p,4c6,8d6,8a5,8g5,8a5,8c#6,4d6,4e6,4d6,8a5,8g5,8f5,8e5,8f5,8a5,4d6,8d5,8e5,2f5,8c6,8a#5,8a#5,8a5,2f5,8d6,8a5,8a5,8g5,2f5,8p,8f5,8d5,8f5,8e5,4e5,8f5,8g5"

#Play in loop
flipper.music_player.play(song)

#Stop loop
flipper.music_player.stop()

#Play for 20 seconds
flipper.music_player.play(song, duration=20)

#Beep
flipper.music_player.beep()

#Beep for 5 seconds
flipper.music_player.beep(duration=5)
```
### NFC

Expand Down
7 changes: 3 additions & 4 deletions lib/serial_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class SerialWrapper:
def __init__(self, port) -> None:
self._serial_port = serial.Serial(port=port, baudrate=9600,
bytesize=8, timeout=None, stopbits=serial.STOPBITS_ONE)
self._serial_port.read_until(b'>')
self._serial_port.read_until(b'>:')

@error_handler
def send(self, payload):
self._serial_port.read()
def send(self, payload: str) -> str:
self._serial_port.write(f"{payload}\r".encode())
time.sleep(0.5)
self._serial_port.readline()
return self._serial_port.read_until(b'>').decode().rstrip('>\r\n')
return self._serial_port.read_until(b'>:').decode().rstrip('\r\n')

def ctrl_c(self):
self._serial_port.write(b'\x03')
12 changes: 9 additions & 3 deletions lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ def remove(self, file):
return self._serial_wrapper.send(f"storage remove {file}")

def read(self, file):
return self._serial_wrapper.send(f"storage read {file}").split('\r\n')[1]
try:
return self._serial_wrapper.send(f"storage read {file}").split('\r\n')[1]
except IndexError:
return ""

def read_chunk(self, file, chunks):
return self._serial_wrapper.send(f"storage read_chunks {file} {chunks}").split('\r\n')[1]

try:
return self._serial_wrapper.send(f"storage read_chunks {file} {chunks}").split('\r\n')[1]
except IndexError:
return ""

def copy(self, source, destination):
return self._serial_wrapper.send(f"storage copy {source} {destination}")

Expand Down
7 changes: 3 additions & 4 deletions lib/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ def __init__(self) -> None:
def exec(self, func, callback, timeout):
def _run():
data = func()
if data:
if data and callback:
callback(func())
def _timer():
if self.thread.is_alive():
time.sleep(timeout)
self.stop()
time.sleep(timeout)
self.stop()
if not self.thread:
self.thread = Thread(target=_run)
self.thread.start()
Expand Down

0 comments on commit 52c1642

Please sign in to comment.