Skip to content

Commit

Permalink
working on quality of life improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HelaFaye committed Oct 25, 2019
1 parent 11c2dfb commit fadb802
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ venv.bak/
# JetBrains stuff
.idea/

.android/
.android/ndk
.android/sdk
.buildozer
4 changes: 2 additions & 2 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ source.include_exts = py,png,jpg,kv,atlas
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
version = 0.6
version = 0.7

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
Expand Down Expand Up @@ -74,7 +74,7 @@ osx.kivy_version = 1.9.1
#

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 1
fullscreen = 0

# (string) Presplash background color (for new android toolchain)
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
Expand Down
2 changes: 2 additions & 0 deletions fwget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self, cache):
if not os.path.exists(self.cachePath):
os.makedirs(self.cachePath)
print("Created NineRiFt cache directory")
#self.progress = 0
#self.maxprogress = 100

def setRepo(self, repo):
self.repoURL = repo
Expand Down
14 changes: 9 additions & 5 deletions fwupd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def setproto(self, p):
def getprog(self):
return self.progress

def getmaxprog(self):
return self.maxprogress

def checksum(self, s, data):
for c in data:
s += c
Expand All @@ -68,11 +71,12 @@ def UpdateFirmware(self, link, tran, dev, fwfile):

dev = self.devices.get(self.device)

try:
toast('Pinging...')
except:
print('Pinging...', end='')

for retry in range(self.PING_RETRIES):
try:
toast('Pinging...')
except:
print('Pinging...', end='')
print(".", end="")
try:
if dev == BT.BLE:
Expand All @@ -90,7 +94,7 @@ def UpdateFirmware(self, link, tran, dev, fwfile):
return False
print("OK")

if self.interface != 'fleet':
if not self.interface.endswith('fleet'):
try:
toast('Locking...')
except:
Expand Down
262 changes: 133 additions & 129 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,145 +6,149 @@
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
#from kivy.uix.progressbar import ProgressBar
from kivy.uix.progressbar import ProgressBar
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.filechooser import FileChooserListView
from kivy.uix.textinput import TextInput
from kivy.uix.spinner import Spinner
from kivy.utils import platform
import threading

try:
from kivymd.toast import toast
from kivymd.toast import toast
except:
print('no toast for you')

print('no toast for you')
from fwupd import FWUpd
from fwget import FWGet

class NineRiFt(App):

def build(self):
sm = ScreenManager()
def switch_screen(scrn):
sm.current = scrn
flashscreen = Screen(name='Flash')
downloadscreen = Screen(name='Download')
root_folder = getattr(self, 'user_data_dir')
cache_folder = os.path.join(root_folder, 'cache')
fwget = FWGet(cache_folder)
fwupd = FWUpd()

def fwget_func(dev, ver):
fwget.Gimme(dev, ver)

def fwupd_func(sfile):
fwupd.Flash(sfile)

seladdr_label = Label(text="Addr:", font_size='12sp', height='15sp',
size_hint_y=1, size_hint_x=.08)
seladdr_input = TextInput(multiline=False, text='',
height='15sp', font_size='12sp', size_hint_x=.92, size_hint_y=1)
seladdr_input.bind(on_text_validate=lambda x: fwupd.setaddr(seladdr_input.text))
selfile_label = Label(text="FW file:", font_size='12sp', size_hint_x=1, height='12sp')
if platform != 'android':
ifaceselspin = Spinner(text='Interface', values=('TCP', 'Serial', 'BLE')
, font_size='12sp',height='14sp', sync_height=True)
elif platform == 'android':
ifaceselspin = Spinner(text='Interface', values=('TCP', 'BLE')
, font_size='12sp',height='14sp', sync_height=True)
ifaceselspin.bind(text=lambda x, y: fwupd.setiface(ifaceselspin.text))
devselspin = Spinner(text='Device', values=('BLE', 'ESC', 'BMS', 'ExtBMS'),
sync_height=True, font_size='12sp', height='14sp')
devselspin.bind(text=lambda x, y: fwupd.setdev(devselspin.text))

selfile = FileChooserListView(path=cache_folder)
flash_button = Button(text="Flash It!", font_size='12sp', height='14sp', size_hint_y=.8,
on_press=lambda x: fwupd_func(selfile.selection[0]))

switcherlayout = BoxLayout(orientation='horizontal', size_hint_y=.08)
flashtoplayout = GridLayout(rows=2, size_hint_y=.2)
flashaddrlayout = BoxLayout(orientation='horizontal', size_hint_y=.3)
flashaddrlayout.add_widget(seladdr_label)
flashaddrlayout.add_widget(seladdr_input)
flashtopbtnlayout = GridLayout(cols=2, size_hint_y=.7)
flashtopbtnlayout.add_widget(ifaceselspin)
flashtopbtnlayout.add_widget(devselspin)
flashtoplayout.add_widget(flashaddrlayout)
flashtoplayout.add_widget(flashtopbtnlayout)
flashmidlayout = BoxLayout(orientation='vertical', size_hint_y=.70)
flashmidlabelbox = AnchorLayout(anchor_y='top', size_hint_y=.1)
flashmidlabelbox.add_widget(selfile_label)
flashmidlayout.add_widget(flashmidlabelbox)
flashmidlayout.add_widget(selfile)
flashbotlayout = BoxLayout(orientation='vertical', size_hint_y=.15)
flashbotlayout.add_widget(flash_button)
#botlayout.add_widget(pb)

flashlayout = GridLayout(cols=1, rows=3)
flashlayout.add_widget(flashtoplayout)
flashlayout.add_widget(flashmidlayout)
flashlayout.add_widget(flashbotlayout)
fwget_devselspin = Spinner(text='Device', values=('BLE', 'DRV', 'BMS'),
sync_height=True, font_size='12sp', height='14sp')
fwget_verselspin = Spinner(text='Version', sync_height=True,
font_size='12sp', height='14sp', values = [], text_autoupdate = True)

def fwget_preload():
fwget.setRepo("https://files.scooterhacking.org/esx/fw/repo.json")
fwget.loadRepo(fwget.repoURL)
fwget_preload()

def fwget_dynver(sel):
fwget_verselspin.values = []
if sel == 'BLE':
dev = fwget.BLE
elif sel == 'BMS':
dev = fwget.BMS
elif sel == 'DRV':
dev = fwget.DRV
for i in dev:
fwget_verselspin.values.append(str(i))
return fwget_verselspin.values

fwget_devselspin.bind(text=lambda x, y: fwget_dynver(fwget_devselspin.text))
fwget_download_button = Button(text="Download It!", font_size='12sp', height='14sp',
on_press=lambda x: fwget_func(fwget_devselspin.text, fwget_verselspin.text))

fwget_toplayout = AnchorLayout(anchor_y='top', size_hint_y=.15)
fwget_topbtnlayout = GridLayout(cols=2)
fwget_topbtnlayout.add_widget(fwget_devselspin)
fwget_topbtnlayout.add_widget(fwget_verselspin)
fwget_toplayout.add_widget(fwget_topbtnlayout)
fwget_midlayout = BoxLayout(orientation='vertical', size_hint_y=.70)
fwget_botlayout = AnchorLayout(anchor_y='bottom', size_hint_y=.15)
fwget_botlayout.add_widget(fwget_download_button)
downloadlayout = GridLayout(cols=1, rows=3)
downloadlayout.add_widget(fwget_toplayout)
downloadlayout.add_widget(fwget_midlayout)
downloadlayout.add_widget(fwget_botlayout)

fwupd_screen_btn = Button(text="Flash", font_size='12sp', height='14sp',
on_press=lambda x: switch_screen('Flash'))
fwget_screen_btn = Button(text="Download", font_size='12sp', height='14sp',
on_press=lambda x: switch_screen('Download'))

switcherlayout.add_widget(fwupd_screen_btn)
switcherlayout.add_widget(fwget_screen_btn)

mainlayout = GridLayout(cols=1, rows=2)
mainlayout.add_widget(switcherlayout)

flashscreen.add_widget(flashlayout)
downloadscreen.add_widget(downloadlayout)
sm.add_widget(flashscreen)
sm.add_widget(downloadscreen)

mainlayout.add_widget(sm)

return mainlayout


class NineRiFt(App):
def build(self):
root_folder = getattr(self, 'user_data_dir')
cache_folder = os.path.join(root_folder, 'cache')
fwget = FWGet(cache_folder)
fwupd = FWUpd()
sm = ScreenManager()
def switch_screen(scrn):
sm.current = scrn
flashscreen = Screen(name='Flash')
downloadscreen = Screen(name='Download')


seladdr_label = Label(text="Addr:", font_size='12sp', height='15sp',
size_hint_y=1, size_hint_x=.08)
seladdr_input = TextInput(multiline=False, text='',
height='15sp', font_size='12sp', size_hint_x=.92, size_hint_y=1)
seladdr_input.bind(on_text_validate=lambda x: fwupd.setaddr(seladdr_input.text))
selfile_label = Label(text="FW file:", font_size='12sp', size_hint_x=1, height='12sp')
if platform != 'android':
ifaceselspin = Spinner(text='Interface', values=('TCP', 'Serial', 'BLE')
, font_size='12sp',height='14sp', sync_height=True)
elif platform == 'android':
ifaceselspin = Spinner(text='Interface', values=('TCP', 'BLE')
, font_size='12sp',height='14sp', sync_height=True)
ifaceselspin.bind(text=lambda x, y: fwupd.setiface(ifaceselspin.text))
devselspin = Spinner(text='Device', values=('BLE', 'ESC', 'BMS', 'ExtBMS'),
sync_height=True, font_size='12sp', height='14sp')
devselspin.bind(text=lambda x, y: fwupd.setdev(devselspin.text))
flashpb = ProgressBar(size_hint_x=0.35, value=0, max=100)
flashpb.bind(max=lambda x: fwupd.getmaxprog)
flashpb.bind(value=lambda x: fwupd.getprog)

selfile = FileChooserListView(path=cache_folder)
flash_button = Button(text="Flash It!", font_size='12sp', height='14sp',
on_press=lambda x: fwupd.Flash(selfile.selection[0]))
switcherlayout = BoxLayout(orientation='horizontal', size_hint_y=.08)
flashtoplayout = GridLayout(rows=2, size_hint_y=.2)
flashaddrlayout = BoxLayout(orientation='horizontal', size_hint_y=.3)
flashaddrlayout.add_widget(seladdr_label)
flashaddrlayout.add_widget(seladdr_input)
flashtopbtnlayout = GridLayout(cols=2, size_hint_y=.7)
flashtopbtnlayout.add_widget(ifaceselspin)
flashtopbtnlayout.add_widget(devselspin)
#flashtopbtnlayout.add_widget()
flashtoplayout.add_widget(flashaddrlayout)
flashtoplayout.add_widget(flashtopbtnlayout)
flashmidlayout = BoxLayout(orientation='vertical', size_hint_y=.70)
flashmidlabelbox = AnchorLayout(anchor_y='top', size_hint_y=.1)
flashmidlabelbox.add_widget(selfile_label)
flashmidlayout.add_widget(flashmidlabelbox)
flashmidlayout.add_widget(selfile)
flashbotlayout = GridLayout(rows=2, size_hint_y=.15)
flashbotlayout.add_widget(flash_button)
flashbotlayout.add_widget(flashpb)

flashlayout = GridLayout(cols=1, rows=3)
flashlayout.add_widget(flashtoplayout)
flashlayout.add_widget(flashmidlayout)
flashlayout.add_widget(flashbotlayout)

fwget_devselspin = Spinner(text='Device', values=('BLE', 'DRV', 'BMS'),
sync_height=True, font_size='12sp', height='14sp')
fwget_verselspin = Spinner(text='Version', sync_height=True,
font_size='12sp', height='14sp', values = [], text_autoupdate = True)

def fwget_preload():
fwget.setRepo("https://files.scooterhacking.org/esx/fw/repo.json")
fwget.loadRepo(fwget.repoURL)
fwget_preload()

def fwget_dynver(sel):
fwget_verselspin.values = []
if sel == 'BLE':
dev = fwget.BLE
elif sel == 'BMS':
dev = fwget.BMS
elif sel == 'DRV':
dev = fwget.DRV
for i in dev:
fwget_verselspin.values.append(str(i))
return fwget_verselspin.values

def fwget_func(dev, ver):
try:
toast('download started')
except:
print('download started')
fwget.Gimme(dev, ver)
try:
toast('download finished')
except:
print('download finished')

fwget_devselspin.bind(text=lambda x, y: fwget_dynver(fwget_devselspin.text))
fwget_download_button = Button(text="Download It!", font_size='12sp', height='14sp',
on_press=lambda x: fwget_func(fwget_devselspin.text, fwget_verselspin.text))

fwget_toplayout = AnchorLayout(anchor_y='top', size_hint_y=.15)
fwget_topbtnlayout = GridLayout(cols=2)
fwget_topbtnlayout.add_widget(fwget_devselspin)
fwget_topbtnlayout.add_widget(fwget_verselspin)
fwget_toplayout.add_widget(fwget_topbtnlayout)
fwget_midlayout = BoxLayout(orientation='vertical', size_hint_y=.70)
fwget_botlayout = AnchorLayout(anchor_y='bottom', size_hint_y=.15)
fwget_botlayout.add_widget(fwget_download_button)
downloadlayout = GridLayout(cols=1, rows=3)
downloadlayout.add_widget(fwget_toplayout)
downloadlayout.add_widget(fwget_midlayout)
downloadlayout.add_widget(fwget_botlayout)

fwupd_screen_btn = Button(text="Flash", font_size='12sp', height='14sp',
on_press=lambda x: switch_screen('Flash'))
fwget_screen_btn = Button(text="Download", font_size='12sp', height='14sp',
on_press=lambda x: switch_screen('Download'))

switcherlayout.add_widget(fwupd_screen_btn)
switcherlayout.add_widget(fwget_screen_btn)

mainlayout = GridLayout(cols=1, rows=2)
mainlayout.add_widget(switcherlayout)

flashscreen.add_widget(flashlayout)
downloadscreen.add_widget(downloadlayout)
sm.add_widget(flashscreen)
sm.add_widget(downloadscreen)

mainlayout.add_widget(sm)
return mainlayout

if __name__ == "__main__":
NineRiFt().run()
NineRiFt().run()
4 changes: 2 additions & 2 deletions py9b/link/droidble.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
service_ids = {"retail": "6e400001-b5a3-f393-e0a9-e50e24dcca9e"} # service UUID

receive_ids = {
"retail": "6e400002-b5a3-f393-e0a9-e50e24dcca9e" # receive characteristic UUID
"retail": "6e400002-b5a3-f393-e0a9-e50e24dcca9e"# receive characteristic UUID
}

transmit_ids = {
"retail": "6e400003-b5a3-f393-e0a9-e50e24dcca9e" # transmit characteristic UUID
"retail": "6e400003-b5a3-f393-e0a9-e50e24dcca9e"# transmit characteristic UUID
}


Expand Down

0 comments on commit fadb802

Please sign in to comment.