コード例 #1
0
ファイル: firenest.cpp プロジェクト: davidlgj/firecrow
    //discover target node
    void discover() {
      //mySerial.println("discover");
      //if we don't get a address we can't fire
      while (true) {
        //send node discovery
        xbee.send(atRequest);
        
        //default value is that responding XBEE can wait up to six seconds before answering
        //so spamming it with node discoverys might be a bad thing, but waiting so long is booring so
        //we we'll try it and see if it works...
        
        //knight rider on the diodes let's the users know we're looking
        for (int i=0; i<CHANNELS; i++) {
          clearLeds();
          digitalWrite(channels[i % CHANNELS].led_pin,HIGH);

          if (checkNDResponse()) {
            return;
          }      
        }

        for (int i=CHANNELS-1; i>=0; i--) {
          clearLeds();
          digitalWrite(channels[i % CHANNELS].led_pin,HIGH);

          if (checkNDResponse()) {
            return;
          }      
        }
      }
    }
コード例 #2
0
/**
Configures hardware for the particular hardware platform:
- Ports: sets direction, interrupts, pullup/pulldown resistors etc.
- Holds radio in reset (active-low)
*/
void halInit()
{
    //
    // Enable the floating-point unit.
    //
    FPUEnable();
    //
    // Configure the floating-point unit to perform lazy stacking of the
    // floating-point state.
    //
    FPULazyStackingEnable();

	oscInit();
	portInit();
	halUartInit();

    //Point the function pointers to doNothing() so that they don't trigger a restart
    debugConsoleIsr = &doNothing;
    buttonIsr = &doNothing;
    clearLeds();
    displayVersion();
#ifdef AF_VERBOSE
        printf("* AF_VERBOSE *\r\n");
#endif
}
コード例 #3
0
int main(void) 
{
    //-----------INITS------------//
	DDRB = (1 << PB2) | (1 << PB5) | (1 << PB3);

	//Setup SPI
    SPCR |= (1 << SPE) | (1 << MSTR);
    SPSR |= (1 << SPI2X);

	PORTB = 0x00;

	clearLeds();



    //-------EVENT LOOP-----------//
    while(1) 
    {
		for (int i=0; i<3; i++)
		{
			clearLeds();
			for (int j=0; j<8; j++)
			{
				leds[j][i] = 0x0F;
			} 
			updateLeds();
			if (i == 0)
				_delay_ms(2000);
			else 
				_delay_ms(1000);
		}
	
		for (int i=0; i<8; i++)
		{
			clearLeds();
			leds[i][RED] = 0x0F;
			leds[i][GREEN] = 0x0F;
			leds[i][BLUE] = 0x0F;
			updateLeds();
			_delay_ms(500);
		}


    }
    return(0);

}
コード例 #4
0
ファイル: firenest.cpp プロジェクト: davidlgj/firecrow
 //flash leds once, variable time
 void flashAll(int ms) {
   for (int i=0;i<CHANNELS; i++) {
     digitalWrite(channels[i].led_pin,HIGH);
   }
   
   delay(ms);
   clearLeds();  
 }
コード例 #5
0
void EffectFindMe::step(Config_t *_cnf, CRGB* _leds, CRGB* _ledsrow) {
  clearLeds(_leds, NUM_LEDS);
  for(uint8_t i=0; i<NUM_ROWS; i++) {
    for(uint8_t j=0; j<FINDME_WIDTH; j++) {
      _leds[getLedIndex(i,_cnf->currFrame+j)] = _currColor;  // for police blue-red pattern use CRGB(255,0,0)
      _leds[getLedIndex(i,_cnf->currFrame+NUM_LEDSPERHALFROW+j)] = _currColor;  // and CRGB(0,0,255)
    }
  }
}
void displayMessages()
{
    spiPoll();
    if (znpBuf[SRSP_LENGTH_FIELD] > 0)
    {
        if (IS_AF_INCOMING_MESSAGE())
        {
            setLed(1);  //LED will blink to indicate a message was received
#ifdef VERBOSE_MESSAGE_DISPLAY               
            printAfIncomingMsgHeader(znpBuf);
            printf("\r\n");
#endif
            if (IS_INFO_MESSAGE_CLUSTER())
            {
                struct infoMessage im = deserializeInfoMessage(znpBuf+20);
                
#ifdef VERBOSE_MESSAGE_DISPLAY                
                printInfoMessage(&im);
#else
                printf("From:");
                for (int j = 0; j<8; j++)
                {
                    printf("%02X", im.header->mac[j]);
                }
                printf(",LQI=%02X", znpBuf[SRSP_HEADER_SIZE+9]);
#endif

                if (im.numParameters > 0)
                {
                    printf(";PanID:%04X", im.parameters[0]);
                    if (im.numParameters == 3)   //panId, vcc3v, light sensor (lux/10)
                    {
                        printf(",Vcc3=%umV,Light Sensor(lux)=%u,Cause=", im.parameters[1], im.parameters[2] * 10); 
                        switch (im.cause)
                        {
                        case CAUSE_SCHEDULED: printf("Timer"); break;
                        case CAUSE_MOTION: printf("Motion"); break;
                        case CAUSE_STARTUP: printf("Startup"); break;
                        }
                    }
                    printf("\r\n");
                }
            } else {
                printf("Rx: ");
                printHexBytes(znpBuf+SRSP_HEADER_SIZE+17, znpBuf[SRSP_HEADER_SIZE+16]);   //print out message payload
            }
            clearLeds();    
        } else { //unknown message, just print out the whole thing
            printf("??: ");
            printHexBytes(znpBuf, (znpBuf[SRSP_LENGTH_FIELD] + SRSP_HEADER_SIZE));
        }             
        znpBuf[SRSP_LENGTH_FIELD] = 0;
    } 
}
コード例 #7
0
/** Use this to verify that you've configured halInit(), toggleLed() and delayMs() correctly. 
Monitor LED with oscilloscope or logic analyzer to verify that delay is equal to ~50mSec. */
int main( void )
{
    halInit();
    while (1) 
    { 
        setLed(0);
        delayMs(50);
        clearLeds();
        delayMs(50);
    }
}
int main( void )
{
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;
    sysTickIsr = &sysTick;    
    printf("\r\n****************************************************\r\n");
    printf("Config Application Example - COORDINATOR\r\n");    
    clearLeds();    
    halRgbLedPwmInit();
    initSysTick();
    HAL_ENABLE_INTERRUPTS(); //NEW
    stateMachine();    //run the state machine
}
コード例 #9
0
int main( void )
{
    halInit();
    moduleInit();
    printf("\r\n****************************************************\r\n");    
    printf("Zigbee Network Explorer\r\n");
    debugConsoleIsr = &handleDebugConsoleInterrupt;
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    /* Now the network is running - wait for any received messages from the ZM */
#ifdef VERBOSE_MESSAGE_DISPLAY    
    printAfIncomingMsgHeaderNames();
#endif
    
    stateMachine();
}
int main( void )
{
    structInit();
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;    
    printf("\r\n****************************************************\r\n");
    printf("Simple Application Example - COORDINATOR\r\n");
    
    routers[0].MAC_address[0] = 0x5E;
    routers[0].MAC_address[1] = 0xD2;
    routers[0].MAC_address[2] = 0x5D;
    routers[0].MAC_address[3] = 0x02;
    routers[0].MAC_address[4] = 0x00;
    routers[0].MAC_address[5] = 0x4B;
    routers[0].MAC_address[6] = 0x12;
    routers[0].MAC_address[7] = 0x00;
    
    routers[1].MAC_address[0] = 0xD3;
    routers[1].MAC_address[1] = 0xD3;
    routers[1].MAC_address[2] = 0x5D;
    routers[1].MAC_address[3] = 0x02;
    routers[1].MAC_address[4] = 0x00;
    routers[1].MAC_address[5] = 0x4B;
    routers[1].MAC_address[6] = 0x12;
    routers[1].MAC_address[7] = 0x00;
    
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    halRgbLedPwmInit();
    
    while (1) {
        stateMachine();    //run the state machine
        if (alarm_sounding == 1 && !alarm_silenced) {
          delayMs(2);
          toggleLed(0);
        }
    }
}
コード例 #11
0
int main( void )
{
    halInit();
    moduleInit();    
    HAL_DISABLE_INTERRUPTS();
    printf("\r\n****************************************************\r\n");    
    printf("Simple Application Example - END DEVICE\r\n");  
    uint16_t vlo = calibrateVlo();
    printf("VLO = %u Hz\r\n", vlo);   
    timerIsr = &handleTimer;  
    clearLeds();
    HAL_ENABLE_INTERRUPTS();
    
    /* Most of the of infoMessage are the same, so we can create most of the message ahead of time. */
    hdr.sequence = 0;  //this will be incremented each message
    hdr.version = INFO_MESSAGE_VERSION;
    hdr.flags = INFO_MESSAGE_FLAGS_NONE;
    
    initializeSensors();
    delayMs(100);
    stateMachine();
}
/** Parse any received messages. If it's one of our OIDs then display the value on the RGB LED too. */
void parseMessages()
{
    getMessage();
    if ((zmBuf[SRSP_LENGTH_FIELD] > 0) && (IS_AF_INCOMING_MESSAGE()))
    {
        setLed(4);                                  //LED will blink to indicate a message was received
#ifdef VERBOSE_MESSAGE_DISPLAY
        printAfIncomingMsgHeader(zmBuf);
        printf("\r\n");
#endif
        if ((AF_INCOMING_MESSAGE_CLUSTER()) == INFO_MESSAGE_CLUSTER)
        {
            struct infoMessage im;
            deserializeInfoMessage(zmBuf+20, &im);  // Convert the bytes into a Message struct
            int j = 0;
#ifdef VERBOSE_MESSAGE_DISPLAY                
            printInfoMessage(&im);
            displayZmBuf();
#else
            printf("From:");                        // Display the sender's MAC address
            for (j = 7; j>(-1); j--)
            {
                printf("%02X", im.header.mac[j]);
            }
            int k;
            for (k = 0; k < NUM_DEVICES; k++) {
              int match = 1;
              for (j = 7; j>(-1); j--) {
                if (routers[k].MAC_address[j] != im.header.mac[j]) {
                  match = 0;
                }
              }
              if (match == 1) {
                current_router_index = k;
                routers[current_router_index].LQI = zmBuf[AF_INCOMING_MESSAGE_LQI_FIELD];
              }
            }
            
            printf(", LQI=%02X, ", zmBuf[AF_INCOMING_MESSAGE_LQI_FIELD]);   // Display the received signal quality (Link Quality Indicator)
            //LQI = zmBuf[AF_INCOMING_MESSAGE_LQI_FIELD];

#endif
            printf("%u KVPs received:\r\n", im.numParameters);
#define NO_VALUE_RECEIVED   0xFF
            uint8_t redIndex = NO_VALUE_RECEIVED; 
            uint8_t blueIndex = NO_VALUE_RECEIVED;
            uint8_t greenIndex = NO_VALUE_RECEIVED;
            for (j=0; j<im.numParameters; j++)                              // Iterate through all the received KVPs
            {
                printf("    %s (0x%02X) = %d  ", getOidName(im.kvps[j].oid), im.kvps[j].oid, im.kvps[j].value);    // Display the Key & Value
                displayFormattedOidValue(im.kvps[j].oid, im.kvps[j].value);
                printf("\r\n");
                // If the received OID was an IR temperature OID then we can just display it on the LED
                if ((rgbLedDisplayMode == RGB_LED_DISPLAY_MODE_TEMP_IR) && (im.kvps[j].oid == OID_TEMPERATURE_IR)) 
                    displayTemperatureOnRgbLed(im.kvps[j].value);
                // But for the color sensor we need to get all three values before displaying
                else if (im.kvps[j].oid == OID_COLOR_SENSOR_RED)
                    redIndex = j;
                else if (im.kvps[j].oid == OID_COLOR_SENSOR_BLUE)
                    blueIndex = j;
                else if (im.kvps[j].oid == OID_COLOR_SENSOR_GREEN)
                    greenIndex = j;
            }
            // Now done iterating through all KVPs. If we received color then update RGB LED
#define RED_VALUE   (im.kvps[redIndex].value)
#define BLUE_VALUE  (im.kvps[blueIndex].value)
#define GREEN_VALUE (im.kvps[greenIndex].value)
            
            if ((rgbLedDisplayMode == RGB_LED_DISPLAY_MODE_COLOR) && 
                ((redIndex != NO_VALUE_RECEIVED) && (blueIndex != NO_VALUE_RECEIVED) && (greenIndex != NO_VALUE_RECEIVED)))
            {
                displayColorOnRgbLed(RED_VALUE, BLUE_VALUE, GREEN_VALUE);
            }
            printf("\r\n");
            
        } else {
            printf("Rx: ");
            printHexBytes(zmBuf+SRSP_HEADER_SIZE+17, zmBuf[SRSP_HEADER_SIZE+16]);   //print out message payload
        }
        clearLeds(0);    
    } else if (IS_ZDO_END_DEVICE_ANNCE_IND()) {
        displayZdoEndDeviceAnnounce(zmBuf);
    } else { //unknown message, just print out the whole thing
        printf("MSG: ");
        printHexBytes(zmBuf, (zmBuf[SRSP_LENGTH_FIELD] + SRSP_HEADER_SIZE));
    }
    zmBuf[SRSP_LENGTH_FIELD] = 0;
}
void stateMachine()
{
    while (1)
    {
        switch (state)
        {
        case STATE_IDLE:
            {
                if (stateFlags & STATE_FLAG_SEND_INFO_MESSAGE)  //if there is a pending info message to be sent
                {
                    state = STATE_SEND_INFO_MESSAGE;            //then send the message and clear the flag
                    stateFlags &= ~STATE_FLAG_SEND_INFO_MESSAGE;
                }
                //note: other flags (for different messages or events) can be added here
                break;
            }
            
        case STATE_ZNP_STARTUP:
            {
#define ZNP_START_DELAY_IF_FAIL_MS 5000
                /* Start the network; if fails then wait a second and try again. */
                signed int startResult = startZnp(END_DEVICE);
                while (startResult != ZNP_SUCCESS)
                {
                    printf("FAILED. Error Code %i, ZNP Result %i. Retrying...\r\n", startResult, znpResult);
                    delayMs(ZNP_START_DELAY_IF_FAIL_MS);
                    startResult = startZnp(END_DEVICE);
                }
                printf("Success\r\n"); 
                
                //ZNP Initialized so store MAC Address
                memcpy(hdr.mac, getMacAddress(), 8); 
#ifdef SEND_MESSAGE_ON_TIMER
                signed int timerResult = initTimer(4, WAKEUP_AFTER_TIMER);
                if (timerResult != 0)
                {
                    printf("timerResult Error %i, STOPPING\r\n", timerResult);
                    while (1);   
                }
#endif
                state = STATE_DISPLAY_NETWORK_INFORMATION;
                break;
            }
        case STATE_DISPLAY_NETWORK_INFORMATION:
            {
                printf("~ni~");
                /* On network, display info about this network */              
                getNetworkConfigurationParameters();                
                getDeviceInformation();    
                state = STATE_SEND_INFO_MESSAGE;
                break;   
            }
        case STATE_SEND_INFO_MESSAGE:
            {
                printf("~im~");
                setLed(1);
                im.header->sequence = sequenceNumber++;                
                im.cause = infoMessageCause;
                unsigned char* panid = getDeviceInformationProperty(DIP_PANID);
                im.parameters[0] = CONVERT_TO_INT(*panid, *(panid+1));      //PAN ID
                im.parameters[1] = getVcc3();                               //VCC
                im.parameters[2] = getLightSensor();                        //Light Sensor
                printInfoMessage(&im);
#define ZNP_RESTART_DELAY_IF_MESSAGE_FAIL_MS 5000
                unsigned char msgBuf[100];
                serializeInfoMessage(&im, msgBuf);
                afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, INFO_MESSAGE_CLUSTER, msgBuf, getSizeOfInfoMessage(&im));
                if (znpResult != ZNP_SUCCESS)
                {
                    printf("afSendData error %i; restarting...\r\n", znpResult);
                    delayMs(ZNP_RESTART_DELAY_IF_MESSAGE_FAIL_MS);  //allow enough time for coordinator to fully restart, if that caused our problem
                    state = STATE_ZNP_STARTUP;
                } else {      
                    state = STATE_IDLE;
                    clearLeds();        
                    HAL_SLEEP();                    
                }
                break;   
            }
        default:     //should never happen
            {
                printf("UNKNOWN STATE\r\n");
                state = STATE_ZNP_STARTUP;
            }
            break;
        }
    } 
}