Ejemplo n.º 1
0
void KSimIoJoin::setPin(const KSimIoPin * pin)
{

	Q_ASSERT(pin != (const KSimIoPin*)0);

	if(m_pin)
	{
		disconnect(m_pin, SIGNAL(destroyed()), this, SLOT(slotPinDelete()));
	}
	if(m_device)
	{
		m_device->unregisterJoin(this);
		getIoComponent()->getContainer()->unregisterIoDevice(m_device);
	}

	m_pin = pin;
	m_p->ioPinID = getPin()->getPinID();

	m_device = m_pin->getDevice();
	Q_CHECK_PTR(m_device);
	m_device->registerJoin(this);
	getIoComponent()->getContainer()->registerIoDevice(m_device);
	m_p->deviceName = getDevice()->getName();

	m_p->defaultConnectorName = QString::fromLatin1("%1(%2)").arg(m_p->deviceName)
	                                          .arg(getPin()->getDefaultI18nName());

	// Rename connector
	updateConnName();

	connect(m_pin, SIGNAL(destroyed()), this, SLOT(slotPinDelete()));

	KSIMDEBUG_VAR("KSimIoJoin::setPin", getDefaultPinName());
}
MeshPortPinDigitalOut::MeshPortPinDigitalOut(int pin, byte local_auto_io_map) : MeshPortPin(pin){
	setOutputMask(getBitMaskForPin(getPin()));
	setLocalAutoIoMap(local_auto_io_map);
	pinMode(getPin(), OUTPUT);
	setOutputTimerByte(0b1);
	
}
Ejemplo n.º 3
0
void Device::setOnOff(const int _commandID) {

	commandID = _commandID;

	switch (type) {
	case TYPE_ARDUINO:
	case TYPE_DIGITAL_IO:
	case TYPE_DIGITAL_IO_NEG:
		if (commandID == COMMAND_ON) digitalWrite(getPin(), HIGH);
		if (commandID == COMMAND_OFF) digitalWrite(getPin(), LOW);
		status = digitalRead(getPin());
		break;
	case TYPE_ANALOG_IN:
	case TYPE_NTC:
		break;
	case TYPE_DHT22:
		break;
	case TYPE_THERMO_HEAT:
	case TYPE_THERMO_COOL:
		if (commandID == COMMAND_ON) status = STATUS_ON;
		if (commandID == COMMAND_OFF) status = STATUS_OFF;
		break;
	case TYPE_AUTO_DOOR:
		doorOnOff(deviceIdx, commandID);
		break;
	default:
		break;
	}
}
Ejemplo n.º 4
0
void Screen::mouseMoveEvent(QMouseEvent *event) {
	if (!m_moving && m_conns->mouseMoveEvent(event)) {
		ScreenObject *object = getObject(event->x(), event->y());
		if (!object) {
			return;
		}

		int pin = getPin(object, event->x(), event->y());
		if (pin == -1) {
			return;
		}

		Pin &p = object->getPins()[pin];
		QToolTip::showText(mapToGlobal(event->pos()), p.name);
		return;
	}

	if (event->buttons() & Qt::LeftButton) {
		if (m_moving) {
			m_moving->setX(NORM(m_moving->x() - (m_movingX - event->x())));
			m_moving->setY(NORM(m_moving->y() - (m_movingY - event->y())));
			m_conns->movePins(m_moving);
			resizeAccordingToObjects();
			repaint();
		}
		else {
			ScreenObject *object = getObject(event->x(), event->y());
			if (!object) {
				return;
			}

			int pin = getPin(object, event->x(), event->y());
			if (pin != -1) {
				return;
			}
			m_moving = object;
		}
		m_movingX = NORM(event->x());
		m_movingY = NORM(event->y());
	}
	else {
		if (m_moving) {
			m_conns->objectMoved(m_moving);
		}
		m_moving = 0;

		ScreenObject *object = getObject(event->x(), event->y());
		if (!object) {
			return;
		}

		int pin = getPin(object, event->x(), event->y());
		if (pin == -1) {
			return;
		}

		Pin &p = object->getPins()[pin];
		QToolTip::showText(mapToGlobal(event->pos()), p.name);
	}
}
Ejemplo n.º 5
0
ColorSelector::~ColorSelector()
{
  App::instance()->PaletteChange.disconnect(m_onPaletteChangeSlot);
  delete m_onPaletteChangeSlot;

  getPin()->getParent()->removeChild(getPin());
}
Ejemplo n.º 6
0
    //% help=pins/spi-pins weight=2 advanced=true
    //% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
    void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) {
        if (NULL != spi) {
            delete spi;
            spi = NULL;
        }

        spi = new SPI(getPin((int)mosi)->name, getPin((int)miso)->name, getPin((int)sck)->name);
    }
Ejemplo n.º 7
0
LedPin getLed(){
  if(getPin(LED_PORT, LED_GREEN))
    return GREEN;
  else if(getPin(LED_PORT, LED_RED))
    return RED;
  else
    return NONE;
}
ImperiumPulseCounter::ImperiumPulseCounter(int objectId, int* pins, int pinCount) : ImperiumObject(objectId, pins, pinCount){
	pinMode(getPin(0), INPUT);
	digitalWrite(getPin(0), HIGH);//pullup

	interruptNum = digitalPinToInterrupt(getPin(0));
	counterObjects[interruptNum] = this;
	count = 0;
	attachInterrupt(interruptNum, interruptHandlers[interruptNum], RISING);
}
Ejemplo n.º 9
0
char battery_status()
{
  char stat = 0;
  setIn(CHARGE_STATUS_PIN);
  setHigh(CHARGE_STATUS_PIN);
  _delay_ms(10);
  if(!getPin(CHARGE_STATUS_PIN)) stat = 1;
  setLow(CHARGE_STATUS_PIN);
  _delay_ms(10);
  if(getPin(CHARGE_STATUS_PIN)) stat = 2;
  return stat;
}
Ejemplo n.º 10
0
void Device::begin(const int _deviceID, const int _deviceIdx) {
/*!
*		Initializes a device. 
*/
	deviceID = _deviceID;
	deviceIdx = _deviceIdx;
	reportType = REPORT_NONE;
	checkType = CHECK_NONE;
	previousCommandValue = 0;
	previousStatus = STATUS_ERROR;

	switch (type) {
	case TYPE_ARDUINO:
		pinMode(getPin(), OUTPUT);
		readInput();
		break;
	case TYPE_DIGITAL_IO:
		pinMode(getPin(), OUTPUT);
		readInput();
		break;
	case TYPE_DIGITAL_IO_NEG:
		pinMode(getPin(), OUTPUT);
		digitalWrite(getPin(),HIGH);
		readInput();
		break;
	case TYPE_ANALOG_IN:
	case TYPE_NTC:
		readInput();
		break;
	case TYPE_DHT22:
		readInput();
		break;
	case TYPE_THERMO_HEAT:
	case TYPE_THERMO_COOL:
		pinMode(getPin(), OUTPUT);
		deviceCommandHandler(deviceIdx, COMMAND_ON, true);
		readInput();
		break;
	case TYPE_AUTO_DOOR:
		pinMode(POWER_RELAY_PIN, OUTPUT);
		pinMode(DIRECTION_RELAY_PIN, OUTPUT);

		pinMode(TOP_SWITCH_PIN, INPUT_PULLUP);
		//digitalWrite(TOP_SWITCH_PIN, HIGH); 	// connect internal pull-up

		pinMode(BOTTOM_SWITCH_PIN, INPUT_PULLUP);
		//digitalWrite(BOTTOM_SWITCH_PIN, HIGH); 	// connect internal pull-up
		readInput();
		break;
	}
}
Ejemplo n.º 11
0
int digitalRead(const char *pin) {
    const struct pin *p = getPin(pin, strlen(pin));

    if(checkPin(p, 0) == 0) {
        printf("Error: %s is not a digital pin\n", pin);
        return 0;
    }
    char buf[29];

    snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%i/value", p->gpio);


    FILE *file = fopen(buf, "r");

    char value = fgetc(file);

    fclose(file);

    if(value == '1') return 1;




    return 0;
}
Ejemplo n.º 12
0
    //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
    //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
    //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
    //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
    void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
        MicroBitPin* pin = getPin((int)name);
        if (!pin) return;

        pin->eventOn(MICROBIT_PIN_EVENT_ON_PULSE);
        registerWithDal((int)name, (int)pulse, body);
    }
Ejemplo n.º 13
0
bool pinDialog::doDialogInloop(pinOpInterface &operation,PinString &authPinCache) {
	for(;;) {
		byte retries = 0;
		try {
				PinString pin;
				if (authPinCache.empty()) {
					if (!doDialog())
						throw std::runtime_error("User cancelled");
					pin = getPin();
				} else
					pin = authPinCache;
				mutexObjLocker lock(operation.m_mutex);
				if (m_key == EstEidCard::AUTH)
					operation.m_card.validateAuthPin(pin,retries);
				else
					operation.m_card.validateSignPin(pin,retries);
				operation.call(operation.m_card,pin,m_key);
				authPinCache = pin;
				return true;
		} catch(AuthError &auth) {
			authPinCache.clear();
			if (auth.m_blocked) {
				showPrompt("Wrong pin entered, PIN is blocked");
				throw std::runtime_error("PIN is blocked");
				}
			std::stringstream buf;
			buf << "Wrong pin entered, " << (int)retries << " retries left";
			if (!showPrompt(buf.str(),true))
				throw std::runtime_error("User cancelled");
			}
		}
	}
Ejemplo n.º 14
0
void Screen::mousePressEvent(QMouseEvent *event) {
	if (m_conns->mousePressEvent(event)) {
		repaint();
		return;
	}

	if (event->button() == Qt::RightButton) {
		ScreenObject *object = getObject(event->x(), event->y());
		if (object) {
			int pin = getPin(object, event->x(), event->y());
			if (pin == -1) {
				showObjectMenu(object, event->globalPos());
			}
			else {
				showPinMenu(object, pin, event->globalPos());
			}
			
		}
		else {
			showScreenMenu(event->globalPos());
		}
	}
	else if (event->button() == Qt::LeftButton) {
		ScreenObject *object = getObject(event->x(), event->y());
		if (!object) {
			return;
		}

		if (object->clicked(event->pos()) && m_wrappers[object]) {
			m_wrappers[object]->reschedule();
		}
	}
}
void Client::setup()
{
    authenticated = false;
    error = false;

    buttonTimeout = new QTimer(this);
    connect(buttonTimeout,SIGNAL(timeout()),this,SLOT(exhibitNumberEntered()));
    buttonTimeout->setSingleShot(true);

//    lcd = new LcdController();
    mediaPlayer = new MediaPlayer();
    keypad = new KeypadController();

    // must register own types or Qt wont connect them properly
    qRegisterMetaType<KeypadButton>("KeypadButton");

    QObject::connect(this, SIGNAL(getPin()), keypad, SLOT(pinRequested()));
    QObject::connect(keypad, SIGNAL(forwardButton(KeypadButton)), this, SLOT(buttonPressed(KeypadButton)));
    QObject::connect(keypad, SIGNAL(forwardPincode(QString)), this, SLOT(pincodeReceived(QString)));

    // network lives in a thread so hook up signals
    network = new Network();
    QObject::connect(this, SIGNAL(request(QUrl, QString)), network, SLOT(getRequest(QUrl, QString)));
    QObject::connect(network, SIGNAL(forwardMessage(QString, unsigned int)), this, SLOT(networkReply(QString, unsigned int)));

    // setup location tracker thread
    tracker = new LocationTracker();
    QObject::connect(tracker, SIGNAL(forwardNewLocation(int)), this, SLOT(locationChanged(int)));
}
Ejemplo n.º 16
0
bool hasExpressionPedal(){
  /* clearPin(EXPRESSION_PEDAL_TIP_PORT, EXPRESSION_PEDAL_TIP_PIN); */
  configureDigitalInput(EXPRESSION_PEDAL_TIP_PORT, EXPRESSION_PEDAL_TIP_PIN, GPIO_PuPd_UP);
  bool connected = getPin(EXPRESSION_PEDAL_TIP_PORT, EXPRESSION_PEDAL_TIP_PIN);
  setupExpressionPedal();
  return connected;
}
Ejemplo n.º 17
0
void KSimIoJoin::setPin(const QString & deviceName, int pinID)
{
	KSimIoDevice * dev = KSimIoDeviceList::getList()->findByName(deviceName);
	if (dev)
	{
		const KSimIoPin * pin = dev->findPinByID(pinID);
		if (pin != (const KSimIoPin *)0)
		{
			if (pin != getPin())
			{
				setPin(pin);
			}
		}
		else
		{
			KSIMDEBUG(QString::fromLatin1("IO Pin not found (Device %1, Pin ID %2)")
			  .arg(deviceName).arg(pinID));
		}
	}
	else
	{
		KSIMDEBUG(QString::fromLatin1("IO Device not found (Device %1)")
		  .arg(deviceName));
		
	}

}
Ejemplo n.º 18
0
void pinDemo() {
    char buf[BUFSIZ];
    while (gets (buf)) {
       const struct pin *p = getPin(buf, strlen (buf));
       if(p) printf ("ID = %s\ngpio = %i\nmux = %s\neeprom = %i\npwm = %s\n", p->ID, p->gpio, p->mux, p->eeprom, p->pwm);
       else printf("nope\n");
    }
}
Ejemplo n.º 19
0
    //% help=input/on-pin-released weight=6 blockGap=8
    //% blockId=device_pin_released block="on pin %NAME|released"
    //% advanced=true
    void onPinReleased(TouchPin name, Action body) {
        auto pin = getPin((int)name);
        if (!pin) return;

        // Forces the PIN to switch to makey-makey style detection.
        pin->isTouched();
        registerWithDal((int)name, MICROBIT_BUTTON_EVT_UP, body);
    }
Ejemplo n.º 20
0
void CodecController::start(){
//   setPin(GPIOA, GPIO_Pin_7); // DEBUG
  setActive(true);
  if(isMaster()){
    /* The I2S peripheral must be enabled when the external master sets the WS line at: */
    if(getProtocol() == I2S_PROTOCOL_PHILIPS){
      while(getPin(CODEC_I2S_GPIO, CODEC_I2S_WS_PIN)); // wait for low
      /* High level when the I2S protocol is selected. */
      while(!getPin(CODEC_I2S_GPIO, CODEC_I2S_WS_PIN)); // wait for high
    }else{
      while(!getPin(CODEC_I2S_GPIO, CODEC_I2S_WS_PIN)); // wait for high
      /* Low level when the LSB or MSB-justified mode is selected. */
      while(getPin(CODEC_I2S_GPIO, CODEC_I2S_WS_PIN)); // wait for low
    }
  }
  I2S_Enable();
  I2S_Run();
}
Ejemplo n.º 21
0
void Servo::attachAndWrite(int value)
{
	if (!attached())
	{
		if (_pin != -1)
			attach(getPin());
	}
	write(value);
}
Ejemplo n.º 22
0
void pwmWrite(const char* pin, int frequency, int percent, int isrun) {
    const struct pin *p = getPin(pin, strlen(pin));

    if(checkPin(p, 3) == 0) {
        printf("Error: %s is not pwm capable\n", pin);
        return;
    }
    char pwm[26] = "/sys/class/pwm/";
    strcat(pwm, getPin(pin, strlen(pin))->pwm);

    char duty_percent[39] = "";
    strcat(duty_percent, pwm);
    strcat(duty_percent, "/duty_percent");

    char period_freq[38] = "";
    strcat(period_freq, pwm);
    strcat(period_freq, "/period_freq");

    char run[30] = "";
    strcat(run, pwm);
    strcat(run, "/run");

    FILE *file = fopen(period_freq, "w");
    fprintf(file,"%i", frequency);
    fclose(file);


    file = fopen(duty_percent, "w");
    fprintf(file, "%i", percent);
    fclose(file);


    if(isrun == 1) {
    	file = fopen(run, "w");
    	fputs("1", file);
    	fclose(file);
    } else {
    	file = fopen(run, "w");
    	fputs("0", file);
    	fclose(file);
    }


}
Ejemplo n.º 23
0
void KSimIoJoinBoolIn::calculate() const
{
	KSimIoJoin::calculate();
	
	bool value;

	getDevice()->getIO(getPin()->getPinID(), &value);

	((ConnectorBoolOut *)getConnector())->setOutput(value);
}
Ejemplo n.º 24
0
QSqlQuery dbConnection::dbInsert(){
    QSqlQuery dbInsert(connectDb());
    dbInsert.prepare("INSERT INTO Kontak(Nama, Pin, Jenis_Kelamin) VALUES (:Nama, :Pin, :Jenis_Kelamin)");
    dbInsert.bindValue(":Nama", getNama());
    dbInsert.bindValue(":Pin", getPin());
    dbInsert.bindValue(":Jenis_Kelamin", getKelamin());
    dbInsert.exec();
    connectDb().close();
    return dbInsert;
}
Ejemplo n.º 25
0
void muxPin(const char* pin, int mode) {
    const struct pin *p = getPin(pin, strlen(pin));

    if(checkPin(p, 0) == 0) {
        printf("Error: pin %s cannot be muxed\n", pin);
        return;
    }
    char buf[44];

    snprintf(buf, sizeof(buf), "/sys/kernel/debug/omap_mux/%s", getPin(pin, strlen(pin))->mux);
    FILE *file = fopen(buf, "w");


    fprintf(file, "%x", mode);



    fclose(file);
}
Ejemplo n.º 26
0
unsigned char SendSPI(unsigned char data)
{
	byte retval = 0;
	byte intData = data;
	int t;

	for (int ctr = 0; ctr < 7; ctr++)
	{
		if (intData & 0x80) setPin(MOSI_8051, HIGH);
		else setPin(MOSI_8051, LOW);

		setPin(CLK_8051, HIGH);
		Sleep(1);

		t = getPin(MISO_8051);
		setPin(CLK_8051, LOW);

		if (t) retval |= 1; else retval &= 0xFE;
		retval <<= 1;
		intData <<= 1;
		Sleep(1);
	}


	if (intData & 0x80) setPin(MOSI_8051, HIGH);
	else setPin(MOSI_8051, LOW);

	setPin(CLK_8051, HIGH);
	Sleep(1);

	t = getPin(MISO_8051);
	setPin(CLK_8051, LOW);

	if (t) retval |= 1;
	else retval &= 0xFE;

	return retval;
}
Ejemplo n.º 27
0
void unexportGpio(const char *pin) {
    const struct pin *p = getPin(pin, strlen(pin));

    if(checkPin(p, 0) == 0) {
        printf("Error: %s is not a gpio pin\n", pin);
        return;
    }
    FILE *file = fopen("/sys/class/gpio/unexport", "w");
    char num[3];
    snprintf(num, sizeof(num), "%i", p->gpio);

    fputs(num, file);

    fclose(file);
}
Ejemplo n.º 28
0
    void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
    {
        if (recordNextFrameTime)
        {
            const double defaultCameraLatency = 0.1;

            firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
            recordNextFrameTime = false;

            ComSmartPtr<IPin> pin;
            if (getPin (filter, PINDIR_OUTPUT, pin))
            {
                ComSmartPtr<IAMPushSource> pushSource;
                HRESULT hr = pin.QueryInterface (pushSource);

                if (pushSource != nullptr)
                {
                    REFERENCE_TIME latency = 0;
                    hr = pushSource->GetLatency (&latency);

                    firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
                }
            }
        }

        {
            const int lineStride = width * 3;
            const ScopedLock sl (imageSwapLock);

            {
                loadingImage.duplicateIfShared();
                const Image::BitmapData destData (loadingImage, 0, 0, width, height, Image::BitmapData::writeOnly);

                for (int i = 0; i < height; ++i)
                    memcpy (destData.getLinePointer ((height - 1) - i),
                            buffer + lineStride * i,
                            lineStride);
            }

            imageNeedsFlipping = true;
        }

        if (listeners.size() > 0)
            callListeners (loadingImage);

        sendChangeMessage();
    }
Ejemplo n.º 29
0
void digitalWrite(const char *pin, int value) {
    const struct pin *p = getPin(pin, strlen(pin));

    if(checkPin(p, 0) == 0) {
        printf("Error: %s is not a digital pin\n", pin);
        return;
    }

    char buf[29];
    snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%i/value", p->gpio);

    FILE *file = fopen(buf, "w");

    if(value) fputc('1', file);
    else      fputc('0', file);

    fclose(file);

}
Ejemplo n.º 30
0
    //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
    //% weight=20 advanced=true
    //% help=pins/pulse-in
    //% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
    //% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
    int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {
        MicroBitPin* pin = getPin((int)name);
        if (!pin) return 0;

        int pulse = value == PulseValue::High ? 1 : 0;
        uint64_t tick =  system_timer_current_time_us();
        uint64_t maxd = (uint64_t)maxDuration;
        while(pin->getDigitalValue() != pulse) {
            if(system_timer_current_time_us() - tick > maxd)
                return 0;
        }

        uint64_t start =  system_timer_current_time_us();
        while(pin->getDigitalValue() == pulse) {
            if(system_timer_current_time_us() - tick > maxd)
                return 0;
        }
        uint64_t end =  system_timer_current_time_us();
        return end - start;
    }