Skip to content

Conversation

Mikefly123
Copy link
Member

@Mikefly123 Mikefly123 commented Jul 1, 2025

Summary

This is a fully vibe coded load switch manager component made in Cursor. The original prompt was as follows:

Based on the current structure of this repository, I would like to start implementing a loadswitch manager in CircuitPython. Help me with this process.

Generally what I want this component to do is to:

  • Provide a consistant interface for toggling the state of load switches from on to off using an enable pin
  • Create a way to build a unique implementation of the load switch manager for unique board implementations.
  • Allow for custom naming of the individual load switch objects
  • Implement a way to track what the state of each load switch in a public dictionary
  • Implement public functions for turning all load switches off and all load switches on

It is kind of shocking that it actually works! I did not personally write a single line of code in this PR. After some deliberation during the July 1, 2025 software working group meeting though we decided to move in a different direction, so this PR will probably be abandoned for that instead.

The new approach we want to look into is just having device managers inherit the load switch proto, so their on/off state is stored locally rather than in a separate component. This would simplify use of the code significantly, but it would also cause challenges for backwards compatibility on boards that don't have load switching capabilities. See #230 for a little more discussion about this.

How was this tested

  • Added new unit tests
  • Ran code on hardware (screenshots are helpful)
  • Other (Please describe)
Test on Hardware Output
Adafruit CircuitPython 9.2.4-11-gf12e5e9ed4 on 2025-04-21; PROVESKit FC Board RP2350 V5a with rp2350a
>>> from pysquared.hardware.load_switch.manager.load_switch import LoadSwitchManager
>>> load_switches = {"Face0", F
Flag            FACE4_ENABLE    FACE0_ENABLE    FACE1_ENABLE
FACE2_ENABLE    FACE3_ENABLE    Face
>>> load_switches = {"Face0":FACE0_ENABLE,"Face1":FACE1_ENABLE}
>>> load_switch_manager = LoadSwitchManager(logger, load_switches, enable_logic=True)
{"time": "2000-01-01 00:11:17", "level": "DEBUG", "msg": "Initialized load switch 'Face0' to off state"}
{"time": "2000-01-01 00:11:17", "level": "DEBUG", "msg": "Initialized load switch 'Face1' to off state"}
>>> load_switch_manager
<LoadSwitchManager object at 0x20026ac0>
>>> 
Counter         __dict__        __file__        __version__
board           c               digitalio       os
register        rtc             sdcardio        storage
time            watchdog        PowerMonitorProto
functions       DRV2605         MCP23017        MCP9808
TCA9548A        VEML7700        cdh
CommandDataHandler              config          Config
BurnwireManager                 _spi_init
initialize_i2c_bus              initialize_pin  imu
LSM6DSOXManager                 magnetometer    LIS2MDLManager
INA219Manager   radio           RFM9xManager    SX1280Manager
logger          Logger          Flag
MicrocontrollerManager          Satellite       sleep_helper
SleepHelper     Watchdog        mux_reset       spi0
spi1            i2c0            i2c1
burnwire_heater_enable          burnwire1_fire  use_fsk_flag
f               sd              vfs             radio2
battery_power_monitor           solar_power_monitor
antenna_deployment              heater_pulse    ENABLE_HEATER
GPIO_RESET      mcp             FACE4_ENABLE    FACE0_ENABLE
FACE1_ENABLE    FACE2_ENABLE    FACE3_ENABLE    ENAB_RF
VBUS_RESET      SPI0_CS1        PAYLOAD_PWR_ENABLE
Z_GPIO0         Z_GPIO1         RF2_IO2         RF2_IO1
all_faces_off   all_faces_on    tca             Face
AllFaces        all_faces       LoadSwitchManager
load_switches   load_switch_manager
>>> help(load_switch_manager
... )
object <LoadSwitchManager object at 0x20026ac0> is of type LoadSwitchManager
  __module__ -- pysquared.hardware.load_switch.manager.load_switch
  remove_switch -- <function remove_switch at 0x0x20036c60>
  __qualname__ -- LoadSwitchManager
  _initialize_switches -- <closure>
  add_switch -- <function add_switch at 0x0x20036be0>
  turn_on -- <function turn_on at 0x0x20035020>
  turn_all_on -- <function turn_all_on at 0x0x20035b80>
  __init__ -- <function __init__ at 0x0x200370f0>
  get_switch_state -- <function get_switch_state at 0x0x20036510>
  get_all_states -- <function get_all_states at 0x0x200365d0>
  turn_all_off -- <function turn_all_off at 0x0x20036130>
  turn_off -- <function turn_off at 0x0x20035730>
  get_switch_names -- <function get_switch_names at 0x0x20036e90>
>>> load_switch_manager.turn_on("Face1")
{"time": "2000-01-01 00:12:00", "level": "DEBUG", "msg": "Turned on load switch: Face1"}
True
>>> load_switch_manager.turn_off("Face1")
{"time": "2000-01-01 00:12:07", "level": "DEBUG", "msg": "Turned off load switch: Face1"}
True
>>> load_switch_manager.get_switch_names()
['Face0', 'Face1']
>>> load_switch_manager.get_switch_state("Face0
Traceback (most recent call last):
  File "<stdin>", line 1
SyntaxError: invalid syntax
>>> load_switch_manager.get_switch_state("Face0")
False
>>> load_switch_manager.add_switch("Face2",FACE2_ENABLE)
{"time": "2000-01-01 00:13:14", "level": "DEBUG", "msg": "Added new load switch: Face2"}
True
>>> load_switch_manager.get_switch_names()
['Face0', 'Face1', 'Face2']
>>> load_switch_manager.turn_all_on()
{"time": "2000-01-01 00:13:28", "level": "DEBUG", "msg": "Turned on load switch: Face0"}
{"time": "2000-01-01 00:13:28", "level": "DEBUG", "msg": "Turned on load switch: Face1"}
{"time": "2000-01-01 00:13:28", "level": "DEBUG", "msg": "Turned on load switch: Face2"}
{"time": "2000-01-01 00:13:28", "level": "INFO", "msg": "Turned on all load switches"}
True
>>> load_switch_manager.turn_all_off()
{"time": "2000-01-01 00:13:32", "level": "DEBUG", "msg": "Turned off load switch: Face0"}
{"time": "2000-01-01 00:13:32", "level": "DEBUG", "msg": "Turned off load switch: Face1"}
{"time": "2000-01-01 00:13:32", "level": "DEBUG", "msg": "Turned off load switch: Face2"}
{"time": "2000-01-01 00:13:32", "level": "INFO", "msg": "Turned off all load switches"}
True
>>> load_switch_manager.remove_switch("Face2")
{"time": "2000-01-01 00:13:53", "level": "DEBUG", "msg": "Turned off load switch: Face2"}
{"time": "2000-01-01 00:13:53", "level": "DEBUG", "msg": "Removed load switch: Face2"}
True
>>> load_switch_manager.get_switch_names()
['Face0', 'Face1']
>>> 

Signed-off-by: Michael Pham <[email protected]>
Signed-off-by: Michael Pham <[email protected]>
Signed-off-by: Michael Pham <[email protected]>
Copy link

sonarqubecloud bot commented Jul 1, 2025

@Mikefly123 Mikefly123 changed the title [DRAFT] Mike vibe loadswitches Vibecoded Load Switch Manager Jul 2, 2025
@Mikefly123 Mikefly123 added wontfix This will not be worked on Refactor labels Jul 14, 2025
@Mikefly123
Copy link
Member Author

Closing this as overtaken by #269 which will add a load switch proto

@Mikefly123 Mikefly123 closed this Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant