Skip to content

Commit

Permalink
fix module_exit
Browse files Browse the repository at this point in the history
  • Loading branch information
txoof committed Jan 20, 2024
1 parent 3d68992 commit 1b7a53d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 16 deletions.
57 changes: 48 additions & 9 deletions epdlib/Screen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@
"cell_type": "code",
"execution_count": null,
"id": "f19afec5",
"metadata": {
"lines_to_next_cell": 2
},
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"from PIL import Image, ImageDraw, ImageOps, ImageColor\n",
"from datetime import datetime\n",
"from pathlib import Path\n",
"from gpiozero import GPIODeviceError\n",
"import time\n",
"\n",
"try:\n",
" from . import constants\n",
"except ImportError as e:\n",
" import constants\n",
"\n",
" "
"from waveshare_epd import epdconfig"
]
},
{
Expand Down Expand Up @@ -777,7 +776,13 @@
" if self.HD:\n",
" pass\n",
" else:\n",
" self.epd.module_exit(cleanup=True)"
" # self.epd.module_exit(cleanup=True)\n",
" logging.info('shutting down epd interface')\n",
" try:\n",
" epdconfig.module_exit(cleanup=True)\n",
" except GPIODeviceError as e:\n",
" logging.warning(f'failed to sleep module: {e}')\n",
" raise ScreenError(e)"
]
},
{
Expand Down Expand Up @@ -984,7 +989,9 @@
" print(f\"using font: {myLayout['title']['font']}\")\n",
" s = Screen(epd=myepd, vcom=voltage, mode='RGB')\n",
" \n",
" for r in [0, 90, 180]:\n",
" # for r in [0, 90, 180]:\n",
" for r in [0]:\n",
" do_exit = False\n",
" print(f'setup for rotation: {r}')\n",
" s.rotation = r\n",
" l = Layout(resolution=s.resolution)\n",
Expand All @@ -1000,11 +1007,19 @@
" print(f'{e}')\n",
" print('Try: $ raspi-config > Interface Options > SPI')\n",
" do_exit = True\n",
" except ScreenError as e:\n",
" print(f'failed to write to screen: {e}')\n",
" do_ext = True\n",
" else:\n",
" do_exit = False\n",
" \n",
" if do_exit:\n",
" try:\n",
" s.module_exit()\n",
" except Exception:\n",
" pass \n",
" sys.exit()\n",
" \n",
" print('sleeping for 2 seconds')\n",
" time.sleep(2)\n",
"\n",
Expand All @@ -1013,12 +1028,20 @@
" print('mirror output')\n",
" s.mirror = True\n",
" s.rotation = 0\n",
" s.writeEPD(l.concat())\n",
" try:\n",
" s.writeEPD(l.concat())\n",
" except ScreenError as e:\n",
" print(f'failed to write to screen: {e}')\n",
" sys.exit()\n",
" time.sleep(3)\n",
" \n",
" print('clear screen')\n",
" s.clearEPD()\n",
" s.module_exit()"
" try:\n",
" s.clearEPD()\n",
" print('shutting down interface')\n",
" s.module_exit()\n",
" except Exception as e:\n",
" print(e)"
]
},
{
Expand All @@ -1031,6 +1054,22 @@
"if __name__ == '__main__':\n",
" e= main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5555fa2e-912b-4076-940e-e520c0493453",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "74b1f769-3905-4b74-aeae-bafd23811eae",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
41 changes: 35 additions & 6 deletions epdlib/Screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
from PIL import Image, ImageDraw, ImageOps, ImageColor
from datetime import datetime
from pathlib import Path
from gpiozero import GPIODeviceError
import time

try:
from . import constants
except ImportError as e:
import constants

from waveshare_epd import epdconfig


# + code_folding=[0]
Expand Down Expand Up @@ -724,7 +725,13 @@ def module_exit(self):
if self.HD:
pass
else:
self.epd.module_exit(cleanup=True)
# self.epd.module_exit(cleanup=True)
logging.info('shutting down epd interface')
try:
epdconfig.module_exit(cleanup=True)
except GPIODeviceError as e:
logging.warning(f'failed to sleep module: {e}')
raise ScreenError(e)


# + code_folding=[]
Expand Down Expand Up @@ -915,7 +922,9 @@ def main():
print(f"using font: {myLayout['title']['font']}")
s = Screen(epd=myepd, vcom=voltage, mode='RGB')

for r in [0, 90, 180]:
# for r in [0, 90, 180]:
for r in [0]:
do_exit = False
print(f'setup for rotation: {r}')
s.rotation = r
l = Layout(resolution=s.resolution)
Expand All @@ -931,11 +940,19 @@ def main():
print(f'{e}')
print('Try: $ raspi-config > Interface Options > SPI')
do_exit = True
except ScreenError as e:
print(f'failed to write to screen: {e}')
do_ext = True
else:
do_exit = False

if do_exit:
try:
s.module_exit()
except Exception:
pass
sys.exit()

print('sleeping for 2 seconds')
time.sleep(2)

Expand All @@ -944,13 +961,25 @@ def main():
print('mirror output')
s.mirror = True
s.rotation = 0
s.writeEPD(l.concat())
try:
s.writeEPD(l.concat())
except ScreenError as e:
print(f'failed to write to screen: {e}')
sys.exit()
time.sleep(3)

print('clear screen')
s.clearEPD()
s.module_exit()
try:
s.clearEPD()
print('shutting down interface')
s.module_exit()
except Exception as e:
print(e)
# -

if __name__ == '__main__':
e= main()




2 changes: 1 addition & 1 deletion epdlib/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.6.3.1"
__version__="0.6.3.2"

0 comments on commit 1b7a53d

Please sign in to comment.