[812dd5]: / src / lib / simulator / src / electronics / components / discretelogic.cpp  Maximize  Restore  History

Download this file

119 lines (86 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "discretelogic.h"
#include "logic.h"
#include "simulator.h"
//BEGIN class Inverter
Inverter::Inverter(Circuit& ownerCircuit)
: Component(ownerCircuit) {
m_pOut.setState(true);
m_pIn.setCallback(this, (CallbackPtr)(&Inverter::inStateChanged));
inStateChanged(false);
}
Inverter::~Inverter() {
}
void Inverter::inStateChanged(bool newState) {
m_pOut.setHigh(!newState);
}
//END class Inverter
//BEGIN class Buffer
Buffer::Buffer(Circuit& ownerCircuit)
: Component(ownerCircuit) {
m_pIn.setCallback(this, (CallbackPtr)(&Buffer::inStateChanged));
inStateChanged(false);
}
Buffer::~Buffer() {
}
void Buffer::inStateChanged(bool newState) {
m_pOut.setHigh(newState);
}
//END class Buffer
//BEGIN class ECLogicInput
ECLogicInput::ECLogicInput(Circuit& ownerCircuit)
: Component(ownerCircuit) {
Property *useToggle = new Property("useToggle", Variant::Type::Bool);
useToggle->setCaption(tr("Use Toggle"));
useToggle->setValue(true);
addProperty(useToggle);
Property *buttonPressed = new Property("buttonPressed", Variant::Type::Bool);
buttonPressed->setValue(false);
buttonPressed->setCaption(tr("Button pressed"));
addProperty(buttonPressed);
m_outState = false;
m_toggleOn = true;
}
ECLogicInput::~ECLogicInput() {
}
void ECLogicInput::propertyChanged(Property& theProperty, QVariant newValue, QVariant oldValue)
{
Q_UNUSED(oldValue);
if( theProperty.name() == "useToggle" ){
m_toggleOn = newValue.toBool();
}
if( theProperty.name() == "buttonPressed" ){
if(m_toggleOn)
m_outState = !m_outState;
else
m_outState = newValue.toBool();
m_pOut.setHigh(m_outState);
}
}
//END class ECLogicInput
//BEGIN class ECLogicOutput
ECLogicOutput::ECLogicOutput(Circuit& ownerCircuit)
: Component(ownerCircuit) {
outValue = new Property("outputValue", Variant::Type::Double);
outValue->setMinValue(0);
outValue->setMaxValue(1);
m_pIn.setCallback(this, (CallbackPtr)(&ECLogicOutput::inStateChanged));
}
ECLogicOutput::~ECLogicOutput() {
}
void ECLogicOutput::inStateChanged(bool newState) {
if (m_bLastState == newState) return;
if(newState)
outValue->setValue(1.0);
else
outValue->setValue(0.0);
}
//END class ECLogicOutput