@pi-topMIKE @Luis @Supernovali I FINALLY DONE IT!!!
got GPS info running in the system menu sooooooo much starting and stopping pt-sys-oled.service and soooooooo much looking at the code wondering what I got wrong and why the service restarts itself when selecting the GPS page. BUT i finally got it working and it does update every second which is nice
The only information that is being displayed is from RMC NMEA sentence, Lat Lon and speed
1 thing with it is that it takes a second or 2 to change to the GPS, but only happens once, i dont know why, it just does, but going back to it after its perfectly fine
https://www.youtube.com/watch?v=YxkZOCtfCP8
WHAT I DONE
I started modifying a copy of the WiFi Widget then scrapped it gave me the information to write my code
Step 0: Edit Menu.py to add an extra menu item
- Line 6 : add gps under ethernet
- Line 93 : copy the CPU MenyPage item
- paste into line 103
- change cpu to gps in the newly pasted MenuPage
- Create a python file in sys_info folder called gps.py
Step 1: config my GPS unit to ONLY show RMC NMEA data
uart.write(b'$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*35\r\n')
Step 2: Config my GPS unit to a 1hz refresh
uart.write(b'$PMTK220,1000*1F\r\n')
Step 3: Install pynmea2 as sudo
Step 4: Get some sort of NMEA displaying on the screen as in my previous post
Step 5: get pynmea formatting
Step 6: get Lat, Lon, Speed displayed in the correct display format
Step 7: import common values to position the text
THE CODE
And here is the code i wrote to make all this happen ( no fancy icons or that just text) enjoy the mess
import serial, io, pynmea2
from components.widgets.common.functions import draw_text
from components.widgets.common.base_widgets import BaseSnapshot
from components.widgets.common.values import (
default_margin_x,
common_first_line_y,
common_second_line_y,
common_third_line_y,
)
class Hotspot(BaseSnapshot):
def __init__(self, width, height, mode, interval, **data):
super(Hotspot, self).__init__(width, height, interval, self.render)
self.uart = serial.Serial('/dev/ttyS0', 9600, timeout=5.0)
self.uart_read = io.TextIOWrapper(io.BufferedRWPair(self.uart, self.uart))
self.interval = 1
self.nmea_dict = {
'latitude' : "",
'longitude' : "",
'speed' : ""}
def render(self, draw, width, height):
line = self.uart_read.readline()
msg = pynmea2.parse(line)
if msg.sentence_type == 'RMC':
pole = 'N' if float(msg.latitude) > 0 else 'S'
lat = f"***{pole} %02dm %04.2fs" % (msg.latitude_minutes, msg.latitude_seconds)
draw_text(draw, xy=(default_margin_x,common_first_line_y), text=str(lat))
pole = 'E' if float(msg.longitude) > 0 else 'W'
lon = str(abs(int('%02d' % (msg.longitude)))).zfill(3)
lon = f"***{pole} %02dm %04.2fs" % (msg.longitude_minutes, msg.longitude_seconds)
draw_text(draw, xy=(default_margin_x,common_second_line_y), text=str(lon))
speed = f'{round((float(msg.spd_over_grnd) * 1.150779448),1)} MPH'
draw_text(draw, xy=(default_margin_x,common_third_line_y), text=str(speed))
BASE STARTING POINT
this is all i took from the WiFi widget to start my code
from components.widgets.common.functions import draw_text
from components.widgets.common.base_widgets import BaseSnapshot
from components.widgets.common.values import (
default_margin_x,
common_first_line_y,
common_second_line_y,
common_third_line_y,
)
class Hotspot(BaseSnapshot):
def __init__(self, width, height, mode, interval, **data):
super(Hotspot, self).__init__(width, height, interval, self.render)
def render(self, draw, width, height):
draw_text(draw, xy=(default_margin_x,common_first_line_y), text='Hello pi-top[4]')
Conclusion
I look forward to an easier way to add to the system menu, any 3rd party modules, install them wiht sudo pip3, whats next with the system menu for me? NOTHING, was really frustating to code, any little error will cause the menu to fail starting (no reboot required, just disable service, stop it enable it and start it). VSCode cannot be started via sudo so saving every time requires typing in password.
Its done, a proof of concept that works