Skip to content

Commit

Permalink
Merge pull request #3 from crismc/feature/rotate_screen
Browse files Browse the repository at this point in the history
Feature/rotate screen
  • Loading branch information
crismc authored Dec 17, 2022
2 parents 7d155c8 + 804c426 commit e351874
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ python3 display.py --config /path/to/options.json
| ---------------------| ------- | ------------ | -------------------------------------------------------| ------------------- |
| i2c_bus | int | **Required** | I2C bus number. /dev/i2c-[bus number] | `1` |
| Temperature_Unit | string | **Required** | Display the CPU temperature in C or F | `C` |
| Rotate | int | **Optional** | Rotates the screen by the number of degrees provided counter clockwise around its centre (e.g. 180 displays the screen upside down). | 0 |
| Default_Duration | int | **Required** | How long in seconds to display each screen by default. Ignored if specified on specific screen | `10` |
| DateTime_Format | string | **Optional** | Format of the ```{datetime}``` static text variable | `%d/%m/%Y %H:%M:%S` |
| Graceful_Exit_Text | string | **Optional** | Text to display when the service is exited. Accepts same variables as the custom screen. | `Exited at {datetime}` |
Expand Down
7 changes: 5 additions & 2 deletions bin/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Config:
'static_screen_text_noscroll': 'static_screen_text_noscroll',
'scroll_amplitude': 'scroll_amplitude',
'datetime_format': 'datetime_format',
'welcome_screen_text': 'welcome_screen_text'
'welcome_screen_text': 'welcome_screen_text',
'rotate': 'rotate'
}

logger = logging.getLogger('Config')
Expand Down Expand Up @@ -108,7 +109,9 @@ def _init_display(self):
if not screenshot:
screenshot = False

self.display = Display(busnum, screenshot)
rotate = self.get_option_value('rotate')
self.display = Display(busnum, screenshot, rotate)

except Exception as e:
raise Exception("Could not create display. Check your i2c bus with 'ls /dev/i2c-*'.")

Expand Down
9 changes: 7 additions & 2 deletions bin/Screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class Display:
DEFAULT_BUSNUM = 1
SCREENSHOT_PATH = "./img/examples/"

def __init__(self, busnum = None, screenshot = False):
def __init__(self, busnum = None, screenshot = False, rotate = False):
if not isinstance(busnum, int):
busnum = Display.DEFAULT_BUSNUM

self.display = SSD1306(busnum)
self.clear()
self.width = self.display.width
self.height = self.display.height
self.rotate = rotate
self.image = Image.new("1", (self.width, self.height))
self.draw = ImageDraw.Draw(self.image)
self.screenshot = screenshot
Expand All @@ -28,9 +29,13 @@ def clear(self):
self.display.display()

def prepare(self):
self.draw.rectangle((0, 0, self.width, self.width), outline = 0, fill = 0)
self.draw.rectangle((0, 0, self.width, self.height), outline = 0, fill = 0)

def show(self):
if isinstance(self.rotate, int):
self.image = self.image.rotate(self.rotate)
self.draw = ImageDraw.Draw(self.image)

self.display.image(self.image)
self.display.display()

Expand Down
1 change: 1 addition & 0 deletions options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"I2C_bus": 1,
"Temperature_Unit": "C",
"rotate": 0,
"DateTime_Format": "%d/%m/%Y %H:%M:%S",
"Default_Duration": 10,
"graceful_exit_text": "Exited at {datetime}",
Expand Down

0 comments on commit e351874

Please sign in to comment.