Skip to content

Commit

Permalink
chat: simplify init
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Dec 8, 2023
1 parent a28f3ba commit bb64f30
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions MAVProxy/modules/mavproxy_chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ def __init__(self, mpstate):
# keep reference to mpstate
self.mpstate = mpstate

# module level variables
self.status_callcount = 0
self.print_interval = 10 # seconds
self.last_print_time = time.time()
# init mavlink message counters
self.packets_mytarget = 0
self.packets_othertarget = 0

# add menu to map and console
if mp_util.has_wxpython:
menu = MPMenuSubMenu('Chat',
items=[
MPMenuItem('Set', 'set', 'chat set'),
MPMenuItem('Show', 'show', 'show chat input window'),
MPMenuItem('Status', 'status', 'chat status'),
])
map = self.module('map')
if map is not None:
Expand All @@ -65,37 +60,22 @@ def __init__(self, mpstate):

# show help on command line options
def usage(self):
return "Usage: chat <set|show|status>"
return "Usage: chat <show>"

# control behaviour of the module
def cmd_chat(self, args):
if len(args) == 0:
print(self.usage())
elif args[0] == "set":
self.chat_settings.command(args[1:])
elif args[0] == "show":
self.show()
elif args[0] == "status":
print(self.status())
else:
print(self.usage())

# return information about chat module
def status(self):
self.status_callcount += 1
self.last_print_time = time.time() # status entertains us

# show chat input window
def show(self):
print("I will show the chat window now")
self.chat_window.show()

# print a message
def print_message(self):
if self.chat_settings.verbose:
return ("I'm very much here")
return ("running")

# handle incoming mavlink packets
def mavlink_packet(self, m):
if m.get_type() == 'GLOBAL_POSITION_INT':
Expand All @@ -106,13 +86,7 @@ def mavlink_packet(self, m):

# update function rapidly called by mavproxy
def idle_task(self):
now = time.time()
if now-self.last_print_time > self.print_interval:
self.last_print_time = now
message = self.print_message()
self.say("%s: %s" % (self.name,message))
# See if whatever we're connected to would like to play:
self.master.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_NOTICE, message)
# do nothing for now

# initialise module
def init(mpstate):
Expand Down

0 comments on commit bb64f30

Please sign in to comment.