def __init__(self): inputs = {} outputs = {} n1 = Nor() n2 = Nor() inputs["set"] = n1.input_a inputs["reset"] = n2.input_b output_q_ = Cathode() output_q = Cathode() n1_split = Split() n2_split = Split() n1.output.connect(n1_split.input) n1_split.connect(n2.input_a) n1_split.connect(output_q_) n2.output.connect(n2_split.input) n2_split.connect(n1.input_b) n2_split.connect(output_q) outputs["output_q_"] = output_q_ outputs["output_q"] = output_q super(SRFlipFlop, self).__init__(inputs, outputs)
def test_cathode_value_changed(): event = Event() a = Anode() c = Cathode(value_changed = event.set) a.connect(c) a.value = True assert event.is_set
def test_anode_cathode(): a = Anode() c = Cathode() a.connect(c) a.value = True assert c.value
def connect(self, aninput): #add the input to the connections self._join_inputs.append(aninput) #create and connect cathode to the input cathode = Cathode(value_changed = self._update_state) aninput.connect(cathode) self._update_state()
def __init__(self): inputs = {} outputs = {} aj1 = And() aj2 = And() ak1 = And() ak2 = And() sr = SRFlipFlop() clk_split = Split() q_split = Split() qsplit = Split() #connect up the inputs inputs["input_j"] = aj1.input_a inputs["clock"] = clk_split.input clk_split.connect(aj1.input_b) clk_split.connect(ak1.input_a) inputs["input_k"] = ak1.input_b #connect the 2nd AND gates to the SR flip flop aj1.output.connect(aj2.input_b) ak1.output.connect(ak2.input_a) aj2.output.connect(sr.set) ak2.output.connect(sr.reset) #connect up the sr outputs output_q_ = Cathode() output_q = Cathode() sr.output_q_.connect(q_split.input) q_split.connect(aj2.input_a) q_split.connect(output_q_) sr.output_q.connect(qsplit.input) qsplit.connect(ak2.input_b) qsplit.connect(output_q) outputs["output_q_"] = output_q_ outputs["output_q"] = output_q super(JKFlipFlop, self).__init__(inputs, outputs)
def test_multipower(): mp = MultiPower() c1 = Cathode() c2 = Cathode() mp.connect(c1) assert not c1.value mp.on() assert c1.value mp.connect(c2) assert c2.value mp.off() assert not c1.value assert not c2.value mp = MultiPower(on=True) mp.connect(c1) assert c1.value
def __init__(self, connect_to_power = True): self._collector = Cathode(value_changed = self._update_state) self._base = Cathode(value_changed = self._update_state) self._emitter = Anode() #an output from the collector (an inverse of the emitter), used not NOT self._collector_output = Anode() if connect_to_power: _MAINPOWER.connect(self._collector) self._update_state() inputs = {} inputs["collector"] = self._collector inputs["base"] = self._base outputs = {} outputs["emitter"] = self.emitter outputs["collector output"] = self.collector_output super(Transistor, self).__init__(inputs, outputs)
def __init__(self, *outputs): inputs = {} #if the input changes, update the outputs inputs["input"] = Cathode(value_changed = self._update_state) #create the split with zero outputs super(Split, self).__init__(inputs, {}) #nodes the split will output to and update self._split_outputs = [] # connect up the outputs for output in outputs: self.connect(output)
def test_split(): sw = Power() c1 = Cathode() c2 = Cathode() c3 = Cathode() split = Split(c1, c2) sw.connect(split.input) sw.off() assert not split.input.value assert not c1.value assert not c2.value sw.on() assert split.input.value assert c1.value assert c2.value split.connect(c3) assert c3.value sw.off() assert not split.input.value assert not c1.value assert not c2.value assert not c3.value
def __init__(self): data_split = Split() write_split = Split() inputs = {} inputs["data"] = data_split.input inputs["write"] = write_split.input outputs = {} output = Cathode() outputs["output"] = output n1 = Not() n2 = Not() a1 = And() a2 = And() a3 = And() o = Or() data_split.connect(a1.input_a) data_split.connect(n1.input) n1.output.connect(a2.input_a) write_split.connect(a1.input_b) write_split.connect(a2.input_b) a1.output.connect(o.input_b) a2.output.connect(n2.input) o.output.connect(a3.input_a) n2.output.connect(a3.input_b) a_output_split = Split() a3.output.connect(a_output_split.input) a_output_split.connect(o.input_a) a_output_split.connect(output) super(GatedLatch, self).__init__(inputs, outputs)
def __init__(self): o = Or() a = And() n = Not() inputs = {} inputs["set"] = o.input_b inputs["reset"] = n.input outputs = {} output = Cathode() outputs["output"] = output o.output.connect(a.input_a) n.output.connect(a.input_b) a_output_split = Split() a.output.connect(a_output_split.input) a_output_split.connect(o.input_a) a_output_split.connect(output) super(AndOrLatch, self).__init__(inputs, outputs)
def test_join(): sw1 = Power() sw2 = Power() sw3 = Power() o = Cathode() j = Join(sw1, sw2) j.output.connect(o) sw1.off() sw2.off() sw3.off() assert not j.value assert not o.value sw1.on() assert j.value assert o.value sw2.on() assert j.value assert o.value sw1.off() sw2.off() assert not j.value assert not o.value sw3.on() j.connect(sw3) assert j.value assert o.value sw1.off() sw2.off() sw3.off() assert not j.value assert not o.value
def __init__(self): inputs = {} outputs = {} n1 = ThreeInputNand() n2 = ThreeInputNand() n3 = Nand() n4 = Nand() n5 = Nand() n6 = Nand() n7 = Nand() n8 = Nand() n = Not() clk_split = Split() n3_split = Split() n4_split = Split() n_split = Split() n7_split = Split() n8_split = Split() output_q_ = Cathode() output_q = Cathode() self.components = {} self.components["clk_split"] = clk_split self.components["n3_split"] = n3_split self.components["n4_split"] = n4_split self.components["n_split"] = n_split # inputs inputs["input_j"] = n1.input_b inputs["clock"] = clk_split.input inputs["input_k"] = n2.input_b # clock split clk_split.connect(n1.input_c) clk_split.connect(n2.input_a) clk_split.connect(n.input) # nand 1 n1.output.connect(n3.input_a) # nand 2 n2.output.connect(n4.input_b) # nand 3 n3.output.connect(n3_split.input) # nand 4 n4.output.connect(n4_split.input) # not n.output.connect(n_split.input) # nand 3 split n3_split.connect(n4.input_a) n3_split.connect(n5.input_a) # nand 4 split n4_split.connect(n3.input_b) n4_split.connect(n6.input_b) # not split n_split.connect(n5.input_b) n_split.connect(n6.input_a) # nand 5 n5.output.connect(n7.input_a) # nand 6 n6.output.connect(n8.input_b) # nand 7 n7.output.connect(n7_split.input) # nand 8 n8.output.connect(n8_split.input) # nand 7 split n7_split.connect(n8.input_a) n7_split.connect(output_q) n7_split.connect(n2.input_c) # nand 8 split n8_split.connect(n7.input_b) n8_split.connect(output_q_) n8_split.connect(n1.input_a) outputs["output_q_"] = output_q_ outputs["output_q"] = output_q super(MasterSlaveJKFlipFlop, self).__init__(inputs, outputs)
def test_cathode(): c = Cathode() assert not c.value