-
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.
- Loading branch information
Showing
4 changed files
with
47 additions
and
64 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,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() |
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 |
---|---|---|
@@ -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) |