Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/inputs/serial_g3x.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@


class serial_g3x(Input):

def __init__(self):
self.name = "g3x"
self.version = 1.0
self.inputtype = "serial"

#Setup moving averages to smooth a bit
self.readings = []
self.max_samples =10
self.readings1 = []
self.max_samples1 =20

def initInput(self,aircraft):
Input.initInput( self, aircraft ) # call parent init Input.
Expand Down Expand Up @@ -54,6 +61,9 @@ def closeInput(self,aircraft):
#############################################
## Function: readMessage
def readMessage(self, aircraft):

def mean(nums):
return float(sum(nums)) / max(len(nums), 1)
if aircraft.errorFoundNeedToExit:
return aircraft;
try:
Expand Down Expand Up @@ -118,6 +128,10 @@ def readMessage(self, aircraft):
aircraft.PALT = int(PressAlt)
aircraft.oat = int(OAT)
aircraft.aoa = int(AOA)
self.readings1.append(aircraft.aoa)
aircraft.aoa = mean(self.readings1) #Moving average to smooth a bit
if len(self.readings1) == self.max_samples1:
self.readings1.pop(0)
aircraft.mag_head = int(Heading)
aircraft.baro = (int(AltSet) + 2750.0) / 100.0
aircraft.baro_diff = aircraft.baro - 29.9213
Expand All @@ -130,9 +144,12 @@ def readMessage(self, aircraft):
aircraft.tas = _utils.ias2tas(aircraft.ias, aircraft.oat, aircraft.PALT)
aircraft.turn_rate = int(RateofTurn) * 0.1
aircraft.vert_G = int(VertAcc) * 0.1
aircraft.slip_skid = int(LatAcc) * 0.1
aircraft.slip_skid = int(LatAcc) * 0.01
self.readings.append(aircraft.slip_skid)
aircraft.slip_skid = mean(self.readings) #Moving average to smooth a bit
if len(self.readings) == self.max_samples:
self.readings.pop(0)
aircraft.msg_count += 1

if aircraft.demoMode: #if demo mode then add a delay. Else reading a file is way to fast.
time.sleep(.08)

Expand Down
35 changes: 18 additions & 17 deletions lib/screens/BrianChesteenHUD.py → lib/screens/Kivic_HUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#################################################
#Custom HUD Screen by Brian Chesteen. 01/31/2019
#Optimized for Garmin G3X Systems.
#Optimized for Garmin G3X System and Kivic HUD using Composite Video Output.
#Credit for original module template goes to Christopher Jones.
from __future__ import print_function
from _screen import Screen
Expand All @@ -13,11 +13,11 @@
import math


class BrianChesteenHUD(Screen):
class Kivic_HUD(Screen):
# called only when object is first created.
def __init__(self):
Screen.__init__(self)
self.name = "Brian Chesteen Hud Screen" # set name for this screen
self.name = "Kivic Hud Screen" # set name for this screen
self.ahrs_bg = 0
self.show_debug = False # default off
self.show_FPS = False #show screen refresh rate in frames per second for performance tuning
Expand Down Expand Up @@ -54,22 +54,23 @@ def initDisplay(self, pygamescreen, width, height):
None, int(self.height / 20)
) # font used by horz lines
self.myfont = pygame.font.SysFont(
"monospace", 22
"monospace", 22, bold = True
) # font used by debug. initialize font; must be called after 'pygame.init()' to avoid 'Font not Initialized' error
self.fontIndicator = pygame.font.SysFont("monospace", 40) # ie IAS and ALT
self.fontIndicator = pygame.font.SysFont("monospace", 40, bold = True) # ie IAS and ALT
self.fontIndicatorSmaller = pygame.font.SysFont(
"monospace", 30
"monospace", 30, bold = True
) # ie. baro and VSI
self.fontsmallest = pygame.font.SysFont(
"monospace", 16
"monospace", 16, bold = True
) # units

#set up the HSI
_hsi.hsi_init(
self,
350, #HSI size
20, #Gnd Trk Tick size
(255,0,0) # HSI color
(255, 0, 0), # HSI rose color
(255, 255, 255) #HSI label color
)

# called every redraw for the screen
Expand Down Expand Up @@ -183,7 +184,7 @@ def draw(self, aircraft, FPS):
self.MainColor,
1,
)

# ALT
hud_graphics.hud_draw_box_text(
self.pygamescreen,
Expand Down Expand Up @@ -259,17 +260,17 @@ def draw(self, aircraft, FPS):
label = self.myfont.render(
"TRK %d\xb0" % (aircraft.gndtrack), 1, (255, 255, 0)
)
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 180))
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 185))
elif aircraft.gndtrack < 100:
label = self.myfont.render(
"TRK %d\xb0" % (aircraft.gndtrack), 1, (255, 255, 0)
)
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 180))
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 185))
else:
label = self.myfont.render(
"TRK %d\xb0" % (aircraft.gndtrack), 1, (255, 255, 0)
)
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 180))
self.pygamescreen.blit(label, (self.width / 2 - 45, (self.heightCenter) - 185))
# OAT
label = self.myfont.render(
"OAT %d\xb0c %d\xb0f" % (aircraft.oat, ((aircraft.oat * 9.0/5.0) + 32.0)), 1, (255, 255, 0)
Expand Down Expand Up @@ -303,7 +304,7 @@ def draw(self, aircraft, FPS):
pygame.draw.circle(
self.pygamescreen,
(255, 255, 255),
(self.width/2 - int(aircraft.slip_skid * 15), self.heightCenter + 170 ),
(self.width/2 - int(aircraft.slip_skid * 150), self.heightCenter + 170 ),
10,
0,
)
Expand Down Expand Up @@ -376,7 +377,7 @@ def draw(self, aircraft, FPS):
" %d\xb0" % (aircraft.mag_head),
(255, 255, 0),
(self.width / 2) - 40,
25,
(self.heightCenter) - 220,
95,
35,
self.MainColor,
Expand All @@ -389,7 +390,7 @@ def draw(self, aircraft, FPS):
" %d\xb0" % (aircraft.mag_head),
(255, 255, 0),
(self.width / 2) - 40,
25,
(self.heightCenter) - 220,
95,
35,
self.MainColor,
Expand All @@ -402,7 +403,7 @@ def draw(self, aircraft, FPS):
"%d\xb0" % (aircraft.mag_head),
(255, 255, 0),
(self.width / 2) - 40,
25,
(self.heightCenter) - 220,
95,
35,
self.MainColor,
Expand All @@ -412,7 +413,7 @@ def draw(self, aircraft, FPS):
label = self.fontsmallest.render(
"M", 1, (255, 255, 255)
)
self.pygamescreen.blit(label, (self.width / 2 + 39, (self.heightCenter) - 195))
self.pygamescreen.blit(label, (self.width / 2 + 39, (self.heightCenter) - 200))

if aircraft.norm_wind_dir != None:
arrow_rotated = pygame.transform.rotate(self.arrow_scaled, aircraft.norm_wind_dir)
Expand Down
79 changes: 49 additions & 30 deletions lib/screens/_hsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,23 @@
import pygame
import math

def hsi_init(self, hsi_size, gnd_trk_tick_size, color):
def hsi_init(self, hsi_size, gnd_trk_tick_size, rose_color, label_color):
self.myfont1 = pygame.font.SysFont(
"Comic Sans MS", 30
"Comic Sans MS", 30, bold = True
) # hsi

# HSI Setup
self.hsi_size = hsi_size
self.gnd_trk_tick_size = gnd_trk_tick_size
self.color = color
self.color = rose_color
self.label_color = label_color
self.rose = pygame.Surface((self.hsi_size, self.hsi_size), pygame.SRCALPHA)
self.labels = pygame.Surface((self.hsi_size, self.hsi_size), pygame.SRCALPHA)
self.ticks = pygame.Surface((self.hsi_size, self.hsi_size), pygame.SRCALPHA)

global old_hsi_hdg
old_hsi_hdg = None

# Setup Compass Rose
# Major Tick Marks
for big_tick in range(36):
cos = math.cos(math.radians(360.0 / 36 * big_tick))
sin = math.sin(math.radians(360.0 / 36 * big_tick))
x0 = roint(self.hsi_size / 2 + self.hsi_size / 15 * cos * 4)
y0 = roint(self.hsi_size / 2 + self.hsi_size / 15 * sin * 4)
x1 = roint(self.hsi_size / 2 + self.hsi_size / 2.8 * cos)
y1 = roint(self.hsi_size / 2 + self.hsi_size / 2.8 * sin)
pygame.draw.line(self.rose, self.color, [x0, y0], [x1, y1], 3)

# Setup Compass Rose
# Minor Tick Marks
for little_tick in range(72):
Expand All @@ -43,32 +33,43 @@ def hsi_init(self, hsi_size, gnd_trk_tick_size, color):
y0 = roint(self.hsi_size / 2 + self.hsi_size / 13 * sin * 4)
x1 = roint(self.hsi_size / 2 + self.hsi_size / 3 * cos)
y1 = roint(self.hsi_size / 2 + self.hsi_size / 3 * sin)
pygame.draw.line(self.rose, self.color, [x0, y0], [x1, y1], 2)
pygame.draw.line(self.rose, self.color, [x0, y0], [x1, y1], 4)

# Setup Compass Rose
# Major Tick Marks
for big_tick in range(36):
cos = math.cos(math.radians(360.0 / 36 * big_tick))
sin = math.sin(math.radians(360.0 / 36 * big_tick))
x0 = roint(self.hsi_size / 2 + self.hsi_size / 15 * cos * 4)
y0 = roint(self.hsi_size / 2 + self.hsi_size / 15 * sin * 4)
x1 = roint(self.hsi_size / 2 + self.hsi_size / 2.8 * cos)
y1 = roint(self.hsi_size / 2 + self.hsi_size / 2.8 * sin)
pygame.draw.line(self.rose, self.color, [x0, y0], [x1, y1], 4)

# Setup Labels
self.N = self.myfont1.render("N", False, (self.color))
self.N = self.myfont1.render("N", False, (self.label_color))
self.N_rect = self.N.get_rect()
self.R3 = self.myfont1.render("3", False, (self.color))
self.R3 = self.myfont1.render("3", False, (self.label_color))
self.R3_rect = self.R3.get_rect()
self.R6 = self.myfont1.render("6", False, (self.color))
self.R6 = self.myfont1.render("6", False, (self.label_color))
self.R6_rect = self.R6.get_rect()
self.E = self.myfont1.render("E", False, (self.color))
self.E = self.myfont1.render("E", False, (self.label_color))
self.E_rect = self.E.get_rect()
self.R12 = self.myfont1.render("12", False, (self.color))
self.R12 = self.myfont1.render("12", False, (self.label_color))
self.R12_rect = self.R12.get_rect()
self.R15 = self.myfont1.render("15", False, (self.color))
self.R15 = self.myfont1.render("15", False, (self.label_color))
self.R15_rect = self.R15.get_rect()
self.S = self.myfont1.render("S", False, (self.color))
self.S = self.myfont1.render("S", False, (self.label_color))
self.S_rect = self.S.get_rect()
self.R21 = self.myfont1.render("21", False, (self.color))
self.R21 = self.myfont1.render("21", False, (self.label_color))
self.R21_rect = self.R21.get_rect()
self.R24 = self.myfont1.render("24", False, (self.color))
self.R24 = self.myfont1.render("24", False, (self.label_color))
self.R24_rect = self.R24.get_rect()
self.W = self.myfont1.render("W", False, (self.color))
self.W = self.myfont1.render("W", False, (self.label_color))
self.W_rect = self.W.get_rect()
self.R30 = self.myfont1.render("30", False, (self.color))
self.R30 = self.myfont1.render("30", False, (self.label_color))
self.R30_rect = self.R30.get_rect()
self.R33 = self.myfont1.render("33", False, (self.color))
self.R33 = self.myfont1.render("33", False, (self.label_color))
self.R33_rect = self.R33.get_rect()

# Setup Ground Track Tick
Expand Down Expand Up @@ -132,9 +133,27 @@ def gnd_trk_tick(self, gnd_trk):

def turn_rate_disp(self, turn_rate):
if abs(turn_rate) > 0.2:
pygame.draw.line(self.pygamescreen, (255, 0, 255), (self.width / 2, 85), (self.width / 2 + (turn_rate * 10), 85), 10)
pygame.draw.line(self.pygamescreen, (255, 255, 255), (self.width / 2 + 31, 80), (self.width / 2 + 31, 90), 2)
pygame.draw.line(self.pygamescreen, (255, 255, 255), (self.width / 2 - 31, 80), (self.width / 2 - 31, 90), 2)
pygame.draw.line(self.pygamescreen, (255, 0, 255),
(self.width / 2, self.height / 2 - 158), (self.width / 2 +
(turn_rate * 10), self.height / 2 - 158), 10)
pygame.draw.line(self.pygamescreen, (255, 255, 255),
(self.width / 2 + 31, self.height / 2 - 153),
(self.width / 2 + 31, self.height / 2 - 163), 3)
pygame.draw.line(self.pygamescreen, (255, 255, 255),
(self.width / 2 - 31, self.height / 2 - 153),
(self.width / 2 - 31, self.height / 2 - 163), 3)
pygame.draw.line(self.pygamescreen, (0, 0, 0),
( self.width/2 + 33, self.height / 2 - 153),
( self.width/2 + 33, self.height / 2 - 163), 1)
pygame.draw.line(self.pygamescreen, (0, 0, 0),
( self.width/2 + 29, self.height / 2 - 153),
( self.width/2 + 29, self.height / 2 - 163), 1)
pygame.draw.line(self.pygamescreen, (0, 0, 0),
( self.width/2 - 33, self.height / 2 - 153),
( self.width/2 - 33, self.height / 2 - 163), 1)
pygame.draw.line(self.pygamescreen, (0, 0, 0),
( self.width/2 - 29, self.height / 2 - 153),
( self.width/2 - 29, self.height / 2 - 163), 1)

def hsi_main(self, hsi_hdg, gnd_trk, turn_rate):
hsi_hdg = (hsi_hdg + 90) % 360
Expand Down