Skip to content

Commit

Permalink
Backed Up to Fix Merge Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikefly123 committed Jul 26, 2024
1 parent 714c552 commit 14113e0
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions CircuitPy/FC_Board/lib/pysquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
* Author(s): Nicole Maggard, Michael Pham, and Rachel Sarmiento
"""


# Common CircuitPython Libs
import gc
import board, microcontroller
import busio, time, sys, traceback
from storage import mount, umount, VfsFat
from storage import mount, umount, VfsFat
import digitalio, sdcardio, pwmio
from os import listdir, stat, statvfs, mkdir, chdir
from bitflags import bitFlag, multiBitFlag, multiByte
Expand All @@ -31,19 +29,11 @@
# NVM register numbers
_BOOTCNT = const(0)
_VBUSRST = const(6)
_BOOTCNT = const(0)
_VBUSRST = const(6)
_STATECNT = const(7)
_TOUTS = const(9)
_ICHRG = const(11)
_DIST = const(13)
_FLAG = const(16)
_TOUTS = const(9)
_ICHRG = const(11)
_DIST = const(13)
_FLAG = const(16)

SEND_BUFF = bytearray(252)

SEND_BUFF = bytearray(252)

Expand All @@ -59,11 +49,6 @@ class Satellite:
c_state_err = multiBitFlag(register=_STATECNT, lowest_bit=0, num_bits=8)
c_distance = multiBitFlag(register=_DIST, lowest_bit=0, num_bits=8)
c_ichrg = multiBitFlag(register=_ICHRG, lowest_bit=0, num_bits=8)
c_boot = multiBitFlag(register=_BOOTCNT, lowest_bit=0, num_bits=8)
c_vbusrst = multiBitFlag(register=_VBUSRST, lowest_bit=0, num_bits=8)
c_state_err = multiBitFlag(register=_STATECNT, lowest_bit=0, num_bits=8)
c_distance = multiBitFlag(register=_DIST, lowest_bit=0, num_bits=8)
c_ichrg = multiBitFlag(register=_ICHRG, lowest_bit=0, num_bits=8)

# Define NVM flags
f_softboot = bitFlag(register=_FLAG, bit=0)
Expand All @@ -74,14 +59,6 @@ class Satellite:
f_shtdwn = bitFlag(register=_FLAG, bit=5)
f_burned = bitFlag(register=_FLAG, bit=6)
f_fsk = bitFlag(register=_FLAG, bit=7)
f_softboot = bitFlag(register=_FLAG, bit=0)
f_solar = bitFlag(register=_FLAG, bit=1)
f_burnarm = bitFlag(register=_FLAG, bit=2)
f_brownout = bitFlag(register=_FLAG, bit=3)
f_triedburn = bitFlag(register=_FLAG, bit=4)
f_shtdwn = bitFlag(register=_FLAG, bit=5)
f_burned = bitFlag(register=_FLAG, bit=6)
f_fsk = bitFlag(register=_FLAG, bit=7)

def debug_print(self, statement):
if self.debug:
Expand Down Expand Up @@ -140,14 +117,6 @@ def __init__(self):
"cr": 8,
"pwr": 23,
"st": 80000,
"id": 0xFB,
"gs": 0xFA,
"freq": 437.4,
"sf": 8,
"bw": 125,
"cr": 8,
"pwr": 23,
"st": 80000,
}
self.hardware = {
"I2C0": False,
Expand All @@ -174,17 +143,13 @@ def __init__(self):
"""
if self.c_boot > 200:
self.c_boot = 0
self.c_boot = 0

if self.f_fsk:
self.debug_print("Fsk going to false")
self.f_fsk = False

self.f_fsk = False

if self.f_softboot:
self.f_softboot = False
self.f_softboot = False

"""
Intializing Communication Buses
Expand Down Expand Up @@ -310,10 +275,8 @@ def __init__(self):
_vfs = VfsFat(_sd)
mount(_vfs, "/sd")
self.fs = _vfs
self.fs = _vfs
sys.path.append("/sd")
self.hardware["SDcard"] = True
self.hardware["SDcard"] = True
except Exception as e:
self.error_print(
"[ERROR][SD Card]" + "".join(traceback.format_exception(e))
Expand Down Expand Up @@ -465,8 +428,6 @@ def reset_vbus(self):
try:
self._resetReg.drive_mode = digitalio.DriveMode.PUSH_PULL
self._resetReg.value = 1
self._resetReg.drive_mode = digitalio.DriveMode.PUSH_PULL
self._resetReg.value = 1
except Exception as e:
self.error_print(
"vbus reset error: " + "".join(traceback.format_exception(e))
Expand Down Expand Up @@ -500,17 +461,13 @@ def mag(self):
except Exception as e:
self.error_print("[ERROR][mag]" + "".join(traceback.format_exception(e)))

def log(self, filedir, msg):
if self.hardware["SDcard"]:
def log(self, filedir, msg):
if self.hardware["SDcard"]:
try:
self.debug_print(f"writing {msg} to {filedir}")
with open(filedir, "a+") as f:
t = int(time.monotonic())
f.write("{}, {}\n".format(t, msg))
t = int(time.monotonic())
f.write("{}, {}\n".format(t, msg))
except Exception as e:
self.error_print(
"SD CARD error: " + "".join(traceback.format_exception(e))
Expand All @@ -524,19 +481,15 @@ def check_reboot(self):
if self.UPTIME > 86400:
self.micro.reset()

def print_file(self, filedir=None, binary=False):
def print_file(self, filedir=None, binary=False):
try:
if filedir == None:
if filedir == None:
raise Exception("file directory is empty")
self.debug_print(f"--- Printing File: {filedir} ---")
self.debug_print(f"--- Printing File: {filedir} ---")
if binary:
with open(filedir, "rb") as file:
self.debug_print(file.read())
self.debug_print("")
self.debug_print("")
else:
with open(filedir, "r") as file:
for line in file:
Expand All @@ -548,16 +501,13 @@ def print_file(self, filedir=None, binary=False):

def read_file(self, filedir=None, binary=False):
try:
if filedir == None:
if filedir == None:
raise Exception("file directory is empty")
self.debug_print(f"--- reading File: {filedir} ---")
self.debug_print(f"--- reading File: {filedir} ---")
if binary:
with open(filedir, "rb") as file:
self.debug_print(file.read())
self.debug_print("")
self.debug_print("")
return file.read()
else:
with open(filedir, "r") as file:
Expand All @@ -569,58 +519,43 @@ def read_file(self, filedir=None, binary=False):
"[ERROR] Cant print file: " + "".join(traceback.format_exception(e))
)

def powermode(self, mode):
def powermode(self, mode):
"""
Configure the hardware for minimum or normal power consumption
Add custom modes for mission-specific control
"""
try:
if "crit" in mode:
self.neopixel.brightness = 0
if "crit" in mode:
self.neopixel.brightness = 0
self.enable_rf.value = False
self.power_mode = "critical"
self.power_mode = "critical"

elif "min" in mode:
self.neopixel.brightness = 0
elif "min" in mode:
self.neopixel.brightness = 0
self.enable_rf.value = False

self.power_mode = "minimum"
self.power_mode = "minimum"

elif "norm" in mode:
elif "norm" in mode:
self.enable_rf.value = True
self.power_mode = "normal"
self.power_mode = "normal"
# don't forget to reconfigure radios, gps, etc...

elif "max" in mode:
elif "max" in mode:
self.enable_rf.value = True
self.power_mode = "maximum"
self.power_mode = "maximum"
except Exception as e:
self.error_print(
"Error in changing operations of powermode: "
+ "".join(traceback.format_exception(e))
)

def new_file(self, substring, binary=False):
"""
def new_file(self, substring, binary=False):
"""
substring something like '/data/DATA_'
directory is created on the SD!
int padded with zeros will be appended to the last found file
"""
if self.hardware["SDcard"]:
"""
if self.hardware["SDcard"]:
try:
ff = ""
Expand All @@ -632,17 +567,6 @@ def new_file(self, substring, binary=False):
_folder, _file
)
)
try:
chdir("/sd" + _folder)
ff = ""
n = 0
_folder = substring[: substring.rfind("/") + 1]
_file = substring[substring.rfind("/") + 1 :]
self.debug_print(
"Creating new file in directory: /sd{} with file prefix: {}".format(
_folder, _file
)
)
try:
chdir("/sd" + _folder)
except OSError:
Expand All @@ -658,7 +582,6 @@ def new_file(self, substring, binary=False):
)
return None
for i in range(0xFFFF):
ff = "/sd{}{}{:05}.txt".format(_folder, _file, (n + i) % 0xFFFF)
ff = "/sd{}{}{:05}.txt".format(_folder, _file, (n + i) % 0xFFFF)
try:
if n is not None:
Expand All @@ -670,20 +593,13 @@ def new_file(self, substring, binary=False):
# print('file number is',n)
break
self.debug_print("creating file..." + str(ff))
if binary:
b = "ab"
else:
b = "a"
with open(ff, b) as f:
self.debug_print("creating file..." + str(ff))
if binary:
b = "ab"
else:
b = "a"
with open(ff, b) as f:
f.tell()
chdir("/")
chdir("/")
return ff
except Exception as e:
self.error_print(
Expand All @@ -692,7 +608,6 @@ def new_file(self, substring, binary=False):
return None
else:
self.debug_print("[WARNING] SD Card not initialized")
self.debug_print("[WARNING] SD Card not initialized")


print("Initializing CubeSat")
Expand Down

0 comments on commit 14113e0

Please sign in to comment.