Skip to content

Commit

Permalink
Adding in randomization of firing fin funnels for nu gundam
Browse files Browse the repository at this point in the history
  • Loading branch information
frozenwizard committed Jun 10, 2023
1 parent a55645b commit a7a8c0f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[MASTER]
disable=
C0114, W0719, C0103, W0718
C0114, W0719, C0103, W0718, R0801

[FORMAT]
max-line-length=140
5 changes: 5 additions & 0 deletions src/config/nu_gundam.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"name": "Fire Fin Funnels",
"path": "fire_funnels",
"method": "fire_funnels"
},
{
"name": "Random",
"path": "random",
"method": "random_funnels"
}
]
}
7 changes: 4 additions & 3 deletions src/gunpla/BaseGundam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

from machine import Pin

from src.pi.LED import LED
from src.pi.board_led import BoardLED
from src.phew.server import logging
Expand All @@ -11,6 +9,9 @@


class BaseGundam:
"""
Base Gunpla.
"""
board_led = BoardLED()

def __init__(self):
Expand All @@ -22,7 +23,7 @@ def get_config_file(self) -> str:
Returns the path to the corresesponding Gundam json file
This is abstract
"""
pass
raise Exception("Not implemented")

def add_routes(self, webserver: server) -> None:
"""
Expand Down
24 changes: 24 additions & 0 deletions src/gunpla/nu_gundam.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import time
import random

from src.gunpla.BaseGundam import BaseGundam
from src.phew.server import Response, Request
from src.pi import LED
Expand Down Expand Up @@ -48,3 +50,25 @@ def fire_funnels(self, request: Request) -> Response:
LEDEffects.fire(fin6)

return Response("finished", 200)

def random_funnels(self, request: Request) -> Response:
"""
Randomly fires fin funnels that are enabled for an infinite amount of time
This currently does not end and needs thread management to properly be able to be halted.
"""
funnels = [self._get_led_from_name("fin_funnel_1"), self._get_led_from_name("fin_funnel_2"),
self._get_led_from_name("fin_funnel_3"), self._get_led_from_name("fin_funnel_4"),
self._get_led_from_name("fin_funnel_5"), self._get_led_from_name("fin_funnel_6")]

# Filter out funnels that are disabled.
funnels = [funnel for funnel in funnels if funnel.enabled()]

if not funnels:
return Response("No funnels can be fired", 400)

while True:
funnel = random.choice(funnels)
LEDEffects.fire(funnel)
time.sleep(random.uniform(0, 3))

return Response("finished", 200)
8 changes: 7 additions & 1 deletion src/pi/DisabledLED.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ class DisabledLED(LED):
An LED that is disabled in the configuration. When attempted to manipulate by turning it on or off, it does nothing.
"""

def __init__(self, led_name: str):
def __init__(self, led_name: str): # pylint: disable=super-init-not-called
self.led_name = led_name

def enabled(self) -> bool:
"""
Returns false as the LED is not connected
"""
return False

def name(self) -> str:
return self.led_name

Expand Down
6 changes: 6 additions & 0 deletions src/pi/LED.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def __init__(self, pin_number: int, name: str):
self.pin: Pin = Pin(pin_number, Pin.OUT)
self.led_name = name

def enabled(self) -> bool:
'''
Returns false as the LED is not connected
'''
return True

def on(self) -> None:
"""
Turns on the LED light
Expand Down
2 changes: 1 addition & 1 deletion src/pi/board_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class BoardLED(LED):
Special Representation of the onboard Pico LED
"""

def __init__(self):
def __init__(self): # pylint # pylint: disable=(super-init-not-called
self.pin: Pin = Pin("LED", Pin.OUT)
self.led_name = "Board LED"
10 changes: 8 additions & 2 deletions src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# This requires just the basic Raspberry Pi Pico W
# Once deployed on the Pico W, it will flash the onboard LED.

from machine import Pin
import time

from machine import Pin


def main():
"""
Blinks the onboard Raspberry Pi Pico W LED several times.
"""
led = Pin("LED", Pin.OUT)
led.on()
time.sleep(0.5)
Expand All @@ -20,5 +25,6 @@ def main():
led.off()
time.sleep(0.5)


if __name__ == "__main__":
main()
main()

0 comments on commit a7a8c0f

Please sign in to comment.