forked from itsdarklikehell/pwnagotchi-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbshim.py
125 lines (102 loc) · 3.41 KB
/
bshim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
import signal
import buttonshim
import subprocess
import sys
import os
libdir = "/home/pi/src/e-Paper/RaspberryPi_JetsonNano/python/lib"
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd2in13b_V3
import time
from PIL import Image, ImageDraw, ImageFont
import traceback
import pwnagotchi.plugins as plugins
class Buttonshim(plugins.Plugin):
__GitHub__ = ""
__author__ = "(edited by: itsdarklikehell [email protected]), [email protected]"
__version__ = "0.0.1"
__license__ = "GPL3"
__description__ = "Pimoroni Button Shim GPIO Button control."
__name__ = "Buttonshim"
__help__ = "Pimoroni Button Shim GPIO Button control."
__dependencies__ = {"pip": ["scapy"]}
__defaults__ = {
"enabled": False,
}
print(
"""
Button SHIM: Control Panel
Press Ctrl+C to exit.
"""
)
def __init__(self):
self.ready = False
logging.debug(f"[{self.__class__.__name__}] plugin init")
self.title = ""
def on_loaded(self):
logging.info(f"[{self.__class__.__name__}] plugin loaded")
def on_unload(self, ui):
logging.info(f"[{self.__class__.__name__}] plugin unloaded")
def on_webhook(self, path, request):
logging.info(f"[{self.__class__.__name__}] webhook pressed")
@buttonshim.on_hold(buttonshim.BUTTON_A, hold_time=2)
def button_a(button):
buttonshim.set_pixel(0x94, 0x00, 0xD3)
try:
os.popen("sudo systemctl restart pwnagotchi.service")
print("Pwnagotchi service restarted successfully...")
except OSError as ose:
print("Error while running the command", ose)
pass
buttonshim.set_pixel(0x00, 0x00, 0x00)
@buttonshim.on_hold(buttonshim.BUTTON_B, hold_time=2)
def button_b(button):
buttonshim.set_pixel(0x94, 0x00, 0xD3)
try:
os.popen("sudo systemctl start pwnagotchi.service")
print("Pwnagotchi service started successfully...")
except OSError as ose:
print("Error while running the command", ose)
pass
buttonshim.set_pixel(0x00, 0x00, 0x00)
@buttonshim.on_hold(buttonshim.BUTTON_C, hold_time=2)
def button_c(button):
buttonshim.set_pixel(0x94, 0x00, 0xD3)
try:
os.popen("sudo systemctl stop pwnagotchi.service")
print("Pwnagotchi service stopped successfully...")
except OSError as ose:
print("Error while running the command", ose)
pass
buttonshim.set_pixel(0x00, 0x00, 0x00)
@buttonshim.on_press(buttonshim.BUTTON_D)
def button_d(button, pressing):
acstat = subprocess.call(["systemctl", "is-active", "--quiet", "pwnagotchi"])
if acstat == 0:
buttonshim.set_pixel(0, 255, 0)
else:
buttonshim.set_pixel(255, 0, 0)
@buttonshim.on_hold(buttonshim.BUTTON_D, hold_time=2)
def button_d(button):
buttonshim.set_pixel(0, 0, 0)
@buttonshim.on_hold(buttonshim.BUTTON_E, hold_time=2)
def button_e(button):
buttonshim.set_pixel(0x94, 0x00, 0xD3)
logging.basicConfig(level=logging.DEBUG)
try:
epd = epd2in13b_V3.EPD()
logging.info("Screen clean...")
epd.init()
epd.Clear()
epd.Clear()
# logging.info("Sleep screen...")
# epd.sleep()
# except IOError as e:
# logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd2in13b_V3.epdconfig.module_exit()
buttonshim.set_pixel(0x00, 0x00, 0x00)
# signal.pause()