Skip to content

Commit 0c45816

Browse files
committed
Implement more in main
1 parent 8f97a06 commit 0c45816

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

main.py

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from lib.pysquared.nvm.flag import Flag
3131
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager
3232
from lib.pysquared.sleep_helper import SleepHelper
33+
from lib.pysquared.watchdog import Watchdog
34+
from lib.pysquared.hardware.magnetometer.manager.lis2mdl import LIS2MDLManager
35+
from lib.pysquared.hardware.imu.manager.lsm6dsox import LSM6DSOXManager
36+
from lib.pysquared.hardware.busio import initialize_i2c_bus, initialize_spi_bus
3337
from version import __version__
3438

3539
rtc = MicrocontrollerManager()
@@ -48,31 +52,61 @@
4852
logger.info(f"Code Starting in {loiter_time-i} seconds")
4953
time.sleep(1)
5054

55+
watchdog = Watchdog(logger, board.WDT_WDI)
56+
watchdog.pet()
57+
5158
logger.debug("Initializing Config")
5259
config: Config = Config("config.json")
5360

54-
c = Satellite(logger, config)
55-
c.watchdog_pet()
56-
sleep_helper = SleepHelper(c, logger)
61+
spi0 = initialize_spi_bus(
62+
logger,
63+
board.SPI0_SCK,
64+
board.SPI0_MOSI,
65+
board.SPI0_MISO,
66+
)
5767

5868
radio_manager = RFM9xManager(
5969
logger,
6070
config.radio,
6171
Flag(index=register.FLAG, bit_index=7, datastore=microcontroller.nvm),
6272
config.is_licensed,
63-
c.spi0,
73+
spi0,
6474
initialize_pin(logger, board.SPI0_CS0, digitalio.Direction.OUTPUT, True),
6575
initialize_pin(logger, board.RF1_RST, digitalio.Direction.OUTPUT, True),
6676
)
6777

68-
f = functions.functions(c, logger, config, sleep_helper, radio_manager)
78+
i2c1 = initialize_i2c_bus(
79+
logger,
80+
board.I2C1_SCL,
81+
board.I2C1_SDA,
82+
100000,
83+
)
84+
85+
magnetometer = LIS2MDLManager(logger, i2c1)
86+
87+
imu = LSM6DSOXManager(logger, i2c1, 0x6B)
88+
89+
c = Satellite(logger, config)
90+
91+
sleep_helper = SleepHelper(c, logger)
92+
93+
f = functions.functions(
94+
c,
95+
logger,
96+
config,
97+
sleep_helper,
98+
radio_manager,
99+
magnetometer,
100+
imu,
101+
watchdog,
102+
)
69103

70104
def initial_boot():
71-
c.watchdog_pet()
105+
watchdog.pet()
72106
f.beacon()
73-
c.watchdog_pet()
107+
watchdog.pet()
74108
f.listen()
75-
c.watchdog_pet()
109+
watchdog.pet()
76110

77111
try:
78112
c.boot_count.increment()
@@ -94,10 +128,10 @@ def initial_boot():
94128
def send_imu_data():
95129
logger.info("Looking to get imu data...")
96130
IMUData = []
97-
c.watchdog_pet()
131+
watchdog.pet()
98132
logger.info("IMU has baton")
99133
IMUData = f.get_imu_data()
100-
c.watchdog_pet()
134+
watchdog.pet()
101135
f.send(IMUData)
102136

103137
def main():
@@ -110,7 +144,7 @@ def main():
110144
f.listen_loiter()
111145

112146
f.all_face_data()
113-
c.watchdog_pet()
147+
watchdog.pet()
114148
f.send_face()
115149

116150
f.listen_loiter()
@@ -125,13 +159,13 @@ def main():
125159

126160
def critical_power_operations():
127161
initial_boot()
128-
c.watchdog_pet()
162+
watchdog.pet()
129163

130164
sleep_helper.long_hibernate()
131165

132166
def minimum_power_operations():
133167
initial_boot()
134-
c.watchdog_pet()
168+
watchdog.pet()
135169

136170
sleep_helper.short_hibernate()
137171

0 commit comments

Comments
 (0)