Skip to content

Commit

Permalink
new launcher with updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sh4d0w28 committed Sep 25, 2021
1 parent bd5c013 commit 9f9199f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 64 deletions.
6 changes: 3 additions & 3 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.update.module_update import moduleUpdate
# from modules.interface.module_interface import moduleInterface

lcd = LCD_LCD144()
Expand All @@ -16,9 +16,9 @@

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

Expand Down
3 changes: 1 addition & 2 deletions modules/basemodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def buttonHandler(self):
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)
self.buttonPressHandlers.get(button)()

def run(self):
self.runFlag = 1
Expand Down
26 changes: 26 additions & 0 deletions modules/update/githubutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import subprocess
import json

class githubutil:

def checkVersion():
pass

def fullUpdate():
output = subprocess.check_output(['curl https://api.github.com/repos/sh4d0w28/raspberry-pi-experiments/releases/latest'], shell=True)
release = json.loads(output.decode())

tarball = release['tarball_url']
tag = release['tag_name']
comment = release['name']

subprocess.run(['cd /home/pi/robot && wget ' + tarball + ' -O - | tar -xz'], shell=True)
dirs = os.scandir("/home/pi/robot")
for dir in dirs:
if dir.is_dir and dir.name.startswith("sh4d0w28"):
subprocess.run(['cd /home/pi/robot && rm -rf work && mv ' + dir.name + ' work'], shell=True)
subprocess.run(['echo "' + tag +'\n' + comment + '" | tee /home/pi/robot/work/release.txt'], shell=True)

if __name__=='__main__':
githubutil.fullUpdate()
76 changes: 17 additions & 59 deletions modules/update/module_update.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,25 @@
import os
import sys
import RPi.GPIO as GPIO
from gdep.LCD144 import KEY1_PIN, KEY2_PIN, KEY_LEFT_PIN
from modules.update.githubutil import githubutil
from gdep.LCD144 import KEY1_PIN, KEY2_PIN
from modules.basemodule import basemodule

import json
import time
import subprocess

class moduleUpdate:
class moduleUpdate(basemodule):

def update(self):
self.status = "downloading..."
try:
output = subprocess.check_output(['cd /home/pi/robot/work && git pull'], shell=True)
if str(output) == 'b\'Already up to date.\\n\'':
self.status = "no new data"
else:
self.status = "download ok"
except subprocess.CalledProcessError as e:
print(e.output)
self.status = "download failed"



lcd = None
runFlag = None
status = ""

downloading = False

def __init__(self, lcd) -> None:
self.lcd = lcd

def title(self):
return "UPDATE"

def run(self):

self.runFlag = 1
while self.runFlag == 1:

self.lcd.draw.rectangle((0,0,128,128), outline=0, fill=0)

if GPIO.input(5) == 0: # press left - close
self.runFlag = 0

if GPIO.input(KEY1_PIN) == 0: # update
self.update()

if GPIO.input(KEY2_PIN) == 0: # restart
os.execv(sys.executable, ['python3'] + [os.path.abspath(sys.argv[0])])

self.lcd.draw.text((80,27), "Download" ,fill=(255,255,255,128))

self.lcd.draw.text((85,58), "Restart" ,fill=(255,255,255,128))
return "Update"

self.lcd.draw.text((5,90), self.status ,fill=(255,0,0,128))
def button_key_1_pin_handler(self):
githubutil.fullUpdate();


self.lcd.draw.text((5,112), "(c)" ,fill=(255,255,255,128))
self.lcd.draw.text((30,108), "Maksim Edush" ,fill=(255,255,255,128))
self.lcd.draw.text((40,118), "sh4d0w28" ,fill=(255,255,255,128))
def button_key_2_pin_handler(self):
os.execv()

self.lcd.disp.LCD_ShowImage(self.lcd.image,0,0)
def init(self):
self.buttonPressHandlers[KEY1_PIN] = self.button_key_1_pin_handler
self.buttonPressHandlers[KEY2_PIN] = self.button_key_2_pin_handler

time.sleep(0.1)
def mainFlow(self):
self.lcd.draw.rectangle((0,0,128,128), outline=0, fill=0)
self.lcd.draw.text((80,27), "Download" ,fill=(255,255,255,128))
self.lcd.draw.text((85,58), "Restart" ,fill=(255,255,255,128))
self.lcd.disp.LCD_ShowImage(self.lcd.image,0,0)

0 comments on commit 9f9199f

Please sign in to comment.