Skip to content

Commit

Permalink
add switch GUI option, add auto activity upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Aug 14, 2024
1 parent d7fbdb9 commit 91eff48
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np
import oyaml as yaml


from logger import CustomRotatingFileHandler, app_logger
from modules.map_config import add_map_config
from modules.helper.setting import Setting
Expand Down Expand Up @@ -230,6 +229,8 @@ class Config:

# GUI mode
G_GUI_MODE = "PyQt"
#G_GUI_MODE = "QML"
#G_GUI_MODE = "Kivy"

# PerformanceGraph:
# 1st: POWER
Expand Down Expand Up @@ -283,6 +284,8 @@ class Config:
G_GPS_KEEP_ON_COURSE_CUTOFF = int(60 / G_GPS_INTERVAL) # [s]

G_UPLOAD_FILE = ""
G_AUTO_UPLOAD = False
G_AUTO_UPLOAD_SERVICE = {"STRAVA": True, "RWGPS": False, "GARMIN": False,}
# STRAVA token (need to write setting.conf manually)
G_STRAVA_API_URL = {
"OAUTH": "https://www.strava.com/oauth/token",
Expand Down Expand Up @@ -324,7 +327,6 @@ class Config:
G_GARMINCONNECT_API = {
"EMAIL": "",
"PASSWORD": "",
"URL_UPLOAD_DIFF": "proxy/upload-service/upload/.fit", # https://connect.garmin.com/modern/proxy/upload-service/upload/.fit
}

G_GOOGLE_DIRECTION_API = {
Expand Down Expand Up @@ -411,6 +413,7 @@ def __init__(self):
parser.add_argument("--demo", action="store_true", default=False)
parser.add_argument("--version", action="version", version="%(prog)s 0.1")
parser.add_argument("--layout")
parser.add_argument("--gui")
parser.add_argument("--headless", action="store_true", default=False)
parser.add_argument("--output_log", action="store_true", default=False)

Expand All @@ -425,6 +428,8 @@ def __init__(self):
self.G_DUMMY_OUTPUT = True
if args.layout and os.path.exists(args.layout):
self.G_LAYOUT_FILE = args.layout
if args.gui and args.gui in ["PyQt", "QML", "Kivy"]:
self.G_GUI_MODE = args.gui
if args.headless:
self.G_HEADLESS = True
if args.output_log:
Expand Down Expand Up @@ -511,21 +516,27 @@ def __init__(self):
self.button_config = Button_Config(self)

def init_loop(self, call_from_gui=False):
if self.G_GUI_MODE == "PyQt":
if self.G_GUI_MODE in ["PyQt", "QML"]:
if call_from_gui:
# workaround for latest qasync and older version(~0.24.0)
asyncio.events._set_running_loop(self.loop)
asyncio.set_event_loop(self.loop)
self.start_coroutine()
else:
self.loop = asyncio.get_event_loop()
if call_from_gui:
self.loop = asyncio.get_event_loop()
self.loop.set_debug(True)
asyncio.set_event_loop(self.loop)

def start_coroutine(self):
self.logger.start_coroutine()
self.display.start_coroutine()

# delay init start
asyncio.create_task(self.delay_init())

async def start_coroutine_async(self):
self.start_coroutine()

async def delay_init(self):
await asyncio.sleep(0.01)
Expand Down Expand Up @@ -638,9 +649,6 @@ async def keyboard_check(self):
self.gui.press_shift_tab()
elif key == "b" and self.gui:
self.gui.back_menu()
# test other functions
elif key == "c" and self.gui:
self.gui.get_screenshot()
except asyncio.CancelledError:
pass

Expand Down Expand Up @@ -699,7 +707,7 @@ async def kill_tasks(self):
tasks = asyncio.all_tasks()
current_task = asyncio.current_task()
for task in tasks:
if self.G_GUI_MODE == "PyQt":
if self.G_GUI_MODE in ["PyQt", "QML"]:
if task == current_task or task.get_coro().__name__ in [
"update_display"
]:
Expand All @@ -714,6 +722,7 @@ async def kill_tasks(self):

async def quit(self):
app_logger.info("quit")

if self.ble_uart is not None:
await self.ble_uart.quit()
await self.network.quit()
Expand All @@ -731,19 +740,14 @@ async def quit(self):
await asyncio.sleep(0.5)
await self.kill_tasks()
self.logger.remove_handler()
app_logger.info("quit done")

def poweroff(self):
# TODO
# should be replaced by quit() with power_off option
# keep the logic for now but remove the shutdown service eg:
# if we are running through a service, stop it and issue power-off command (on rasp-pi only)

# this returns 0 if active
app_logger.info("quit done")

if is_running_as_service():
exec_cmd(["sudo", "systemctl", "stop", "pizero_bikecomputer"])
if self.G_IS_RASPI:
async def power_off(self):
service_state = is_running_as_service() if self.G_IS_RASPI else False

await self.quit()
if service_state and self.G_IS_RASPI:
exec_cmd(["sudo", "poweroff"])

def reboot(self):
Expand Down

0 comments on commit 91eff48

Please sign in to comment.