void spanResetWires(Pin* source){ if (source == NULL) return; if (source->visited()) return; source->visited(true); Wire *wire = source->wire(); if (!wire) return; //cout <<"spanResetWires wire: "<< wire->info()<<endl; wire->voltage(false); list<Pin *>pins = wire->pins(); list<Pin *>::iterator it; for (it = pins.begin(); it != pins.end(); it++){ Pin *pin = (*it); if (pin == source) continue; pin->visited(true); Element *element = pin->element(); if (element->type() == "switch"){ Switch *switc = (Switch *)element; Pin *nextPin = switc->outPin(pin); spanResetWires(nextPin); } else if (element->type() == "resistor"){ Resistor *resistor = (Resistor *)element; Pin *nextPin = resistor->outPin(pin); spanResetWires(nextPin); } else if (element->type() == "bridge"){ Bridge *bridge = (Bridge *)element; Pin *nextPin = bridge->outPin(pin); spanResetWires(nextPin); } } }
Capacitor::Capacitor( QObject* parent, QString type, QString id ) : Component( parent, type, id ), eCapacitor() { m_ePin.resize(2); QString nodid = m_id; nodid.append(QString("lnod")); QPoint nodpos = QPoint(-16-8,0); Pin* pin = new Pin( 180, nodpos, nodid, 0, this); pin->setLength(12); pin->setPos(-16, 0 ); m_ePin[0] = pin; nodid = m_id; nodid.append(QString("rnod")); nodpos = QPoint(16+8,0); pin = new Pin( 0, nodpos, nodid, 1, this); pin->setLength(12); pin->setPos( 16, 0 ); m_ePin[1] = pin; label->setText( QString("") ); label->setPos(-16,-24); /*const QFont sansFont("Helvetica [Cronyx]", 7); m_labelcurr = Circuit::self()->addSimpleText( id.toLatin1().data(), sansFont ); m_labelcurr->setParentItem( this ); m_labelcurr->setPos(-13, -5.5 ); //m_labelcurr->rotate( 180-dir ); m_labelcurr->setText( QString("%1").arg(m_resist) );*/ }
virtual void eat() { TCritSect cs; LED0.On(); LED0.Off(); }
Pin *Module::getPinByOffset(double offsetX, double offsetY) { for (int i = 0; i < pins->size(); i++) { Pin *pin = pins->at(i); if (pin->getOffsetX() == offsetX && pin->getOffsetY() == offsetY) { return pin; } } return 0; }
int HWAdmux::GetMuxOutput() { int pin = admux&(MUX2|MUX1|MUX0); Pin* p = ad[pin]; if(!p){ cerr << "HWAdmux::GetMuxOutput null pin on " << pin << endl; return 0; } return p->GetAnalog(); }
void CCircuitView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. if (nChar == VK_DELETE) { CLogicSimulatorDoc *pDoc = (CLogicSimulatorDoc *)GetDocument(); int lin = pDoc->currBox->lines.size(); int lon = pDoc->currBox->logicInfo.size(); for (int i = 0; i < lin; i++) { if (pDoc->currBox->lines.at(i)->isSelected == TRUE) { delete pDoc->currBox->lines.at(i); pDoc->currBox->lines.erase(pDoc->currBox->lines.begin() + i); lin--; } } for (int i = 0; i < lon; i++) { if (pDoc->currBox->logicInfo.at(i)->isSelected == TRUE) { //OUT & INPIN Ưº° Ãë±Þ if (pDoc->currBox->logicInfo.at(i)->objectName == PIN) { Pin* TP = (Pin*)pDoc->currBox->logicInfo.at(i); if (TP->getConNum() >= 0) pDoc->currBox->ConnInput[TP->getConNum()] = FALSE; pDoc->currBox->NumInput--; } else if (pDoc->currBox->logicInfo.at(i)->objectName == OUTPIN) { Out* TO = (Out*)pDoc->currBox->logicInfo.at(i); if (TO->getConNum() >= 0) pDoc->currBox->ConnOutput[TO->getConNum()] = FALSE; pDoc->currBox->NumOuput--; } delete pDoc->currBox->logicInfo.at(i); pDoc->currBox->logicInfo.erase(pDoc->currBox->logicInfo.begin() + i); lon--; } } pDoc->currBox->LineCheck(); pDoc->CheckPoint(); Invalidate(); } CView::OnKeyDown(nChar, nRepCnt, nFlags); }
extern "C" void pinMode(uint8_t pin, uint8_t mode) { ResourceMap *rmap = ResourceMap::getInstance(); Pin *p = rmap->getPin(pin); if (!p) return; p->setTris(mode); }
extern "C" void digitalWrite(uint8_t pin, uint8_t val) { ResourceMap *rmap = ResourceMap::getInstance(); Pin *p = rmap->getPin(pin); if (!p) return; p->setValue(val); }
extern "C" int digitalRead(uint8_t pin) { ResourceMap *rmap = ResourceMap::getInstance(); Pin *p = rmap->getPin(pin); if (!p) return -1; if (p->getValue()) return HIGH; return LOW; }
void Motor::directionPin( const int& value) { Pin* pin = Esp8266::getInstance()->getPin(directionPinId); if (pin) { pin->digitalWrite(value); Logger::logDebug("Direction pin[" + String(pin->getPinId()) + "] = " + String(value) + "\n"); } }
void Motor::speedPin( const int& value) { Pin* pin = Esp8266::getInstance()->getPin(speedPinId); if (pin) { pin->analogWrite(value); Logger::logDebug("Speed pin[" + String(pin->getPinId()) + "] = " + String(value) + "\n"); } }
void Scope::SetInStateForChannel(unsigned int channel, Pin& p) { if ( lastVal[channel]!= p.GetAnalog() ) { ostringstream os; os << name << " ChangeValue " << SystemClock::Instance().GetCurrentTime() << " " << channel << " " << p.GetAnalog()<<endl; ui->Write(os.str()); //cout << "Set last val for channel " << channel << " value " << p.GetAnalog() << endl; lastVal[channel]=p.GetAnalog(); //cout << "OK" << endl << endl; } }
int main() { // configure IO pins LED0.Direct(OUTPUT); LED0.Off(); LED1.Direct(OUTPUT); LED1.Off(); // run OS OS::run(); }
INTERRUPT_HANDLER(Timer3_period_ISR, ITC_IRQ_TIM3_OVF) { TIMER3_ISR.On(); TIM3->SR1 &= ~TIM3_SR1_UIF; OS::TISRW ISRW; TIMER3_TO_PROC1.On(); Timer3_Ovf.signal_isr(); TIMER3_ISR.Off(); }
void Thrusters::device_setup(){ port_motor.reset(); vertical_motor.reset(); starboard_motor.reset(); thrusterOutput.reset(); controltime.reset(); bypasssmoothing = false; #ifdef ESCPOWER_PIN escpower.reset(); escpower.write(1); //Turn on the ESCs #endif }
//void spanResistors(Pin *source, list<Wire *>wires){ void spanResistors(Pin *source, list<Resistor *>resistors){ //cout <<"entering spanResistors"<<endl; /* 1. try to reach the end. * 2. if end is reached, must go back and turn all wires on in the path */ if (source == NULL) return; if (source->visited()) return; source->visited(true); //debug("spanResistors source pin: "<< source->fullName()); Wire *wire = source->wire(); if (!wire) return; //debug("spanResistors wire: "<< wire->name()); list<Pin *>pins = wire->pins(); list<Pin *>::iterator it; for (it = pins.begin(); it != pins.end(); it++){ Pin *pin = (*it); if (pin == source) continue; pin->visited(true); //get element for source Element *element = pin->element(); if (element->type() == "source"){ //cerr << "Encountered source "<< element->info() <<" while completing circuit."<<endl; return; } else if (element->type() == "ground"){ //cout <<"ground reached: "<<endl; //end reached. activateResistors(resistors); //upWires(wires); } else if (element->type() == "switch"){ Switch *switc = (Switch *)element; if (!switc->isOn()) continue; Pin *nextPin = switc->outPin(pin); spanResistors(nextPin,resistors); } else if (element->type() == "resistor"){ Resistor *resistor = (Resistor *)element; resistors.push_back(resistor); Pin *nextPin = resistor->outPin(pin); spanResistors(nextPin, resistors); } else if (element->type() == "bridge"){ Bridge *bridge = (Bridge *)element; Pin *nextPin = bridge->outPin(pin); spanResistors(nextPin, resistors); } } }
void Circuit::calculateCellsPins(){ int halfPinSize=currentRules->getRule(E1M1VI)+currentRules->getRule(W2VI)/2; int hGrid=currentRules->getIntValue(getHPitch()), vGrid=currentRules->getIntValue(getVPitch()); for(map<string, CellNetlst>::iterator cellNetlsts_it=cellNetlsts.begin(); cellNetlsts_it!=cellNetlsts.end(); ++cellNetlsts_it){ map<string, CLayout>::iterator layouts_it=layouts.find(cellNetlsts_it->first); if(layouts_it!=layouts.end()){ layouts_it->second.getPins().clear(); for(int x=hGrid/2; x<=layouts_it->second.getWidth(); x+=hGrid){ for(int y=vGrid; y<=layouts_it->second.getHeight()-vGrid; y+=vGrid){ string connectedNet="none"; string aroundNet="none"; bool fail=false; int finalX, finalY; for(map <layer_name , list<Box> >::iterator layers_it = layouts_it->second.layers.begin(); layers_it != layouts_it->second.layers.end(); layers_it++){ if(layers_it->first==MET1){ for(list <Box>::iterator layer_it = layers_it->second.begin(); layer_it != layers_it->second.end(); layer_it++){ int dx=max(layer_it->getX1(),x-halfPinSize) - min(layer_it->getX2(),x+halfPinSize); int dy=max(layer_it->getY1(),y-halfPinSize) - min(layer_it->getY2(),y+halfPinSize); if(dx<=-(2*halfPinSize-1) && dy<=-(2*halfPinSize-1)){ if(connectedNet=="none"){ connectedNet=layer_it->getNet(); finalX=x; finalY=y; } if(connectedNet!=layer_it->getNet() || (aroundNet!="none" && aroundNet!=connectedNet)) fail=true; }else if((dx<0 && dy<0) || (dx<=0 && dy>=0 && dy<currentRules->getRule(S1M1M1)-1) || (dx>=0 && dy<=0 && dx<currentRules->getRule(S1M1M1)-1) || (dx>=0 && dy>=0 && sqrt(float(dx*dx+dy*dy))<currentRules->getRule(S1M1M1)-1)){ if(aroundNet=="none") aroundNet=layer_it->getNet(); if(aroundNet!=layer_it->getNet() || (connectedNet!="none" && aroundNet!=connectedNet)) fail=true; } } } } Pin p; p.setPos(x,y); p.setLayer(MET1); if(!fail && connectedNet!="none" && connectedNet!=""){ layouts_it->second.getPins().insert(make_pair(connectedNet,p)); layouts_it->second.addLabel(connectedNet, Point(x, y)); } else if(!(connectedNet=="none" && aroundNet=="none")){ layouts_it->second.getPins().insert(make_pair("bl",p)); // layouts_it->second.addLabel("bl", Point(x, y)); } } } } } }
void Motor::setup() { Pin* pin = Esp8266::getInstance()->getPin(directionPinId); if (pin) { pin->setMode(OUTPUT); } pin = Esp8266::getInstance()->getPin(speedPinId); if (pin) { pin->setMode(OUTPUT); } }
NavModeAutoTest () { system("gpsd -n -S 3001 /dev/ttyS4 /dev/ttyACM0"); mode = NavModeBase::factory(me, NavModeEnum::AUTONOMOUS); rcchannels->at(Conf::get()->RCchannelMap().at("auto")) = Conf::get()->RClimits().at("min"); start = std::chrono::system_clock::now(); me.health = &health; health.setADCdevice(&adc); me.rudder = &rudder; me.throttle = &throttle; me.rc = &rc; me.adc = &adc; me.gps = &gps; me.orient = &orient; me.relays = RelayMap::instance(); adc.init(); me.relays->init(); harness.accessADC(&adc, &adcraw, &adcvalid); harness.accessRC(&rc, NULL, NULL, &rcfailsafe, &rcvalid, &rcchannels, NULL, NULL, NULL); harness.accessGPSd(&gps, &fix, NULL); harness.accessOrientation(&orient, &orientvalue, &orientvalid); for (auto r: *me.relays->getmap()) { Pin *drive; Pin *fault; harness.accessRelay(r.second, &drive, &fault); fault->setDir(true); fault->init(); fault->clear(); } fix->fixValid = true; fix->speed = 0; fix->track = 0; fix->fix.lat = 48.0; fix->fix.lon = -114.0; me.lastFix = *fix; me.rudder->attach(Conf::get()->rudderPort(), Conf::get()->rudderPin()); me.disarmInput.setDir(true); me.disarmInput.init(); me.disarmInput.set(); me.armInput.setDir(true); me.armInput.init(); me.armInput.clear(); *adcvalid = true; *rcvalid = true; *rcfailsafe = false; *orientvalid = true; adcraw->at(Conf::get()->batmonName()) = 3000; health.readHealth(); }
void MSERNode::tick( double dt ) { Timer t; t.start(); Pin* outPin = findPinFromLabel("out"); Pin* inPin = findPinFromLabel("in"); if( !inPin->isConnected() ) waitForConnection(); if( !outPin->isConnected() ) waitForConnection(); if( outPin->isConnected() && inPin->isConnected() ) { vector<ObjectBlob*> b = inPin->read(); if( b.size() > 0 ) { for( int k = 0; k < b.size(); ++k ) { if( b[k]->getTypeName() == "Image" ) { monadic::Image img; img.deserialize(b[k]); cv::Mat m( img.getHeight(), img.getWidth(), CV_8UC3, img.ptr() ); cv::Mat res( img.getHeight(), img.getWidth(), CV_8UC3 ); res = m.clone(); cv::cvtColor( m, m, CV_RGB2GRAY ); vector< vector< cv::Point > > ret; cv::MSER* det = (cv::MSER*)(detector); (*det)(m, ret); for( size_t i = 0; i < ret.size(); ++i ) { //cv::circle( res, kps[i].pt, 3, CV_RGB(255,0,0) ); cv::Rect r = cv::boundingRect(ret[i]); cv::rectangle( res, r, CV_RGB(255,0,0), 3 ); } monadic::Image imgout; imgout.create( res.cols, res.rows, 8, res.channels() ); size_t bufferSize = res.cols * res.rows * res.channels(); imgout.copyFrom( (char*)res.data, bufferSize ); ObjectBlob* bout = imgout.serialize(); outPin->write( bout ); delete bout; } delete b[k]; } } } t.stop(); }
inline bool wait_for(bool value, unsigned int timeout) { timeout += millis(); while (echo->read_digital() != value) if (millis() > timeout) return false; return true; }
void OS::system_timer_user_hook() { static int timer_event_counter = 5; if (!--timer_event_counter) { timer_event_counter = 5; LED1.On(); TimerEvent.signal_isr(); } }
void setup() { Serial.begin(9600); ppm_sp.setup(); ppm_rl.setup(); motor_l.setup(); motor_r.setup(); power_h_bridge.set_output(true); }
void removeFromPin(Pin &pin) { // get disc on the middle point goTo(pin.x, pin.y, (pin.num_discs - 0.5) * DISC_HEIGHT + BASE_HEIGHT); // close Gripper! closeGripper(); // go to the top of the pin goTo(pin.x, pin.y, (3 + ALPHA) * DISC_HEIGHT + BASE_HEIGHT); // update pin state pin.remove(); }
void moveToPin(Pin &pin) { // go to the top of the pin goTo(pin.x, pin.y, (3 + ALPHA) * DISC_HEIGHT + BASE_HEIGHT); // update pin state pin.add(); // get disc on the middle point goTo(pin.x, pin.y, (pin.num_discs - 0.5) * DISC_HEIGHT + BASE_HEIGHT); // open Gripper! openGripper(); }
void move_discs(Pin &orig, Pin &dest, int num_discs) { // Stop case of recorrence if (num_discs == 1) { move_disc(orig, dest); return; } // Discover intermediate pin if (orig.pos() != PIN_A && dest.pos() != PIN_A) { move_discs(orig, p_a, num_discs - 1); move_disc(orig, dest); move_discs(p_a, dest, num_discs - 1); } else if (orig.pos() != PIN_B && dest.pos() != PIN_B) { move_discs(orig, p_b, num_discs - 1); move_disc(orig, dest); move_discs(p_b, dest, num_discs - 1); } else { move_discs(orig, p_c, num_discs - 1); move_disc(orig, dest); move_discs(p_c, dest, num_discs - 1); } }
PluginChip::PluginChip(DLLHANDLETYPE aDllHandle, const char *aChipname) { memset(&mChipInfo,0,sizeof(mChipInfo)); dllcreate = (createproc)getdllproc(aDllHandle, "create"); dllupdate = (updateproc)getdllproc(aDllHandle, "update"); dllrender = (renderproc)getdllproc(aDllHandle, "render"); dllcleanup = (cleanupproc)getdllproc(aDllHandle, "cleanup"); if (dllcreate == NULL || dllupdate == NULL || dllrender == NULL || dllcleanup == NULL || dllcreate(&mChipInfo, aChipname) == 0) { dllcreate = NULL; return; } set(0, 0, mChipInfo.mWidth, mChipInfo.mHeight, mChipInfo.mTooltip); int i; for (i = 0; i < mChipInfo.mPinCount; i++) { const char *tt = NULL; Pin *p = new Pin; mPin.push_back(p); if (mChipInfo.mPinTooltips) tt = mChipInfo.mPinTooltips[i]; if (tt == NULL) tt = "-"; p->set(mChipInfo.mPinCoordinates[i*2+0], mChipInfo.mPinCoordinates[i*2+1], this, tt); } mTexture = 0; if (mChipInfo.mTextureFilename) mTexture = load_texture((char*)mChipInfo.mTextureFilename); }
void Lights::device_loop(Command command){ if( command.cmp("ligt")){ int value = command.args[1]; //0 - 255 light.write(value); _SERIAL_PORT_.print(F("LIGT:")); _SERIAL_PORT_.print(value); _SERIAL_PORT_.print(';'); _SERIAL_PORT_.print(F("LIGP:")); _SERIAL_PORT_.print(command.args[1]/255.0); _SERIAL_PORT_.println(';'); } }
VibrationSensor2::VibrationSensor2( const String& id, const int& pinId) : Component(id) { this->pinId = pinId; serverId = ""; sensitivity = DEFAULT_SENSITIVITY; responsiveness= DEFAULT_RESPONSIVENESS; vibrationCount = 0; for (int i = 0; i < NUM_INTERVALS; i++) { queue[i] = NOT_VIBRATING; } Pin* pin = Esp8266::getInstance()->getPin(pinId); if (pin) { pin->setMode(INPUT); } stateChangeTime = millis(); }
void Pin::copy(const Pin &rhs) { setPen(rhs.pen()); attributes = rhs.attributes; hidden = rhs.hidden; _length = rhs._length; _bubble = rhs._bubble; bubbleToggle = rhs.bubbleToggle; clock = rhs.clock; position = rhs.position; // pinname and pinnumber depend on bubble and clock so they need to be assigned after bubble and clock pinname = rhs.pinname; pinnumber = rhs.pinnumber; rebuild(); }