-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new module structure for title+interface+servos
- Loading branch information
Showing
10 changed files
with
243 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from gdep.LCD144 import KEY1_PIN, KEY2_PIN, KEY3_PIN, KEY_DOWN_PIN, KEY_LEFT_PIN, KEY_PRESS_PIN, KEY_RIGHT_PIN, KEY_UP_PIN, LCD_LCD144 | ||
import RPi.GPIO as GPIO | ||
import threading | ||
import time | ||
|
||
class basemodule: | ||
|
||
# global values for module | ||
lcd: LCD_LCD144 | ||
runFlag = None | ||
buttonStates = { | ||
KEY1_PIN: 1, | ||
KEY2_PIN: 1, | ||
KEY3_PIN: 1, | ||
KEY_RIGHT_PIN: 1, | ||
KEY_DOWN_PIN: 1, | ||
KEY_UP_PIN: 1, | ||
KEY_PRESS_PIN: 1, | ||
KEY_LEFT_PIN: 1 | ||
} | ||
|
||
def default_exit_on_press_left(self): | ||
self.runFlag = 0 | ||
|
||
buttonPressHandlers = { | ||
KEY_LEFT_PIN: default_exit_on_press_left | ||
} | ||
|
||
def __init__(self, lcd) -> None: | ||
self.lcd = lcd | ||
self.init() | ||
|
||
def buttonHandler(self): | ||
while self.runFlag == 1: | ||
for button in self.buttonStates: | ||
if GPIO.input(button) != self.buttonStates[button]: | ||
self.buttonStates[button] = GPIO.input(button) | ||
# print(str(button) + ' = ' + str(self.buttonStates[button])) | ||
if GPIO.input(button) == 0 and self.buttonPressHandlers.get(button): | ||
self.buttonPressHandlers.get(button)(self) | ||
|
||
def run(self): | ||
self.runFlag = 1 | ||
process = threading.Thread(target=self.buttonHandler) | ||
process.start(); | ||
while self.runFlag == 1: | ||
self.mainFlow() | ||
self.lcd.disp.LCD_ShowImage(self.lcd.image,0,0) | ||
time.sleep(0.05) | ||
|
||
def title(self): | ||
return "DEFINE TITLE():STRING" | ||
|
||
def init(self): | ||
pass | ||
|
||
def mainFlow(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from modules.basemodule import basemodule | ||
from modules.connectinfo.network_helper import networkHelper | ||
|
||
class connectInfo(basemodule): | ||
|
||
def title(self): | ||
return "Connection status" | ||
|
||
def mainFlow(self): | ||
self.lcd.draw.rectangle((0,0,128,128), outline=0, fill=0) | ||
|
||
wifisid = networkHelper.getWifiSsid() | ||
extIp = networkHelper.getExtIp() | ||
ngrokIps = networkHelper.getNgrokIp() | ||
|
||
self.lcd.draw.text((2,5), "WiFi:" ,fill=(255,255,255,128)) | ||
self.lcd.draw.text((33,5), wifisid ,fill=(255,255,255,128)) | ||
|
||
self.lcd.draw.text((2,15), "IP:" ,fill=(255,255,255,128)) | ||
self.lcd.draw.text((33,15), extIp ,fill=(255,255,255,128)) | ||
|
||
try: | ||
tcps = ngrokIps['tcpurl'].split(b':') | ||
self.lcd.draw.text((2,35), "TCP:" ,fill=(128,255,128,128)) | ||
self.lcd.draw.text((33,35), tcps[1][2:] ,fill=(128,255,128,128)) | ||
self.lcd.draw.text((2,45), "PORT:" ,fill=(128,255,128,128)) | ||
self.lcd.draw.text((33,45), tcps[2] ,fill=(128,255,128,128)) | ||
except Exception as e: | ||
print(e) | ||
|
||
try: | ||
hcps = ngrokIps['httpurl'].split(b':') | ||
self.lcd.draw.text((2,65), "HTTP:" ,fill=(128,255,128,128)) | ||
self.lcd.draw.text((2,75), hcps[1][2:] ,fill=(128,255,128,128)) | ||
self.lcd.draw.text((70,85), ".ngrok.io" ,fill=(128,255,128,128)) | ||
except Exception as e: | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import subprocess | ||
|
||
class networkHelper: | ||
|
||
def getWifiSsid(): | ||
try: | ||
output = subprocess.check_output(['/usr/sbin/iwgetid']) | ||
wifissid = str(output).split('"')[1] | ||
return wifissid | ||
except IndexError as e: | ||
return "" | ||
except subprocess.CalledProcessError as e: | ||
print(e.output) | ||
return "" | ||
|
||
def getNgrokIp(): | ||
resultUrl = { | ||
"tcpurl" : "", | ||
"httpurl": "" | ||
} | ||
try: | ||
output = subprocess.check_output(['curl http://127.0.0.1:4040/api/tunnels | jq ".tunnels[].public_url"'], shell=True) | ||
urls = output.splitlines() | ||
for url in urls: | ||
cleanurl = url.strip(b'"') | ||
if cleanurl.startswith(b'tcp'): | ||
resultUrl['tcpurl'] = cleanurl | ||
if cleanurl.startswith(b'https'): | ||
resultUrl['httpurl'] = cleanurl.replace(b".ngrok.io", b"") | ||
except IndexError as e: | ||
return resultUrl | ||
except subprocess.CalledProcessError as e: | ||
print(e.output) | ||
return resultUrl | ||
|
||
return resultUrl | ||
|
||
def getExtIp(): | ||
try: | ||
output = subprocess.check_output(['hostname', '-I']) | ||
localip = str(output).split(' ')[0].split("'")[1] | ||
return localip | ||
except IndexError as e: | ||
return "" | ||
except subprocess.CalledProcessError as e: | ||
print(e.output) | ||
return "" |
Oops, something went wrong.