Skip to content

Commit 0847c0b

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 3a5b6d1 commit 0847c0b

2 files changed

Lines changed: 31 additions & 30 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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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-
from time import sleep
9-
101
"""
112
Small library to interact with a fluepdot controlled display
123
https://fluepdot.readthedocs.io/en/latest/
@@ -19,6 +10,12 @@
1910
Currently there is no support for changing the timings.
2011
"""
2112

13+
import requests
14+
from requests import Response
15+
from enum import Enum
16+
from typing import Any, Dict, Optional, List
17+
from time import sleep
18+
2219
GetParam = Dict[str, Any]
2320
PostParam = str
2421

@@ -55,17 +52,16 @@ def post_time(self) -> None:
5552
dt = ndt
5653
self.post_text(dt, x=8, y=1, font="fixed_7x14")
5754

58-
def get_size(self) -> (int, int):
55+
def get_size(self) -> tuple[int, int]:
5956
frame = self.get_frame()
6057
self.width = len(frame[0])
6158
self.height = len(frame) - 1
62-
return [self.width, self.height]
59+
return self.width, self.height
6360

6461
def get_frame(self) -> List[str]:
6562
r = self._get(frameURL)
6663
return r.text.split('\n')
6764

68-
6965
def get_pixel(self, x: int = 0, y: int = 0) -> bool | None:
7066
r = self._get(pixelURL, get={"x": x, "y": y})
7167
rtn = True if r.text == "X" else False if r.text == " " else None
@@ -122,13 +118,18 @@ def _pad_frame(line: str) -> str:
122118
self.post_frame_raw("\n".join(l[i:i+115] for l in frame))
123119
sleep(sleep_time)
124120

125-
def post_frame(self, frame: List[List[bool]]) -> Response:
121+
def post_frame(self, frame: List[List[bool]], center: bool = False) -> Response:
126122
data: List[List[str]] = [[" "] * self.width for _ in range(self.height)]
127-
for x, l in enumerate(frame):
128-
for y, b in enumerate(l):
123+
x_offset: int = 0
124+
y_offset: int = 0
125+
if center:
126+
x_offset = (self.width - max(len(line) for line in frame)) // 2
127+
y_offset = (self.height - len(frame))//2
128+
for y, l in enumerate(frame):
129+
for x, b in enumerate(l):
129130
if b:
130131
try:
131-
data[x][y] = "X"
132+
data[y+y_offset][x+x_offset] = "X"
132133
except IndexError as e:
133134
print(e)
134135
outStr = ""

0 commit comments

Comments
 (0)