Browse Source

expand on commentary & docstrings

Brennen Bearnes 10 months ago
parent
commit
2333a91e4c
2 changed files with 29 additions and 5 deletions
  1. 8
    0
      code.py
  2. 21
    5
      glitterpos.py

+ 8
- 0
code.py View File

@@ -1,3 +1,11 @@
1
+"""
2
+Main program loop for Glitter Positioning System.
3
+
4
+https://github.com/adafruit/glitterpos
5
+
6
+* Author(s): Brennen Bearnes, Limor Fried
7
+"""
8
+
1 9
 from glitterpos import GlitterPOS
2 10
 gp = GlitterPOS()
3 11
 while True:

+ 21
- 5
glitterpos.py View File

@@ -24,7 +24,7 @@ from glitterpos_util import timestamp, compass_bearing, bearing_to_pixel, map_ra
24 24
 # MAG_MIN and MAG_MAX.
25 25
 from glitterpos_cfg import MY_ID, MAG_MIN, MAG_MAX, DECLINATION_RAD
26 26
 
27
-# Colors for status lights, etc.
27
+# Colors for status lights, NeoPixel ring, etc.:
28 28
 RED = (255, 0, 0)
29 29
 YELLOW = (255, 150, 0)
30 30
 GREEN = (0, 255, 0)
@@ -34,6 +34,7 @@ PURPLE = (180, 0, 255)
34 34
 
35 35
 # BOULDER_ID = 23
36 36
 
37
+# Color presets for each glitterpos_id:
37 38
 COLOR_LOOKUP = {
38 39
     0: GREEN,
39 40
     1: BLUE,
@@ -46,6 +47,7 @@ COLOR_LOOKUP = {
46 47
     # BOULDER_ID: RED
47 48
 }
48 49
 
50
+# You can add fixed points here:
49 51
 DEFAULT_BOX_COORDS = {
50 52
     # BOULDER_ID: (40.018258, -105.278457)
51 53
 }
@@ -91,6 +93,7 @@ class GlitterPOS:
91 93
         self.statuslight.fill(YELLOW)
92 94
 
93 95
     def startup_animation(self):
96
+        """Initialize NeoPixel test pattern."""
94 97
         self.pixels[bearing_to_pixel(0)] = PURPLE
95 98
         self.pixels.show()
96 99
         time.sleep(.5)
@@ -107,12 +110,12 @@ class GlitterPOS:
107 110
         """Set up RFM95."""
108 111
         spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
109 112
         self.rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
110
-        self.rfm9x.tx_power = 18 # Default is 13 dB, but the RFM95 can go up to 23 dB
113
+        self.rfm9x.tx_power = 18 # Default is 13 dB; the RFM95 goes up to 23 dB
111 114
         self.radio_tx('d', 'hello world')
112 115
         time.sleep(1)
113 116
 
114 117
     def init_gps(self):
115
-        """Some GPS module setup."""
118
+        """Set up GPS module."""
116 119
         uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=3000)
117 120
         gps = adafruit_gps.GPS(uart)
118 121
         time.sleep(1)
@@ -126,12 +129,22 @@ class GlitterPOS:
126 129
         self.gps = gps
127 130
 
128 131
     def init_compass(self):
132
+        """Set up LSM9DS1."""
129 133
         i2c = busio.I2C(board.SCL, board.SDA)
130 134
         self.compass = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
131 135
         time.sleep(1)
132 136
 
133 137
     def advance_frame(self):
134
-        """Essentially our main program loop."""
138
+        """
139
+        Check the radio for new packets, poll GPS and compass data, send a
140
+        radio packet if coordinates have changed (or if it's been a while), and
141
+        update NeoPixel display.  Called in an infinite loop by code.py.
142
+
143
+        To inspect the state of the system, initialize a new GlitterPOS object
144
+        from the CircuitPython REPL, and call gp.advance_frame() manually.  You
145
+        can then access the instance variables defined in __init__() and
146
+        init_()* methods.
147
+        """
135 148
 
136 149
         current = time.monotonic()
137 150
         self.radio_rx(timeout=0.5)
@@ -144,7 +157,8 @@ class GlitterPOS:
144 157
             self.statuslight.fill(RED)
145 158
             return
146 159
 
147
-        # We want to send coordinates out either on new GPS data or roughly every 15 seconds.
160
+        # We want to send coordinates out either on new GPS data or roughly
161
+        # every 15 seconds:
148 162
         if (not new_gps_data) and (current - self.last_send < 15):
149 163
             return
150 164
 
@@ -238,6 +252,8 @@ class GlitterPOS:
238 252
         """Display current state on the NeoPixel ring."""
239 253
         self.pixels.fill((0, 0, 0))
240 254
 
255
+        # We can't meaningfully point at other locations if we don't know our
256
+        # own position:
241 257
         if not self.gps.has_fix:
242 258
             return
243 259
 

Loading…
Cancel
Save