Skip to content

Commit 27602e6

Browse files
committed
added option for centering in post_frame method.
when passed frame is smaller than the display it can be centered. minor fixes and updated readme.
1 parent d0a09d8 commit 27602e6

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ fd = Fluepdot("http://module.local")
1414
## Functions
1515

1616

17-
function | args | default values | return type | description
18-
---|---|---|---|---
19-
_init_ | baseURL: str, width: int, height: int | x=115, y=16 | fluepdot.Fluepdot | Constructor for Fluepdot class
20-
post_time ||| None | indefinitly sets the module to display the current time.
21-
get_size ||| (int, int) | returns the size of the connected display
22-
get_frame ||| str | returns the current frame stored by the module
23-
get_pixel | x: int, y: int | x=0, y=0 | returns the state of a single pixel
24-
get_fonts ||| None | prints a list of fonts installed on the module
25-
get_mode ||| fluepdot.Mode | returns the mode the module is in
26-
post_text | text: str, x: int, y: int, font: str | x=0, y=0, font="DejaVuSans12" | requests.Response | posts a text to the module and returns the requests response
27-
post_frame | frame: List[List[bool]] || requests.Response | posts a frame to the module and returns the requests response
28-
set_pixel | x: int, y: int | x=0, y=0 | requests.Response | sets a pixel on the display to active and returns the requests response
29-
unset_pixel | x: int, y: int | x=0, y=0 | sets a pixel on thes display to inactive and returns the requests response
30-
set_mode | mode: fluepdot.Mode | mode=Mode.FULL | requests.Response | sets the module to FULL or DIFFERENTIAL update mode and returns the requests response
17+
| function | args | default values | return type | description |
18+
|-------------|---------------------------------------|-------------------------------|-------------------|---------------------------------------------------------------------------------------|
19+
| _init_ | baseURL: str, width: int, height: int | x=115, y=16 | fluepdot.Fluepdot | Constructor for Fluepdot class |
20+
| post_time | | | None | indefinitly sets the module to display the current time. |
21+
| get_size | | | tuple[int, int] | returns the size of the connected display |
22+
| get_frame | | | str | returns the current frame stored by the module |
23+
| get_pixel | x: int, y: int | x=0, y=0 | bool | returns the state of a single pixel |
24+
| get_fonts | | | None | prints a list of fonts installed on the module |
25+
| get_mode | | | fluepdot.Mode | returns the mode the module is in |
26+
| post_text | text: str, x: int, y: int, font: str | x=0, y=0, font="DejaVuSans12" | requests.Response | posts a text to the module and returns the requests response |
27+
| post_frame | frame: List[List[bool]], center: bool | center=False | requests.Response | posts a frame to the module and returns the requests response |
28+
| set_pixel | x: int, y: int | x=0, y=0 | requests.Response | sets a pixel on the display to active and returns the requests response |
29+
| unset_pixel | x: int, y: int | x=0, y=0 | requests.Response | sets a pixel on thes display to inactive and returns the requests response |
30+
| set_mode | mode: fluepdot.Mode | mode=Mode.FULL | requests.Response | sets the module to FULL or DIFFERENTIAL update mode and returns the requests response |

src/fluepdot/fluepdot.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# python fluepdot module
2-
3-
import requests
4-
import binascii
5-
from requests import Response
6-
from enum import Enum
7-
from typing import Any, Dict, Optional, List
8-
91
"""
102
Small library to interact with a fluepdot controlled display
113
https://fluepdot.readthedocs.io/en/latest/
@@ -15,6 +7,11 @@
157
Currently there is no support for changing the timings.
168
"""
179

10+
import requests
11+
from requests import Response
12+
from enum import Enum
13+
from typing import Any, Dict, Optional, List
14+
1815
GetParam = Dict[str, Any]
1916
PostParam = str
2017

@@ -51,17 +48,17 @@ def post_time(self) -> None:
5148
dt = ndt
5249
self.post_text(dt, x=8, y=1, font="fixed_7x14")
5350

54-
def get_size(self) -> (int, int):
51+
def get_size(self) -> tuple[int, int]:
5552
frame = self.get_frame()
5653
self.width = len(frame[0])
5754
self.height = len(frame) - 1
58-
return [self.width, self.height]
55+
return self.width, self.height
5956

6057
def get_frame(self) -> List[str]:
6158
r = self._get(frameURL)
6259
return r.text.split('\n')
6360

64-
def get_pixel(self, x: int = 0, y: int = 0) -> bool:
61+
def get_pixel(self, x: int = 0, y: int = 0) -> bool | None:
6562
r = self._get(pixelURL, get={"x": x, "y": y})
6663
rtn = True if r.text == "X" else False if r.text == " " else None
6764
return rtn
@@ -81,13 +78,18 @@ def post_text(self, text: str, x: int = 0, y: int = 0, font: str = "DejaVuSans12
8178
def post_frame_raw(self, frame: str) -> Response:
8279
return self._post(frameURL, post=frame)
8380

84-
def post_frame(self, frame: List[List[bool]]) -> Response:
81+
def post_frame(self, frame: List[List[bool]], center: bool = False) -> Response:
8582
data: List[List[str]] = [[" "] * self.width for _ in range(self.height)]
86-
for x, l in enumerate(frame):
87-
for y, b in enumerate(l):
83+
x_offset: int = 0
84+
y_offset: int = 0
85+
if center:
86+
x_offset = (self.width - max(len(line) for line in frame)) // 2
87+
y_offset = (self.height - len(frame))//2
88+
for y, l in enumerate(frame):
89+
for x, b in enumerate(l):
8890
if b:
8991
try:
90-
data[x][y] = "X"
92+
data[y+y_offset][x+x_offset] = "X"
9193
except IndexError as e:
9294
print(e)
9395
outStr = ""

0 commit comments

Comments
 (0)