2022-03-09 16:51:21 +08:00
|
|
|
import _thread
|
|
|
|
|
|
|
|
from queue import Queue
|
|
|
|
from machine import Timer
|
|
|
|
from usr.logging import getLogger
|
|
|
|
|
|
|
|
import usr.settings as settings
|
2022-03-03 09:53:51 +08:00
|
|
|
|
2022-03-08 17:12:38 +08:00
|
|
|
# from usr.led import LED
|
2022-03-09 16:51:21 +08:00
|
|
|
# from usr.sensor import Sensor
|
|
|
|
from usr.remote import Remote
|
|
|
|
from usr.location import Location
|
2022-03-08 17:12:38 +08:00
|
|
|
from usr.alert import AlertMonitor
|
2022-03-09 16:51:21 +08:00
|
|
|
from usr.common import Singleton
|
2022-03-03 09:53:51 +08:00
|
|
|
|
2022-03-09 16:51:21 +08:00
|
|
|
log = getLogger(__name__)
|
2022-03-04 13:21:48 +08:00
|
|
|
|
2022-03-09 16:51:21 +08:00
|
|
|
|
|
|
|
def tracker_worker(args):
|
|
|
|
self = args
|
|
|
|
while True:
|
|
|
|
data = self.tracker_command_queue.get()
|
|
|
|
if data == 'loc_mode':
|
|
|
|
self.loc_timer_init()
|
|
|
|
|
|
|
|
|
|
|
|
class Tracker(Singleton):
|
|
|
|
def __init__(self, remote_read_cb, loc_read_cb, alert_read_cb, **kw):
|
2022-03-08 17:12:38 +08:00
|
|
|
# self.led = LED()
|
2022-03-09 16:51:21 +08:00
|
|
|
# self.sensor = Sensor()
|
|
|
|
self.remote = Remote(remote_read_cb)
|
|
|
|
self.locator = Location(loc_read_cb)
|
2022-03-08 17:12:38 +08:00
|
|
|
self.alert = AlertMonitor(alert_read_cb)
|
2022-03-09 16:51:21 +08:00
|
|
|
|
|
|
|
self.loc_timer = Timer(Timer.Timer0)
|
|
|
|
self.tracker_command_queue = Queue(maxsize=64)
|
|
|
|
_thread.start_new_thread(tracker_worker, (self,))
|
|
|
|
|
|
|
|
self.loc_timer_init()
|
|
|
|
|
|
|
|
def loc_timer_cb(self, args):
|
|
|
|
self.locator.trigger()
|
|
|
|
|
|
|
|
def loc_timer_init(self):
|
|
|
|
current_settings = settings.settings.get()
|
|
|
|
if (current_settings['app']['loc_mode'] & settings.default_values_app._loc_mode.cycle) \
|
|
|
|
and current_settings['app']['loc_cycle_period']:
|
|
|
|
log.debug('[.] loc_timer to restart.')
|
|
|
|
self.loc_timer.stop()
|
|
|
|
log.debug('[.] loc_timer stop.')
|
|
|
|
self.loc_timer.start(period=current_settings['app']['loc_cycle_period'] * 1000, mode=self.loc_timer.PERIODIC, callback=self.loc_timer_cb)
|
|
|
|
log.debug('[.] loc_timer start.')
|
|
|
|
else:
|
|
|
|
self.loc_timer.stop()
|
|
|
|
log.debug('[.] loc_timer stop forever.')
|