Skip to content

Commit 8c93246

Browse files
committed
Initial commit: directly from Kristian's v3 archive
1 parent d6c1537 commit 8c93246

19 files changed

+2046
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Ignore Sound Effects
2+
soundfx/
3+
!soundfx/.gitkeep
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]
@@ -127,3 +131,4 @@ dmypy.json
127131

128132
# Pyre type checker
129133
.pyre/
134+
.DS_Store

check_address.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/home/sg1/sg1_venv/bin/python3
2+
"""
3+
This is a script to help check if your chosen address is valid for use with your stargate. (It checks if it conflicts with other already known stargates)
4+
This document shows what symbol has what number in this program: https://thestargateproject.com/symbols_overview.pdf
5+
The script is designed to run from the command line as follows:
6+
SSH into your pi and run the following command where you input your chosen address at the end as seen in this example:
7+
/home/sg1/sg1_venv/bin/python /home/sg1/sg1/check_address.py '[7, 5, 20, 27, 32, 21]'
8+
When you have found an address you want to use and want to add it to the public address book so other stargate builders can dial your gate,
9+
you need to follow the instructions here: https://thestargateproject.com/address-book/#GetYourOwnAddress
10+
"""
11+
from helper_functions import validate_string_as_stargate_address, get_fan_gates_from_db
12+
import sys
13+
from hardcoded_addresses import known_planets
14+
15+
def usable_address(input_addr):
16+
"""
17+
This functions checks the input_addr for conflicts and returns the result.
18+
:return: Different strings with information is returned.
19+
"""
20+
if len(input_addr) < 6:
21+
return f'The chosen address {input_addr} is too short. You need at least 6 symbols.'
22+
# Check the known_planets dictionary for a conflicting address
23+
for planet in known_planets:
24+
if known_planets[planet][:2] == input_addr[:2]: # if the two first symbols clash.
25+
return f'Sorry, but address {input_addr} conflicts with the known_planet; {planet} -> {known_planets[planet]}'
26+
# Check the fan_gates dictionary for a conflicting address
27+
fan_gates = get_fan_gates_from_db({})
28+
for planet in fan_gates:
29+
if fan_gates[planet][0][:2] == input_addr[:2]: # if the two first symbols clash.
30+
return f'Sorry, but address {input_addr} conflicts with the known_planet; {planet} -> {fan_gates[planet][0]}'
31+
return f'CONGRATULATIONS, there are no conflicts with your chosen address; {input_addr}'
32+
33+
if len(sys.argv) > 2:
34+
print("ERROR: Too many arguments, try encapsulating the address in quotes like this example: '[7, 5, 20, 27, 32, 21]'")
35+
36+
address = validate_string_as_stargate_address(sys.argv[1])
37+
if not address:
38+
print("ERROR: Not a valid input: Try formatting it as this example: '[7, 5, 20, 27, 32, 21]'")
39+
else:
40+
print(usable_address(address))

chevrons.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# You can change or the values in this file to match your setup. This file should not be overwritten with an automatic update
2+
# The first number in the parenthesis is the gpio led number and the second value is the motor number.
3+
from classes.CHEVRON import Chevron
4+
5+
chevrons = {1: Chevron(21, 3),
6+
2: Chevron(16, 4),
7+
3: Chevron(20, 5),
8+
4: Chevron(26, 6),
9+
5: Chevron(6, 7),
10+
6: Chevron(13, 8),
11+
7: Chevron(19, 9),
12+
8: Chevron(None, 10),
13+
9: Chevron(None, 11)}

classes/CHEVRON.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
class Chevron:
2+
"""
3+
This is the class to create and control Chevron objects.
4+
The led_gpio variable is the number for the gpio pin where the led-wire is connected as an int.
5+
The motor_number is the number for the motor as an int.
6+
"""
7+
from time import sleep
8+
def __init__(self, led_gpio, motor_number):
9+
from pathlib import Path
10+
from gpiozero import LED
11+
import simpleaudio as sound
12+
# If we provide a LED gpio number
13+
if led_gpio is not None:
14+
self.led = LED(led_gpio)
15+
else:
16+
self.led = None
17+
self.motor_number = motor_number
18+
self.root_path = Path(__file__).parent.absolute()
19+
20+
### Make ready the sound effects ###
21+
self.chev1 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_1.wav"))
22+
self.chev2 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_2.wav"))
23+
self.chev3 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_3.wav"))
24+
25+
### Make ready the sound effects for incoming wormhole ###
26+
self.chev4 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_4.wav"))
27+
self.chev5 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_5.wav"))
28+
self.chev6 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_6.wav"))
29+
self.chev7 = sound.WaveObject.from_wave_file(str(self.root_path / "../soundfx/chev_usual_7.wav"))
30+
self.possible_incoming_sounds = [self.chev4, self.chev5, self.chev6, self.chev7]
31+
32+
33+
def on(self):
34+
from adafruit_motorkit import MotorKit
35+
36+
### determine the right motor for the chevron ###
37+
if self.motor_number == 1:
38+
motor = MotorKit().motor1
39+
elif self.motor_number == 2:
40+
motor = MotorKit().motor2
41+
elif self.motor_number == 3:
42+
motor = MotorKit().motor3
43+
elif self.motor_number == 4:
44+
motor = MotorKit().motor4
45+
elif self.motor_number == 5:
46+
motor = MotorKit(address=0x61).motor1
47+
elif self.motor_number == 6:
48+
motor = MotorKit(address=0x61).motor2
49+
elif self.motor_number == 7:
50+
motor = MotorKit(address=0x61).motor3
51+
elif self.motor_number == 8:
52+
motor = MotorKit(address=0x61).motor4
53+
elif self.motor_number == 9:
54+
motor = MotorKit(address=0x62).motor1
55+
elif self.motor_number == 10:
56+
motor = MotorKit(address=0x62).motor2
57+
elif self.motor_number == 11:
58+
motor = MotorKit(address=0x62).motor3
59+
elif self.motor_number == 12:
60+
motor = MotorKit(address=0x62).motor4
61+
else:
62+
motor = None
63+
64+
### Chevron Down ###
65+
self.chev1.play() # chev down audio
66+
self.sleep(0.2)
67+
68+
motor.throttle = -0.65
69+
self.sleep(0.1) # Motor movement time
70+
motor.throttle = None
71+
72+
### Turn on the LED ###
73+
self.sleep(0.35) # wait time without motion
74+
self.chev3.play() # led on audio
75+
if self.led:
76+
self.led.on()
77+
self.sleep(0.35) # wait time without motion
78+
79+
### Chevron Up ###
80+
self.chev2.play() # chev up audio
81+
motor.throttle = 0.65
82+
self.sleep(0.2) # motor movement time
83+
motor.throttle = None
84+
85+
def incoming_on(self):
86+
from random import choice
87+
if self.led:
88+
self.led.on()
89+
choice(self.possible_incoming_sounds).play().wait_done() # random led on audio
90+
91+
def off(self, sound=None):
92+
from random import choice
93+
if sound == 'on':
94+
choice(self.possible_incoming_sounds).play() # random led on audio
95+
if self.led:
96+
self.led.off()

classes/DHD.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
class DHD:
2+
"""
3+
This is the old DHD version. Not recommended. Use the new version instead.
4+
"""
5+
def __init__(self):
6+
import adafruit_dotstar as dotstar
7+
import board
8+
self.dots = dotstar.DotStar(board.D14, board.D15, 39, brightness=0.01)
9+
self.center_dot = dotstar.DotStar(board.D14, board.D15, 1, brightness=0.15)
10+
11+
def light_on(self, symbol_number, color):
12+
"""
13+
This helper function activates the light for the dhd button of "symbol" with the "color" specified.
14+
:param symbol_number: The symbol number of which to control.
15+
:param color: The color for the led as a tuple. eg: (250, 117, 0)
16+
:return: nothing is returned.
17+
"""
18+
symbol_number_to_dhd_light_map = {0: 0, 1: 25, 2: 19, 3: 38, 4: 20, 5: 23, 6: 30, 7: 28, 8: 3, 9: 22,
19+
10: 11, 11: 36, 12: 34, 14: 17, 15: 6, 16: 9, 17: 18, 18: 16, 19: 26,
20+
20: 21, 21: 37, 22: 27, 23: 15, 24: 29, 25: 1, 26: 14, 27: 4, 28: 10, 29: 31,
21+
30: 8, 31: 5, 32: 24, 33: 12, 34: 33, 35: 7, 36: 2, 37: 35, 38: 32, 39: 13}
22+
self.dots[symbol_number_to_dhd_light_map[symbol_number]] = color
23+
def lights_off(self):
24+
"""
25+
This method turns off all dhd lights
26+
"""
27+
self.dots.fill((0, 0, 0))
28+
def center_light_on(self):
29+
"""
30+
A helper function to turn on the centre dhd light. It needs a bit more brightness than the other lights. Hence
31+
this extra method.
32+
"""
33+
self.center_dot[0] = (255, 0, 0)
34+
35+
import PyCmdMessenger
36+
from pprint import pprint
37+
class DHDv2:
38+
39+
def __init__(self, port, baud_rate):
40+
# Initialize an ArduinoBoard instance.
41+
self.board = PyCmdMessenger.ArduinoBoard(port, baud_rate=baud_rate)
42+
43+
# List of command names (and formats for their associated arguments). These must
44+
# be in the same order as in the sketch.
45+
self.commands = [
46+
["get_fw_version", "s"],
47+
["get_hw_version", "s"],
48+
["get_identifier", "s"],
49+
["reset", ""],
50+
["evt_error", "s"],
51+
["evt_ack", ""],
52+
53+
["message_bool", "?"],
54+
["message_string", "s"],
55+
["message_int", "i"],
56+
["message_long", "l"],
57+
["message_double", "d"],
58+
["message_color", "iii"],
59+
60+
["clear_all", ""], # Turns off all pixels in the RAM buffer.
61+
["clear_pixel", "i"],
62+
# Turns off the pixel at the provided index, in the RAM buffer. [ pixelIndex ]. Index starts at 0.
63+
["set_all", "iii"], # Sets all pixels to color provided, in the RAM buffer. [ red, green, blue ]
64+
["set_pixel", "iiii"],
65+
# Sets pixel to color provided, in the RAM buffer.[ pixelIndex, red, green, blue ]. Index starts at 0.
66+
67+
["get_pixel_count", "i"], # Returns the number of pixels managed by the library instance
68+
69+
["set_brightness_symbols", "i"], # Set brightness for the symbol rings' LEDs.
70+
# ** Per library documentation: "Intended to be called once, in setup(),
71+
# to limit the current/brightness of the LEDs throughout the life of the
72+
# sketch. It is not intended as an animation effect itself! The operation
73+
# of this function is “lossy” — it modifies the current pixel data in RAM,
74+
# not in the show() call — in order to meet NeoPixels’ strict timing
75+
# requirements. Certain animation effects are better served by leaving the
76+
# brightness setting at the default maximum, modulating pixel brightness
77+
# in your own sketch logic and redrawing the full strip with setPixel()."
78+
["set_brightness_center", "i"], # Set brightness for the center LED. Call this once: cautions as above.
79+
80+
["latch", ""], # Transmits the current pixel configuration in the RAM buffer out to the pixels
81+
]
82+
83+
# Initialize the messenger
84+
self.c = PyCmdMessenger.CmdMessenger(self.board, self.commands)
85+
86+
pass
87+
88+
def getFirmwareVersion(self):
89+
self.c.send("get_fw_version")
90+
return self.c.receive()[1][0]
91+
92+
def getHardwareVersion(self):
93+
self.c.send("get_hw_version")
94+
return self.c.receive()[1][0]
95+
96+
def getIdentifierString(self):
97+
self.c.send("get_identifier")
98+
return self.c.receive()[1][0]
99+
100+
def getPixelColorTuple(self, pixelIndex):
101+
self.c.send("get_pixel_color", pixelIndex)
102+
pprint(self.c.receive())
103+
return self.c.receive()[1]
104+
105+
def getPixelCount(self):
106+
self.c.send("get_pixel_count")
107+
return self.c.receive()[1][0]
108+
109+
def setBrightnessSymbols(self, brightness):
110+
self.c.send("set_brightness_symbols", brightness)
111+
return True
112+
113+
def setBrightnessCenter(self, brightness):
114+
self.c.send("set_brightness_center", brightness)
115+
return True
116+
117+
def setAllPixelsToColor(self, red, green, blue):
118+
self.c.send("set_all", red, green, blue)
119+
return True
120+
121+
def setPixel(self, pixelIndex, red, green, blue):
122+
symbol_number_to_dhd_light_map = {0: 0, 1: 34, 2: 2, 3: 21, 4: 20, 5: 36, 6: 29, 7: 31, 8: 18, 9: 37,
123+
10: 10, 11: 23, 12: 25, 14: 4, 15: 15, 16: 12, 17: 3, 18: 5, 19: 33,
124+
20: 38, 21: 22, 22: 32, 23: 6, 24: 30, 25: 1, 26: 7, 27: 17, 28: 11, 29: 28,
125+
30: 13, 31: 16, 32: 35, 33: 9, 34: 26, 35: 14, 36: 19, 37: 24, 38: 27, 39: 8}
126+
self.c.send("set_pixel", symbol_number_to_dhd_light_map[pixelIndex], red, green, blue)
127+
return True
128+
129+
def setPixel_use_LED_id(self, pixelIndex, red, green, blue):
130+
self.c.send("set_pixel", pixelIndex, red, green, blue)
131+
return True
132+
133+
def clearAllPixels(self):
134+
self.c.send("clear_all")
135+
return True
136+
137+
def clearPixel(self, pixelIndex):
138+
self.c.send("clear_pixel", pixelIndex)
139+
return True
140+
141+
def latch(self):
142+
self.c.send("latch")
143+
return True
144+
145+
class DhdKeyboardMode:
146+
"""
147+
This is just a fallback class that disables all the DHD LED functions in case the DHD is not present. You can use a regular keyboard instead.
148+
To dial Aphopis's base, just hit cFX1K98A on your keyboard.
149+
"""
150+
151+
def __init__(self):
152+
pass
153+
154+
def getFirmwareVersion(self):
155+
pass
156+
157+
def getHardwareVersion(self):
158+
pass
159+
160+
def getIdentifierString(self):
161+
pass
162+
163+
def getPixelColorTuple(self, pixelIndex):
164+
pass
165+
166+
def getPixelCount(self):
167+
pass
168+
169+
def setBrightnessSymbols(self, brightness):
170+
pass
171+
172+
def setBrightnessCenter(self, brightness):
173+
pass
174+
175+
def setAllPixelsToColor(self, red, green, blue):
176+
pass
177+
178+
def setPixel(self, pixelIndex, red, green, blue):
179+
symbol_number_to_dhd_light_map = {0: 0, 1: 34, 2: 2, 3: 21, 4: 20, 5: 36, 6: 29, 7: 31, 8: 18, 9: 37,
180+
10: 10, 11: 23, 12: 25, 14: 4, 15: 15, 16: 12, 17: 3, 18: 5, 19: 33,
181+
20: 38, 21: 22, 22: 32, 23: 6, 24: 30, 25: 1, 26: 7, 27: 17, 28: 11, 29: 28,
182+
30: 13, 31: 16, 32: 35, 33: 9, 34: 26, 35: 14, 36: 19, 37: 24, 38: 27, 39: 8}
183+
pass
184+
185+
def setPixel_use_LED_id(self, pixelIndex, red, green, blue):
186+
pass
187+
188+
def clearAllPixels(self):
189+
pass
190+
191+
def clearPixel(self, pixelIndex):
192+
pass
193+
194+
def latch(self):
195+
pass

0 commit comments

Comments
 (0)