void updateOccupancyStatus(){ static uint8 index ; if( io[index].newState != io[index].oldState ) { LN_STATUS status ; uint8 type = io[index].type ; uint8 address = io[index].address ; uint8 state = io[index].newState ; if( type == ACCESSORY ){status = LocoNet.requestSwitch( address, 1, state ) ; status = LocoNet.requestSwitch( address, 0, state ) ; } else {status = LocoNet.reportSensor( address, state ) ; } //status = LocoNet.reportSensor( address, state ) ; } if( status == LN_DONE ) // if message has transmitted succesfully... { io[index].oldState = io[index].newState ; // ...update status if( ++ index == nInputs ) index = 0 ; // and go to next object } } else { if( ++ index == nInputs ) index = 0 ; // if object's state has not changed, go to next object. }}
Nu zijn 5 x 16 melders die in dezelfde milliseconde (en misschien wel microseconde, het begin althans) verstuurd moeten worden ook wel erg uitzonderlijk.
Je maakt mooi spul Bas maar dat plakband vind ik persoonlijk een beetje jammer voor de uitstraling.
Daar is het voorgeschreven dat als een node een collision detecteert, dat hij een random tijd moet wachten voor hij het opnieuw gaat proberen
void updateOccupancyStatus(){ static uint32 interval = 1 ; // default interval of 1ms REPEAT_MS( interval ) // best macro ever, creates an interval { static uint8 index ; if( io[index].newState != io[index].oldState ) { LN_STATUS status ; uint8 type = io[index].type ; uint8 address = io[index].address ; uint8 state = io[index].newState ; if( type == ACCESSORY ){status = LocoNet.requestSwitch( address, 1, state ) ; status = LocoNet.requestSwitch( address, 0, state ) ; } else {status = LocoNet.reportSensor( address, state ) ; } //status = LocoNet.reportSensor( address, state ) ; } if( status == LN_DONE ) { io[index].oldState = io[index].newState ; if( ++ index == nInputs ) index = 0 ; interval = 1; // if status is OK, maintain 1ms interval } else { interval = random( 5, 50 ) ; // in event of collission, wait with random interval } } else { if( ++ index == nInputs ) index = 0 ; } } END_REPEAT}
Het start adres kan je in arduino's randomSeed() functie proppen.
void setup(){ LocoNet.init(LNtxPin) ; loadEEPROM() ; randomSeed( io[0].address ) ; // <--- startupDelay = random( 1, 1000 ) ; // <--- for( int i = 0 ; i < nInputs ; i ++ ) input[i].begin() ; pinMode(13, OUTPUT) ;}void loop(){ waitStartDelay : if( millis() <= startupDelay ) goto waitStartDelay ; // <---
#define startupDelay( interval ) PIGS_CAN_FLY: if( millis() <= interval ) goto PIGS_CAN_FLY;
Code: [Selecteer] waitStartDelay : if( millis() <= startupDelay ) goto waitStartDelay ; // <--- Ik moet hier een macro voor maken voor in m'n macros.h
waitStartDelay : if( millis() <= startupDelay ) goto waitStartDelay ; // <---
while( millis() <= startupDelay ){}