示例#1
0
 void onElectricThink()
 {
     InputPin *value = getInputPin("value");
     OutputPin *control = getOutputPin("control");
     Signal::Voltage fValue = value->outputSignal().getVoltage();
     bool controlOutput = control->outputSignal().isHigh();
     if(mBelowMax)
     {
         if(fValue < mHigher)
             controlOutput = true;
         else
         {
             mBelowMax = false;
             controlOutput = false;
         }
     }
     else
     {
         if(fValue > mLower)
             controlOutput = false;
         else
         {
             mBelowMax = true;
             controlOutput = true;
         }
     }
     if(control->outputSignal().isHigh() != controlOutput)
         control->inputSignal(Signal(controlOutput));
     Device::sleep();
 }
示例#2
0
    virtual void onThink()
    {
        SinkConnector *energyIn = getInput("energy-in");
        SourceConnector *energyOut = getOutput("energy-out");
        OutputPin *readout = getOutputPin("readout");
        mStored.attemptPumpSource(energyIn, Testing::Generator::ENERGY_PER_GENERATION);
        mStored.attemptPumpSink(energyOut, Testing::Generator::ENERGY_PER_GENERATION / 2);

        // 'waste' some output
        energyOut->pumpSource(Testing::Generator::ENERGY_PER_GENERATION / 4);

        Resource::Quantity stored = mStored.getQuantity() + energyOut->sourceQuantity();
        float percentFull = (float) stored / mStored.getCapacity();
        if(readout->outputSignal().getVoltage() != percentFull)
            readout->inputSignal(Signal(percentFull));

        cout << "[capacitor] percent full: " << (percentFull * 100.0) << endl;

        // go to sleep
        if(mStored.getQuantity() <= 0)
            Module::sleep();
    }