~travisshears/sewa-reef-controller

2f911edf8a2c580b64a6319060d167276baeb9f3 — Travis Shears 7 months ago 170bfa1
add more power heads and tidal sim
M CIRCUITPY/aquarium_controller/feed_mode.py => CIRCUITPY/aquarium_controller/feed_mode.py +5 -6
@@ 1,8 1,7 @@
import time
from .power import feed_mode_prio
from .power import feed_mode_prio, all_pumps, power_heads

_pumps = ['main_pump', 'power_head_1', 'power_head_2']
_flow_pumps = ['power_head_1', 'power_head_2']
_food_mixing_pumps = [power_heads[0], power_heads[1]]
_prio = feed_mode_prio

class FeedMode():


@@ 21,7 20,7 @@ class FeedMode():
        self.started_part_two = False
        self.start_time = time.time()
        # turn pumps oof
        for pump in _pumps:
        for pump in all_pumps:
            self.core.publish('pwr', {
                'code': pump,
                'value': False,


@@ 32,7 31,7 @@ class FeedMode():
    def start_part_two(self):
        self.started_part_two = True
        # turn flow food mixing pumps on
        for pump in _flow_pumps:
        for pump in _food_mixing_pumps:
            self.core.publish('pwr', {
                'code': pump,
                'value': True,


@@ 48,7 47,7 @@ class FeedMode():
            'code': 'main_pump',
            'prio': _prio
        })
        for pump in _pumps:
        for pump in all_pumps:
            self.core.publish('release', {
                'code': pump,
                'prio': _prio,

M CIRCUITPY/aquarium_controller/flow.py => CIRCUITPY/aquarium_controller/flow.py +57 -22
@@ 1,30 1,65 @@
from .power import normal_sim_prio
from .power import normal_sim_prio, power_heads

p = {
    'right_low': power_heads[0],
    'left_low': power_heads[1],
    'right_high': power_heads[2],
    'left_high': power_heads[3]
}

patterns = {
    'SL': {
        'name': 'Soft Left',
        'pumps': [p['left_low']]
    },
    'SR': {
        'name': 'Soft Right',
        'pumps': [p['right_low']]
    },
    'C': {
        'name': 'Calm',
        'pumps': []
    },
    'HL': {
        'name': 'Hard Left',
        'pumps': [p['left_low'], p['left_high']]
    },
    'HR': {
        'name': 'Hard Right',
        'pumps': [p['right_low'], p['right_high']]
    },
    'X': {
        'name': 'Clean',
        'pumps': p
    },
    'MB': {
        'name': 'Mix Back',
        'pumps': [p['right_low'], p['left_low']]
    },
    'MF': {
        'name': 'Mix Front',
        'pumps': [p['right_high'], p['left_high']]
    },
    'CW': {
        'name': 'Clockwise spin',
        'pumps': [p['left_low'], p['right_high']]
    },
    'CRW': {
        'name': 'Counter Clockwise spin',
        'pumps': [p['right_low'], p['left_high']]
    }
}

raw_schedule = 'C,SL,CRW,CW,CRW,SR,C,MB,X,X,X,MF,C,HR,CW,CRW,CW,HL,C,SR,MB,SL,MB,MF,C,HL,CRW,CW,CRW,HR,C,SL,MB,SR,MB,MF,C,SR,CW,CRW,CW,SL,C,MB,SR,SL,MB,MF'
schedule = raw_schedule.split(',')

def flow_sim(core):
    flow_code = 'C'
    # R = Right, L= Left, M=Mixing, C=Calm
    base_pattern = ['R', 'M', 'L', 'M', 'M', 'C']
    pattern_names = {
        'R': 'Right',
        'L': 'Left',
        'M': 'Mixing',
        'C': 'Calm'
    }
    schedule = []
    for _ in range(8): # 6 * 8 = 48 and 24 * 2 = 48, there are 48 30min periods
        schedule += base_pattern
    all_pumps = ['power_head_1', 'power_head_2']
    pump_assignments = {
        'R': ['power_head_2'],
        'L': ['power_head_1'],
        'M': ['power_head_1', 'power_head_2'],
        'C': []
    }

    def manage_pumps():
        for pump_code in all_pumps:
        for pump_code in power_heads:
            new_pump_value = False
            if pump_code in pump_assignments[flow_code]:
            if pump_code in patterns[flow_code]['pumps']:
                new_pump_value = True
            core.publish('pwr', {
                'code': pump_code,


@@ 43,7 78,7 @@ def flow_sim(core):
        if(mode['code'] is not 'flow'):
            return
        core.publish('render', {
            'text': f"Current flow\npattern: {pattern_names[flow_code]}"
            'text': f"Current flow\npattern: {patterns[flow_code]['name']}"
        })

    core.subscribe('rtc time', on_tick)

M CIRCUITPY/aquarium_controller/power.py => CIRCUITPY/aquarium_controller/power.py +20 -3
@@ 1,12 1,29 @@
import board
import digitalio

all_pumps = [
    'power_head_1', # right low
    'power_head_2', # left  low
    'power_head_3', # right high
    'power_head_4',  # left  high
    'main_pump'
]

power_heads = [
    'power_head_1', # right low
    'power_head_2', # left  low
    'power_head_3', # right high
    'power_head_4'  # left  high
]

_default_power_state = {
    # 'test_pin': False
    'refigium_light': False,
    'main_pump': True, # carbon_reactor will mirror main_pump via powerstrip
    'power_head_1': True,
    'power_head_2': True,
    'power_head_3': False,
    'power_head_4': False,
}

# prios


@@ 30,6 47,8 @@ def power(core):
        'main_pump': board.GP26,
        'power_head_1': board.GP28,
        'power_head_2': board.GP22,
        'power_head_3': board.GP21,
        'power_head_4': board.GP20
    }

    # init prios


@@ 39,9 58,7 @@ def power(core):

    left_over_pins = [
        board.GP18,
        board.GP19,
        board.GP20,
        board.GP21,
        board.GP19
    ]

    # turn on all left over outlets

M CIRCUITPY/code.py => CIRCUITPY/code.py +1 -1
@@ 14,7 14,7 @@ from aquarium_controller.feed_mode import FeedMode
from aquarium_controller.power import power, id_outlets, master_power_switch, normal_sim_prio, hard_reset_prio
from aquarium_controller.flow import flow_sim

ver = '1.1.0'
ver = '1.2.0'

def util_mode(core):
    def change(mode):