From cfd3f6dbc0c4b51e44d14f5c34a1308f7580b26b Mon Sep 17 00:00:00 2001
From: nicesocket <56041912+nicesocket@users.noreply.github.com>
Date: Tue, 1 Oct 2019 19:38:52 +0200
Subject: [PATCH] Make sure to clear with the correct parameters for the
 configured display

The former versions always used the V2-Controls which effectively destroys V1-Boards.
---
 sdcard/rootfs/root/pwnagotchi/scripts/main.py | 36 +++++++++++++++----
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/main.py b/sdcard/rootfs/root/pwnagotchi/scripts/main.py
index dcb6c21..10e0490 100755
--- a/sdcard/rootfs/root/pwnagotchi/scripts/main.py
+++ b/sdcard/rootfs/root/pwnagotchi/scripts/main.py
@@ -24,12 +24,36 @@ args = parser.parse_args()
 
 if args.do_clear:
     print("clearing the display ...")
-    from pwnagotchi.ui.waveshare.v2.waveshare import EPD
-
-    epd = EPD()
-    epd.init(epd.FULL_UPDATE)
-    epd.Clear(0xff)
-    quit()
+    with open(args.config, 'rt') as fp:
+      config = yaml.safe_load(fp)
+      cleardisplay=config['ui']['display']['type']
+      if cleardisplay in ('inkyphat', 'inky'):
+              print("inky display")
+              from inky import InkyPHAT
+              epd = InkyPHAT(config['ui']['display']['color'])
+              epd.set_border(InkyPHAT.BLACK)
+              self._render_cb = self._inky_render
+      elif cleardisplay in ('papirus', 'papi'):
+              print("papirus display")
+              from pwnagotchi.ui.papirus.epd import EPD
+              os.environ['EPD_SIZE'] = '2.0'
+              epd = EPD()
+              epd.clear()
+      elif cleardisplay in ('waveshare_1', 'ws_1', 'waveshare1', 'ws1'):
+              print("waveshare v1 display")
+              from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
+              epd = EPD()
+              epd.init(epd.lut_full_update)
+              epd.Clear(0xFF)
+      elif cleardisplay in ('waveshare_2', 'ws_2', 'waveshare2', 'ws2'):
+              print("waveshare v2 display")
+              from pwnagotchi.ui.waveshare.v2.waveshare import EPD
+              epd = EPD()
+              epd.init(epd.FULL_UPDATE)
+              epd.Clear(0xff)
+      else:
+              print("unknown display type %s" % cleardisplay)
+      quit()
 
 with open(args.config, 'rt') as fp:
     config = yaml.safe_load(fp)