Skip to content

Commit

Permalink
new module structure for title+interface+servos
Browse files Browse the repository at this point in the history
  • Loading branch information
sh4d0w28 committed Sep 25, 2021
1 parent efc99e0 commit bd5c013
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .vscode/sftp.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"host": "192.168.1.193",
"host": "192.168.1.195",
"username": "pi",
"password": "raspberry",
"remotePath": "/home/pi/robot/work/",
Expand Down
14 changes: 6 additions & 8 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
import time
import RPi.GPIO as GPIO

# from modules.recorder.module_recorder import moduleRecorder
from modules.title.module_title import moduleTitle
# from modules.servos.module_servos import moduleServos
from modules.connectinfo.connectinfo_main import connectInfo
from modules.servos.servos_main import servos
# from modules.pong.module_pong import modulePong
# from modules.update.module_update import moduleUpdate
from modules.interface.module_interface import moduleInterface
# from modules.interface.module_interface import moduleInterface

lcd = LCD_LCD144()

mode = -1
selected = 0

modules = [
moduleTitle(lcd),
# moduleRecorder(lcd),
# moduleServos(lcd),
connectInfo(lcd),
servos(lcd)
# modulePong(lcd),
# moduleUpdate(lcd),
moduleInterface(lcd)
# moduleInterface(lcd)
]

runFlag = 1
Expand Down
58 changes: 58 additions & 0 deletions modules/basemodule.py
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
37 changes: 37 additions & 0 deletions modules/connectinfo/connectinfo_main.py
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)
47 changes: 47 additions & 0 deletions modules/connectinfo/network_helper.py
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 ""
Loading

0 comments on commit bd5c013

Please sign in to comment.