mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 20:03:53 +08:00
* param to control stock vs sp ui * init styles * SP Toggles * Lint * optimizations * sp raylib preview * fix callback * fix ui preview * dialog txt * compare vs what used to be done before InputDialog * merge origin raylib toggles * tree dialog * less trees for the planet * the heck * save the trees we got icons * Update process.py * Remove 'sunnypilot_ui' Removed 'sunnypilot_ui' parameter from params_keys.h * Update raylib_screenshots.py Removed the parameter setting for 'sunnypilot_ui' in the test. * ui: fuzzy search helper * better tree. fully dynamic and stuff * rm * more indent * Squashed commit of the following: commit6b5b686fa5Author: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 17:16:17 2025 -0800 more indent commit76bc538ac7Merge:53eb821dc4c53e2134e2Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 24 17:15:48 2025 -0800 Merge branch 'master' into rl-tree-dialog commit53eb821dc4Merge:82e1ebe97e844f4cbc74Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 24 11:54:55 2025 -0800 Merge branch 'master' into rl-tree-dialog commit82e1ebe97eAuthor: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 10:23:35 2025 -0800 rm commitda3ff45bb6Merge:41da513fcaa829a1b972Author: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 10:19:08 2025 -0800 Merge remote-tracking branch 'origin/rl-tree-dialog' into rl-tree-dialog commit41da513fcaAuthor: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 10:18:43 2025 -0800 better tree. fully dynamic and stuff commitb2950149fbMerge:4fb8e4beed924e5a3211Author: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 10:17:51 2025 -0800 Merge remote-tracking branch 'origin/input-dialog' into rl-tree-dialog commita829a1b972Merge:848290d07e9edc36ca66Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 24 10:16:28 2025 -0800 Merge branch 'master' into rl-tree-dialog commit4fb8e4beedMerge:848290d07eaf4f0f8372Author: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 24 10:16:20 2025 -0800 Merge remote-tracking branch 'origin/fuzzy-dialog' into rl-tree-dialog commitaf4f0f8372Merge:1d5f0ab2823cd55260d9Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 24 06:39:29 2025 -0800 Merge branch 'master' into fuzzy-dialog commit1d5f0ab282Author: discountchubbs <alexgrant990@gmail.com> Date: Sun Nov 23 11:28:59 2025 -0800 ui: fuzzy search helper commit848290d07eAuthor: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 21:08:07 2025 -0800 Update raylib_screenshots.py Removed the parameter setting for 'sunnypilot_ui' in the test. commit6694928a46Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 21:06:57 2025 -0800 Remove 'sunnypilot_ui' Removed 'sunnypilot_ui' parameter from params_keys.h commitb3c90ef7b2Merge:0d3bc959c8457b6634fdAuthor: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 21:06:04 2025 -0800 Merge branch 'master' into rl-tree-dialog commit924e5a3211Merge:a4ee4ba76dd92d2cb683Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 19:33:18 2025 -0800 Merge branch 'master' into input-dialog commita4ee4ba76dMerge:e911de59684f13a0f775Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 16:24:31 2025 -0800 Merge branch 'master' into input-dialog commite911de5968Merge:cea6e008190ba5cbea91Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 13:50:33 2025 -0800 Merge branch 'master' into input-dialog commitcea6e00819Merge:d7b8ce86ed8184cd8a6aAuthor: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 12:01:45 2025 -0800 Merge branch 'master' into input-dialog commit0d3bc959c8Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Wed Nov 19 20:29:30 2025 -0800 Update process.py commit4f3c19ffb5Author: James Vecellio <alexgrant990@gmail.com> Date: Wed Nov 19 20:28:59 2025 -0800 save the trees we got icons commitae5c44355dAuthor: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 13:38:04 2025 -0800 the heck commit066438ad10Merge:9532675814e74460f3a8Author: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 12:18:17 2025 -0800 Merge remote-tracking branch 'origin/rl-tree-dialog' into rl-tree-dialog commit9532675814Author: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 12:17:52 2025 -0800 less trees for the planet commite74460f3a8Merge:c347db376a423a7d2ed0Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Wed Nov 19 09:37:44 2025 -0800 Merge branch 'rl-sp-toggles' into rl-tree-dialog commitc347db376aAuthor: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 09:36:33 2025 -0800 tree dialog commitc9bd67b261Author: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 09:34:08 2025 -0800 merge origin raylib toggles commitd7b8ce86edAuthor: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 17 20:21:33 2025 -0800 compare vs what used to be done before InputDialog commit2d3d104658Merge:ded02895f4f1025f6ee9Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 17 19:24:20 2025 -0800 Merge branch 'master' into input-dialog commitded02895f4Author: discountchubbs <alexgrant990@gmail.com> Date: Mon Nov 17 19:22:01 2025 -0800 dialog txt commit9778a925b0Merge:cb03d0839708e85808c5Author: Jason Wen <haibin.wen3@gmail.com> Date: Sun Nov 16 03:16:58 2025 -0500 input dialog commit423a7d2ed0Author: nayan <nayan8teen@gmail.com> Date: Sun Nov 16 11:15:28 2025 -0500 fix ui preview commite4e10d4b87Author: nayan <nayan8teen@gmail.com> Date: Sun Nov 16 11:15:22 2025 -0500 fix callback commit362e9ce04bAuthor: nayan <nayan8teen@gmail.com> Date: Sun Nov 16 09:53:28 2025 -0500 sp raylib preview commit3946e643f6Author: nayan <nayan8teen@gmail.com> Date: Sat Nov 15 20:24:20 2025 -0500 optimizations commit0c37a38596Author: nayan <nayan8teen@gmail.com> Date: Sat Nov 15 09:42:12 2025 -0500 Lint commit9c5acf61c0Author: nayan <nayan8teen@gmail.com> Date: Sat Nov 15 09:29:07 2025 -0500 SP Toggles commit121b304fe0Author: nayan <nayan8teen@gmail.com> Date: Sat Nov 15 09:28:58 2025 -0500 init styles commit47d848293bAuthor: nayan <nayan8teen@gmail.com> Date: Sat Nov 15 09:28:43 2025 -0500 param to control stock vs sp ui * Squashed commit of the following: commit70ad001addMerge:142663c490844f4cbc74Author: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon Nov 24 11:54:58 2025 -0800 Merge branch 'master' into rl-progress-bar commit142663c490Author: discountchubbs <alexgrant990@gmail.com> Date: Sat Nov 22 20:12:44 2025 -0800 smoother updating commit4476e418ddAuthor: discountchubbs <alexgrant990@gmail.com> Date: Sat Nov 22 09:55:17 2025 -0800 easier to see commitad66c22e88Merge:0c46ef5948457b6634fdAuthor: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Sat Nov 22 07:45:05 2025 -0800 Merge branch 'master' into rl-progress-bar commit0c46ef5948Author: discountchubbs <alexgrant990@gmail.com> Date: Sat Nov 22 07:42:59 2025 -0800 freaking test dir commit11c19aad24Merge:7785238d548184cd8a6aAuthor: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Fri Nov 21 12:01:36 2025 -0800 Merge branch 'master' into rl-progress-bar commit7785238d54Author: discountchubbs <alexgrant990@gmail.com> Date: Wed Nov 19 07:47:10 2025 -0800 raylib: progress bar * OSM panel * fetching * only show if fav_param is used in the call * flattened and custom search query * conditional for mypy * sunny's new x,y makes this even easier! * download all * add back the rough estimate * not sure i like the 'Download' * simplify the path * actual size as of today * format * more simple * only show on download or delete * loathing loathing, unadulterated loathing, i loathe it all * loathing loathing, unadulterated loathing, i loathe it all * # Conflicts: # system/ui/sunnypilot/lib/styles.py # system/ui/sunnypilot/widgets/tree_dialog.py * search * st * Update osm.py * one second updates: its heavy process, which isnt really noticeable during downloads ayways. the once a second ensures responsiveness on the ui, while also maintaining 20fps on device for country/state downloads. * efficient? i hope * big boi texts * big boi texts * use our own classes * need to clear all params when delete all * more * collateral lol * do not behave as selected if canceled during US->States dialog * more * instead of timestamp, let's just show formatted time * disable button when downloading dbs * should be the buttons being disabled * well gotta re-enable them too * empty country * might be bigger now * fixes for mapd manager * should stay as a json * sanitize it a bit * revert * only nuke if the cancel button is called * always try to update the labels * Revert "always try to update the labels" This reverts commitba0988fc06. * re-enable button after download is complete * disable all while downloading (till we could cancel and re-download) * fix progress bar not filling up as intended for smaller total counts * revert * use new --------- Co-authored-by: nayan <nayan8teen@gmail.com> Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
145 lines
5.0 KiB
Python
Executable File
145 lines
5.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
import json
|
|
import platform
|
|
import os
|
|
import glob
|
|
import shutil
|
|
from datetime import datetime
|
|
|
|
from openpilot.common.params import Params
|
|
from openpilot.common.realtime import Ratekeeper, config_realtime_process
|
|
from openpilot.common.swaglog import cloudlog
|
|
from openpilot.selfdrive.selfdrived.alertmanager import set_offroad_alert
|
|
from openpilot.sunnypilot.mapd.live_map_data.osm_map_data import OsmMapData
|
|
from openpilot.system.hardware.hw import Paths
|
|
from openpilot.sunnypilot.mapd import MAPD_PATH
|
|
from openpilot.sunnypilot.mapd.mapd_installer import VERSION, update_installed_version
|
|
|
|
# PFEIFER - MAPD {{
|
|
params = Params()
|
|
mem_params = Params("/dev/shm/params") if platform.system() != "Darwin" else params
|
|
# }} PFEIFER - MAPD
|
|
|
|
|
|
def get_files_for_cleanup() -> list[str]:
|
|
paths = [
|
|
f"{Paths.mapd_root()}/db",
|
|
f"{Paths.mapd_root()}/v*"
|
|
]
|
|
files_to_remove = []
|
|
for path in paths:
|
|
if os.path.exists(path):
|
|
files = glob.glob(path + '/**', recursive=True)
|
|
files_to_remove.extend(files)
|
|
# check for version and mapd files
|
|
if not os.path.isfile(MAPD_PATH):
|
|
files_to_remove.append(MAPD_PATH)
|
|
return files_to_remove
|
|
|
|
|
|
def cleanup_old_osm_data(files_to_remove: list[str]) -> None:
|
|
for file in files_to_remove:
|
|
# Remove trailing slash if path is file
|
|
if file.endswith('/') and os.path.isfile(file[:-1]):
|
|
file = file[:-1]
|
|
# Try to remove as file or symbolic link first
|
|
if os.path.islink(file) or os.path.isfile(file):
|
|
os.remove(file)
|
|
elif os.path.isdir(file): # If it's a directory
|
|
shutil.rmtree(file, ignore_errors=False)
|
|
|
|
|
|
def request_refresh_osm_location_data(nations: list[str], states: list[str] = None) -> None:
|
|
params.put("OsmDownloadedDate", str(datetime.now().timestamp()))
|
|
params.put_bool("OsmDbUpdatesCheck", False)
|
|
|
|
osm_download_locations = {
|
|
"nations": nations,
|
|
"states": states or []
|
|
}
|
|
|
|
print(f"Downloading maps for {json.dumps(osm_download_locations)}")
|
|
mem_params.put("OSMDownloadLocations", osm_download_locations)
|
|
|
|
|
|
def filter_nations_and_states(nations: list[str], states: list[str] = None) -> tuple[list[str], list[str]]:
|
|
"""Filters and prepares nation and state data for OSM map download.
|
|
|
|
If the nation is 'US' and a specific state is provided, the nation 'US' is removed from the list.
|
|
If the nation is 'US' and the state is 'All', the 'All' is removed from the list.
|
|
The idea behind these filters is that if a specific state in the US is provided,
|
|
there's no need to download map data for the entire US. Conversely,
|
|
if the state is unspecified (i.e., 'All'), we intend to download map data for the whole US,
|
|
and 'All' isn't a valid state name, so it's removed.
|
|
|
|
Parameters:
|
|
nations (list): A list of nations for which the map data is to be downloaded.
|
|
states (list, optional): A list of states for which the map data is to be downloaded. Defaults to None.
|
|
|
|
Returns:
|
|
tuple: Two lists. The first list is filtered nations and the second list is filtered states.
|
|
"""
|
|
|
|
if "US" in nations and states and not any(x.lower() == "all" for x in states):
|
|
# If a specific state in the US is provided, remove 'US' from nations
|
|
nations.remove("US")
|
|
elif "US" in nations and states and any(x.lower() == "all" for x in states):
|
|
# If 'All' is provided as a state (case invariant), remove those instances from states
|
|
states = [x for x in states if x.lower() != "all"]
|
|
elif "US" not in nations and states and any(x.lower() == "all" for x in states):
|
|
states.remove("All")
|
|
return nations, states or []
|
|
|
|
|
|
def update_osm_db() -> None:
|
|
if params.get_bool("OsmDbUpdatesCheck"):
|
|
cleanup_old_osm_data(get_files_for_cleanup())
|
|
country = params.get("OsmLocationName", return_default=True)
|
|
state = params.get("OsmStateName", return_default=True)
|
|
filtered_nations, filtered_states = filter_nations_and_states([country], [state])
|
|
request_refresh_osm_location_data(filtered_nations, filtered_states)
|
|
|
|
if not mem_params.get("OSMDownloadBounds"):
|
|
mem_params.put("OSMDownloadBounds", "")
|
|
|
|
if not mem_params.get("LastGPSPosition"):
|
|
mem_params.put("LastGPSPosition", "{}")
|
|
|
|
|
|
def main_thread():
|
|
update_installed_version(VERSION, params)
|
|
config_realtime_process([0, 1, 2, 3], 5)
|
|
|
|
rk = Ratekeeper(1, print_delay_threshold=None)
|
|
live_map_sp = OsmMapData()
|
|
|
|
# Create folder needed for OSM
|
|
try:
|
|
os.mkdir(Paths.mapd_root())
|
|
except FileExistsError:
|
|
pass
|
|
except PermissionError:
|
|
cloudlog.exception(f"mapd: failed to make {Paths.mapd_root()}")
|
|
|
|
while True:
|
|
show_alert = get_files_for_cleanup() and params.get_bool("OsmLocal")
|
|
set_offroad_alert("Offroad_OSMUpdateRequired", show_alert, "This alert will be cleared when new maps are downloaded.")
|
|
|
|
update_osm_db()
|
|
live_map_sp.tick()
|
|
rk.keep_time()
|
|
|
|
|
|
def main():
|
|
main_thread()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|