Пример #1
0
    virtual void setup() {
        if(!active()) return;

        pinMode(PIN_IO_RST,OUTPUT);
        ioSetup();
        addBitlashFunction("io", ioCmd);

        sv_.setup();
        addBitlashFunction("sv", svCmd);

        st_.setup();
        addBitlashFunction("st", stCmd);

        fan_.setup();
        addBitlashFunction("fan", fanCmd);

        led_.setup();
        addBitlashFunction("led", ledCmd);

        tmp_.setup();
        addBitlashFunction("tmp", tmpCmd);

        attachInterrupt(0,Body::onInterrupt,FALLING);
        attachInterrupt(1,Body::onButton,FALLING);
    }
Пример #2
0
    static numvar ioCmd() {
        byte n = getarg(0);
        if(!n) {
            ioSetup();
        }else if(n==1) {
            switch(getarg(1)) {
            case 0:
                n = Body::mcp_.readGPIO(0);
#define PRINT_BIT(_b) (n&(1<<_b))?spb('1'):spb('0')
                PRINT_BIT(PIN_FRAME_STOP);
                PRINT_BIT(PIN_STEP_STOP1);
                PRINT_BIT(PIN_STEP_STOP2);
                speol();
                break;
            case 1:
                n = Body::mcp_.readGPIO(1);
                printHex(n);
                speol();
                break;
            case 2:
                printHex(button_);
                speol();
                button_ = 0xff;
                break;
            }
        }else{
            switch(getarg(1)) {
            case 0:
                powerSetup(PIN_EP_EN,getarg(2));
                break;
            }
        }
        return 0;
    }
Пример #3
0
/**
 * @brief Configura todo o sistema
 */
void configSystem(void)
{
	// Configure USART
	usartSetup();

	// Configure CAN
	canSetup();

	// Configure inputs and outputs
	ioSetup();

	// Enable global interrupts
	//sei();
}
Пример #4
0
int main(void) {
	clockSetup();
	ioSetup();
	adcSetup();

	while (1) {
		adcSample();
		avg_adc = ((adc[0]+adc[1]+adc[2]+adc[3]+adc[4]+adc[5]+adc[6]+adc[7]+adc[8]+adc[9]) / 10);;
		findClosest();
		if (distance < 20) {
			if (alarm_state == STATE_DISARMED) state = 0;
			else {
				if (state == 0) {
					alarm_state = STATE_ALERT;
					memset(txString, 0, 80);
					sprintf(txString, "%s%sSystem Status: %s", clear_screen, line_1, ALERT);
					i = 0;
					state = STATE_CHANGE;
					UC0IE |= UCA0TXIE; // Enable USCI_A0 TX interrupt
					UCA0TXBUF = txString[i++];
				}
				P2OUT |= ALERTLED;
				P2OUT &= ~(SAFELED + WARNLED);
				change_lights = 1;
			}

		} else if (change_lights == 1) {
			if (alarm_state == STATE_ARMED) {
				P2OUT |= SAFELED;
				P2OUT &= ~(ALERTLED + WARNLED);
			} else if (alarm_state == STATE_DISARMED) {
				P2OUT |= WARNLED;
				P2OUT &= ~(ALERTLED + SAFELED);
			}
		}
	}
}