Beispiel #1
0
    virtual void loop() {
        if(!active()) return;

        if(interruptPending_) {
            interruptPending_ = false;
            uint8_t n = mcp_.getInterruptPinValuesA();
            if(st_.active() && 
                ( !bitRead(n,PIN_FRAME_STOP) ||
                    !bitRead(n,PIN_STEP_STOP1) ||
                    !bitRead(n,PIN_STEP_STOP2)))
                st_.stop();
            if(fan_.tachoActive() && !bitRead(n,PIN_FAN_TACHO))
                fan_.tachoCount();
        }
        if(buttonPending_) {
            buttonPending_ = false;
            button_ &= mcp_.getInterruptPinValuesB();
        }

        sv_.loop();
        st_.loop();
        fan_.loop();
        led_.loop();
        tmp_.loop();
    }
Beispiel #2
0
void Sensor::initSensors() {
	sensGPIO.begin(1);
	
	//Address pins
	sensGPIO.pinMode(FRPIN, OUTPUT);
	sensGPIO.pinMode(LTRPIN, OUTPUT);
	sensGPIO.pinMode(LTLPIN, OUTPUT);
	sensGPIO.pinMode(FLPIN, OUTPUT);
	sensGPIO.pinMode(MRPIN, OUTPUT);
	sensGPIO.pinMode(MLPIN, OUTPUT);
	sensGPIO.pinMode(BRPIN, OUTPUT);
	sensGPIO.pinMode(BLPIN, OUTPUT);

	//-------Set all sensor select pins to high---------------
	sensGPIO.writeGPIOA(0xFF);

	//Ultrasonic pins
	pinMode(A0, OUTPUT);
	pinMode(A1, INPUT);
	
	 for (byte i = sC::FR; i < sC::invalid; i++) {
		SelectSensor(i);
		tsl.begin(TSL2561_ADDR_0);
		tsl.setTiming(TSL2561_GAIN_16X, TSL2561_INTEGRATIONTIME_14MS);
		tsl.setPowerUp();
	}
	 
	delay(14);
	_sensorInitComplete = true;
}
Beispiel #3
0
 static void stepperInterrupt(bool on) {
     if(on) {
         mcp_.setupInterruptPin(PIN_FRAME_STOP,CHANGE);
         mcp_.setupInterruptPin(PIN_STEP_STOP1,CHANGE);
         mcp_.setupInterruptPin(PIN_STEP_STOP2,CHANGE);
         if(fan_.tachoActive()) {
             mcp_.setupInterruptPin(PIN_FAN_TACHO,LOW);
             mcp_.pullUp(PIN_FAN_TACHO,LOW);
         }
     }else{
         mcp_.setupInterruptPin(PIN_FRAME_STOP,LOW);
         mcp_.setupInterruptPin(PIN_STEP_STOP1,LOW);
         mcp_.setupInterruptPin(PIN_STEP_STOP2,LOW);
         if(fan_.tachoActive()){
             mcp_.setupInterruptPin(PIN_FAN_TACHO,CHANGE);
             mcp_.pullUp(PIN_FAN_TACHO,HIGH);
         }
     }
 }
Beispiel #4
0
//Switches the I2C address of the desired sensor and removes others
void Sensor::SelectSensor(byte sensorNumber) {
	if (sensorNumber == sC::FR) { sensGPIO.writeGPIOA(0x7F); SEN_PRINTLN("FR Selected"); }
	else if (sensorNumber == sC::LTR) { sensGPIO.writeGPIOA(0xBF); SEN_PRINTLN("LTR Selected"); }
	else if (sensorNumber == sC::LTL) { sensGPIO.writeGPIOA(0xDF); SEN_PRINTLN("LTL Selected"); }
	else if (sensorNumber == sC::FL) { sensGPIO.writeGPIOA(0xEF); SEN_PRINTLN("FL Selected"); }
	else if (sensorNumber == sC::MR) { sensGPIO.writeGPIOA(0xF7); SEN_PRINTLN("MR Selected"); }
	else if (sensorNumber == sC::ML) { sensGPIO.writeGPIOA(0xFB); SEN_PRINTLN("ML Selected"); }
	else if (sensorNumber == sC::BR) { sensGPIO.writeGPIOA(0xFD); SEN_PRINTLN("BR Selected"); }
	else if (sensorNumber == sC::BL) { sensGPIO.writeGPIOA(0xFE); SEN_PRINTLN("BL Selected"); }
	else {
		ERROR_PRINTLN("Sensor Select Error");
		ERROR_PRINTLN("All address lines returned to default");
		sensGPIO.writeGPIOA(0xFF);
	}
}
Beispiel #5
0
    static void ioSetup() {
        digitalWrite(PIN_IO_RST,LOW);
        delay(100);
        digitalWrite(PIN_IO_RST,HIGH);
        delay(100);

        mcp_.begin(IO_ADDR);
        mcp_.pinMode(PIN_EP_EN,OUTPUT);
        mcp_.pinMode(PIN_LED_EN,OUTPUT);
        mcp_.pinMode(PIN_SRV_EN,OUTPUT);
        mcp_.pinMode(PIN_FAN_EN,OUTPUT);
        mcp_.pinMode(PIN_FAN_TACHO,INPUT);
        mcp_.pinMode(PIN_HOST_INT,OUTPUT);
        mcp_.pinMode(PIN_STEP_SLP,OUTPUT);

        mcp_.pullUp(PIN_FRAME_STOP,HIGH);
        mcp_.pullUp(PIN_STEP_STOP1,HIGH);
        mcp_.pullUp(PIN_STEP_STOP2,HIGH);
        mcp_.pullUp(PIN_BTN11,HIGH);
        mcp_.pullUp(PIN_BTN12,HIGH);
        mcp_.pullUp(PIN_BTN13,HIGH);
        mcp_.pullUp(PIN_BTN21,HIGH);
        mcp_.pullUp(PIN_BTN22,HIGH);
        mcp_.pullUp(PIN_BTN23,HIGH);
        mcp_.setupInterruptPin(PIN_BTN11,CHANGE);
        mcp_.setupInterruptPin(PIN_BTN12,CHANGE);
        mcp_.setupInterruptPin(PIN_BTN13,CHANGE);
        mcp_.setupInterruptPin(PIN_BTN21,CHANGE);
        mcp_.setupInterruptPin(PIN_BTN22,CHANGE);
        mcp_.setupInterruptPin(PIN_BTN23,CHANGE);
        mcp_.setupInterrupts(false,false,LOW);

        if(st_.active())
            stepperInterrupt(true);
        if(fan_.tachoActive())
            fanInterrupt(true);
    }
Beispiel #6
0
 static void powerSetup(byte pin, byte value) {
     mcp_.digitalWrite(pin,value?HIGH:LOW);
 }
Beispiel #7
0
 static void fanInterrupt(bool on) {
     if(!on || !st_.active()) {
         mcp_.pullUp(PIN_FAN_TACHO,on?HIGH:LOW);
         mcp_.setupInterruptPin(PIN_FAN_TACHO,on?CHANGE:LOW);
     }
 }