Skip to content

Commit

Permalink
Updating to main
Browse files Browse the repository at this point in the history
mrosseel committed Jan 26, 2025

Verified

This commit was signed with the committer’s verified signature.
Lyrisbee lyrisbee
1 parent 47d9eba commit 9edf2bb
Showing 18 changed files with 636 additions and 247 deletions.
7 changes: 0 additions & 7 deletions default_config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{
"display_brightness": 255,
"keypad_brightness": "0",
"last_location": {
"lat": 34.0,
"lon": -118.0,
"altitude": 51.0,
"gps_lock": false,
"timezone": "America/Los_Angeles"
},
"camera_exp": 400000,
"camera_gain": 20,
"menu_anim_speed": 0.1,
18 changes: 9 additions & 9 deletions pifinder_post_update.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
git submodule update --init --recursive
sudo pip install -r /home/pifinder/PiFinder/python/requirements.txt
# sudo pip install -r ./python/ments.txt

# Set up migrations folder if it does not exist
if ! [ -d "/home/pifinder/PiFinder_data/migrations" ]
if ! [ -d "~/PiFinder_data/migrations" ]
then
mkdir /home/pifinder/PiFinder_data/migrations
mkdir ~/PiFinder_data/migrations
fi

# v1.x.x
# everying prior to selecitve migrations
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v1.x.x" ]
if ! [ -f "~/PiFinder_data/migrations/v1.x.x" ]
then
source /home/pifinder/PiFinder/migration_source/v1.x.x.sh
touch /home/pifinder/PiFinder_data/migrations/v1.x.x
source ./migration_source/v1.x.x.sh
touch ~/PiFinder_data/migrations/v1.x.x
fi

# v2.1.0
# Switch to Cedar
if ! [ -f "/home/pifinder/PiFinder_data/migrations/v2.1.0" ]
if ! [ -f "~/PiFinder_data/migrations/v2.1.0" ]
then
source /home/pifinder/PiFinder/migration_source/v2.1.0.sh
touch /home/pifinder/PiFinder_data/migrations/v2.1.0
source ./migration_source/v2.1.0.sh
touch ~/PiFinder_data/migrations/v2.1.0
fi

# DONE
14 changes: 8 additions & 6 deletions python/PiFinder/calc_utils.py
Original file line number Diff line number Diff line change
@@ -142,14 +142,14 @@ def aim_degrees(shared_state, mount_type, screen_direction, target):
solution = shared_state.solution()
location = shared_state.location()
dt = shared_state.datetime()
if location and dt and solution:
if location.lock and dt and solution:
if mount_type == "Alt/Az":
if solution["Alt"]:
# We have position and time/date!
sf_utils.set_location(
location["lat"],
location["lon"],
location["altitude"],
location.lat,
location.lon,
location.altitude,
)
target_alt, target_az = sf_utils.radec_to_altaz(
target.ra,
@@ -180,8 +180,8 @@ def calc_object_altitude(shared_state, obj) -> Optional[float]:
dt = shared_state.datetime()
if location and dt and solution:
aa = FastAltAz(
location["lat"],
location["lon"],
location.lat,
location.lon,
dt,
)
alt, _ = aa.radec_to_altaz(
@@ -412,6 +412,8 @@ def calc_planets(self, dt):
'altaz': (1.667930045300066, 228.61434416619613)},
}
"""
if not self.observer_loc:
return {}
t = self.ts.from_datetime(dt)
observer = self.observer_loc.at(t)
planet_dict = {}
9 changes: 5 additions & 4 deletions python/PiFinder/catalogs.py
Original file line number Diff line number Diff line change
@@ -182,8 +182,8 @@ def calc_fast_aa(self, shared_state):
dt = shared_state.datetime()
if location and dt and solution:
self.fast_aa = calc_utils.FastAltAz(
location["lat"],
location["lon"],
location.lat,
location.lon,
dt,
)
else:
@@ -643,8 +643,9 @@ def init_planets(self, dt):
planet_dict = sf_utils.calc_planets(dt)
sequence = 0
for name in sf_utils.planet_names:
if name.lower() != "sun":
self.add_planet(sequence, name, planet_dict[name])
planet_data = planet_dict.get(name, None)
if name.lower() != "sun" and planet_data:
self.add_planet(sequence, name, planet_data)
sequence += 1
with self.virtual_id_lock:
new_low = self.assign_virtual_object_ids(self, self.virtual_id_low)
1 change: 1 addition & 0 deletions python/PiFinder/config.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ def __init__(self):
self._config_dict = {}
else:
with open(self.config_file_path, "r") as config_file:
print("Loading config from", self.config_file_path)
self._config_dict = json.load(config_file)

# open default default_config
2 changes: 1 addition & 1 deletion python/PiFinder/gps_fake.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ def gps_monitor(gps_queue, console_queue, log_queue):
time.sleep(0.5)
fix = (
"fix",
{"lat": 34.22, "lon": -118.22, "altitude": 22},
{"lat": 34.22, "lon": -118.22, "altitude": 22, "source": "fakeGPS"},
)
gps_queue.put(fix)
tm = ("time", datetime.datetime.now())
17 changes: 17 additions & 0 deletions python/PiFinder/gps_pi.py
Original file line number Diff line number Diff line change
@@ -111,6 +111,23 @@ async def gps_main(gps_queue, console_queue, log_queue):
client, gps_queue, console_queue, gps_locked
),
)
logger.debug("last reading is %s", result)
if result.get("lat") and result.get("lon") and result.get("altHAE"):
if gps_locked is False:
gps_locked = True
console_queue.put("GPS: Locked")
logger.debug("GPS locked")
msg = (
"fix",
{
"lat": result.get("lat"),
"lon": result.get("lon"),
"altitude": result.get("altHAE"),
"source": "GPS",
},
)
logger.debug("GPS fix: %s", msg)
gps_queue.put(msg)

logger.debug("GPS sleeping now for 7s")
await asyncio.sleep(7)
6 changes: 3 additions & 3 deletions python/PiFinder/integrator.py
Original file line number Diff line number Diff line change
@@ -103,9 +103,9 @@ def integrator(shared_state, solver_queue, console_queue, log_queue, is_debug=Fa
if location and dt:
# We have position and time/date!
calc_utils.sf_utils.set_location(
location["lat"],
location["lon"],
location["altitude"],
location.lat,
location.lon,
location.altitude,
)
alt, az = calc_utils.sf_utils.radec_to_altaz(
solved["RA"],
46 changes: 23 additions & 23 deletions python/PiFinder/main.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@
from PiFinder.ui.console import UIConsole
from PiFinder.ui.menu_manager import MenuManager

from PiFinder.state import SharedStateObj, UIState
from PiFinder.state import SharedStateObj, UIState, Location

from PiFinder.image_util import subtract_background

@@ -347,18 +347,18 @@ def main(

# Load last location, set lock to false
tz_finder = TimezoneFinder()
initial_location = cfg.get_option("last_location")
initial_location["timezone"] = tz_finder.timezone_at(
lat=initial_location["lat"], lng=initial_location["lon"]
)
initial_location["gps_lock"] = False
initial_location["last_gps_lock"] = None
shared_state.set_location(initial_location)
sf_utils.set_location(
initial_location["lat"],
initial_location["lon"],
initial_location["altitude"],
)
# initial_location = cfg.get_option("last_location")
# initial_location["timezone"] = tz_finder.timezone_at(
# lat=initial_location["lat"], lng=initial_location["lon"]
# )
# initial_location["gps_lock"] = False
# initial_location["last_gps_lock"] = None
# shared_state.set_location(initial_location)
# sf_utils.set_location(
# initial_location["lat"],
# initial_location["lon"],
# initial_location["altitude"],
# )

console.write(" Camera")
console.update()
@@ -479,23 +479,23 @@ def main(
if gps_msg == "fix":
# logger.debug("GPS fix msg: %s", gps_content)
if gps_content["lat"] + gps_content["lon"] != 0:
location = shared_state.location()
location["lat"] = gps_content["lat"]
location["lon"] = gps_content["lon"]
location["altitude"] = gps_content["altitude"]
location["last_gps_lock"] = (
location: Location = shared_state.location()
location.lat = gps_content["lat"]
location.lon = gps_content["lon"]
location.altitude = gps_content["altitude"]
location.last_gps_lock = (
datetime.datetime.now().time().isoformat()[:8]
)
if location["gps_lock"] is False:
if not location.lock:
# Write to config if we just got a lock
location["timezone"] = tz_finder.timezone_at(
lat=location["lat"], lng=location["lon"]
location.timezone = tz_finder.timezone_at(
lat=location.lat, lng=location.lon
)
cfg.set_option("last_location", location)
console.write(
f'GPS: Location {location["lat"]} {location["lon"]} {location["altitude"]}'
f'GPS: Location {location.lat} {location.lon} {location.altitude}'
)
location["gps_lock"] = True
location.lock = True

shared_state.set_location(location)
if gps_msg == "time":
6 changes: 3 additions & 3 deletions python/PiFinder/obslog.py
Original file line number Diff line number Diff line change
@@ -57,9 +57,9 @@ def session_uuid(self):

self.db.create_obs_session(
local_time.timestamp(),
location["lat"],
location["lon"],
location["timezone"],
location.lat,
location.lon,
location.timezone,
self.__session_uuid,
)

9 changes: 5 additions & 4 deletions python/PiFinder/server.py
Original file line number Diff line number Diff line change
@@ -638,6 +638,7 @@ def gps_lock(lat: float = 50, lon: float = 3, altitude: float = 10):
"lat": lat,
"lon": lon,
"altitude": altitude,
"source": "WEB",
},
)
self.gps_queue.put(msg)
@@ -679,11 +680,11 @@ def update_gps(self):
logging.debug(
"self shared state is %s and location is %s", self.shared_state, location
)
if location["gps_lock"] is True:
if location.lock is True:
self.gps_locked = True
self.lat = location["lat"]
self.lon = location["lon"]
self.altitude = location["altitude"]
self.lat = location.lat
self.lon = location.lon
self.altitude = location.altitude
else:
self.gps_locked = False
self.lat = None
47 changes: 44 additions & 3 deletions python/PiFinder/state.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,9 @@
import logging
from typing import List
from PiFinder.composite_object import CompositeObject
from typing import Optional
from dataclasses import dataclass, asdict
import json

logger = logging.getLogger("SharedState")

@@ -117,14 +120,52 @@ def __repr__(self):
'Dec_target': 15.347716050003328, 'T_extract': 75.79255499877036, 'Alt': None, 'Az': None, 'solve_source': 'CAM', 'constellation': 'Psc'},
imu={'moving': False, 'move_start': 1695297928.69749, 'move_end': 1695297928.764207, 'pos': [171.39798541261814, 202.7646132036331, 358.2794741322842],
'start_pos': [171.4009455613444, 202.76321535004726, 358.2587208386012], 'status': 3},
location={'lat': 59.05139745, 'lon': 7.987654, 'altitude': 151.4, 'gps_lock': False, 'timezone': 'Europe/Stockholm', 'last_gps_lock': None},
location={'lat': 59.05139745, 'lon': 7.987654, 'altitude': 151.4, 'source': 'GPS', gps_lock': False, 'timezone': 'Europe/Stockholm', 'last_gps_lock': None},
datetime=None,
screen=<PIL.Image.Image image mode=RGB size=128x128 at 0xE693C910>,
solve_pixel=[305.6970520019531, 351.9438781738281]
)
"""


@dataclass
class Location:
"""
the location of the observer, lat/lon/altitude and the source of the data.
"""
lat: float = 0.0
lon: float = 0.0
altitude: float = 0.0
source: str = "None"
lock: bool = False
timezone: Optional[str] = None
last_gps_lock: Optional[str] = None

def __str__(self):
return f"Location(lat={self.lat:.6f}, " \
f"lon={self.lon:.6f}, alt={self.altitude:.1f}m, " \
f"source={self.source}, alt={self.altitude:.1f}m, " \
f"Lock: {'Yes' if self.lock else 'No'})"

def to_dict(self):
"""Convert the Location object to a dictionary."""
return asdict(self)

def to_json(self):
"""Convert the Location object to a JSON string."""
return json.dumps(self.to_dict())

@classmethod
def from_dict(cls, data):
"""Create a Location object from a dictionary."""
return cls(**data)

@classmethod
def from_json(cls, json_str):
"""Create a Location object from a JSON string."""
data = json.loads(json_str)
return cls.from_dict(data)

class SharedStateObj:
def __init__(self):
self.__power_state = 1
@@ -139,7 +180,7 @@ def __init__(self):
self.__solution = None
self.__sats = None
self.__imu = None
self.__location = None
self.__location: Location = Location()
self.__datetime = None
self.__datetime_time = None
self.__screen = None
@@ -233,7 +274,7 @@ def local_datetime(self):
return self.datetime()

dt = self.datetime()
return dt.astimezone(pytz.timezone(self.__location["timezone"]))
return dt.astimezone(pytz.timezone(self.__location.timezone))

def set_datetime(self, dt):
if dt.tzname() is None:
2 changes: 1 addition & 1 deletion python/PiFinder/ui/base.py
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ def screen_update(self, title_bar=True, button_hints=True) -> None:
moving = True if imu and imu["pos"] and imu["moving"] else False

# GPS status
if self.shared_state.location()["gps_lock"]:
if self.shared_state.location().lock:
self._gps_brightness = 0
else:
gps_anim = int(128 * (time.time() - self.last_update_time)) + 1
2 changes: 1 addition & 1 deletion python/PiFinder/ui/console.py
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ def screen_update(self, title_bar=True, button_hints=True):
moving = True if imu and imu["pos"] and imu["moving"] else False

# GPS status
if self.shared_state.location()["gps_lock"]:
if self.shared_state.location().lock:
self._gps_brightness = 0
else:
gps_anim = int(128 * (time.time() - self.last_update_time)) + 1
164 changes: 164 additions & 0 deletions python/PiFinder/ui/gpsstatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
This module contains all the UI Module classes
"""

import time
from PiFinder import state_utils
from PiFinder.ui.base import UIModule


class UIGPSStatus(UIModule):
"""
UI for seeing GPS status
"""

__title__ = "GPS"

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def update(self, force=False):
state_utils.sleep_for_framerate(self.shared_state)
self.clear_screen()
draw_pos = self.display_class.titlebar_height + 2
location = self.shared_state.location()
sats = self.shared_state.sats()
if sats is None:
sats = (0, 0)
self.draw.text(
(0, draw_pos),
f"Sats seen: {sats[0]}",
font=self.fonts.base.font,
fill=self.colors.get(128),
)
draw_pos += 10

self.draw.text(
(0, draw_pos),
f"Sats used: {sats[1]}",
font=self.fonts.base.font,
fill=self.colors.get(128),
)
draw_pos += 10

self.draw.text(
(10, draw_pos),
f"Lock: {location.lock}",
font=self.fonts.bold.font,
fill=self.colors.get(192),
)
draw_pos += 16

if location.lock:
self.draw.text(
(0, draw_pos),
f"Source: {location.source}",
font=self.fonts.base.font,
fill=self.colors.get(128),
)
draw_pos += 10

# self.draw.text(
# (10, draw_pos),
# f"{self._release_version}",
# font=self.fonts.bold.font,
# fill=self.colors.get(192),
# )
#
# if self._wifi_mode != "Client":
# self.draw.text(
# (10, 90),
# "WiFi must be",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# self.draw.text(
# (10, 105),
# "client mode",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# return self.screen_update()
#
# if self._release_version == "-.-.-":
# self.draw.text(
# (10, 90),
# "Checking for",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# self.draw.text(
# (10, 105),
# f"updates{'.' * int(self._elipsis_count / 10)}",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# self._elipsis_count += 1
# if self._elipsis_count > 39:
# self._elipsis_count = 0
# return self.screen_update()
#
# if self._release_version.strip() == self._software_version.strip():
# self.draw.text(
# (10, 90),
# "No Update",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# self.draw.text(
# (10, 105),
# "needed",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# return self.screen_update()
#
# # If we are here, go for update!
# self._go_for_update = True
# self.draw.text(
# (10, 90),
# "Update Now",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# self.draw.text(
# (10, 105),
# "Cancel",
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )
# if self._option_select == "Update":
# ind_pos = 90
# else:
# ind_pos = 105
# self.draw.text(
# (0, ind_pos),
# self._RIGHT_ARROW,
# font=self.fonts.large.font,
# fill=self.colors.get(255),
# )

return self.screen_update()

# def toggle_option(self):
# if not self._go_for_update:
# return
# if self._option_select == "Update":
# self._option_select = "Cancel"
# else:
# self._option_select = "Update"
#
# def key_up(self):
# self.toggle_option()
#
# def key_down(self):
# self.toggle_option()
#
# def key_right(self):
# if self._option_select == "Cancel":
# self.remove_from_stack()
# else:
# self.update_software()
519 changes: 348 additions & 171 deletions python/PiFinder/ui/menu_structure.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions python/PiFinder/ui/status.py
Original file line number Diff line number Diff line change
@@ -270,11 +270,11 @@ def update_status_dict(self):
sats = self.shared_state.sats()
self.status_dict["GPS"] = [
f"GPS {sats[0]}/{sats[1]}" if sats else "GPS 0/0",
f"{location['lat']:.2f}/{location['lon']:.2f}",
f"{location.lat:.2f}/{location.lon:.2f}",
]

self.status_dict["GPS ALT"] = f"{location['altitude']:.1f}m"
last_lock = location["last_gps_lock"]
self.status_dict["GPS ALT"] = f"{location.altitude:.1f}m"
last_lock = location.last_gps_lock
self.status_dict["GPS LST"] = last_lock if last_lock else "--"

dt = self.shared_state.datetime()
8 changes: 0 additions & 8 deletions shell.nix

This file was deleted.

0 comments on commit 9edf2bb

Please sign in to comment.