Skip to content

Commit

Permalink
wait min 100ms between 2 send operations
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed May 5, 2017
1 parent eec6b1a commit 7632eac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AlarmClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace as {

#define TICKS_PER_SECOND 10UL
#define TICKS_PER_SECOND 100UL

#define seconds2ticks(tm) ( tm * TICKS_PER_SECOND )
#define ticks2seconds(tm) ( tm / TICKS_PER_SECOND )
Expand Down
1 change: 0 additions & 1 deletion MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class MultiChannelDevice : public Device<HalType> {
for( uint8_t i=1; i<=channels(); ++i ) {
ChannelType& ch = channel(i);
if( ch.changed() == true ) {
_delay_ms(100); // TODO use STATUSINFO_MINDELAY
DeviceType::sendInfoActuatorStatus(DeviceType::getMasterID(),DeviceType::nextcount(),ch);
worked = true;
}
Expand Down
23 changes: 23 additions & 0 deletions Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _CC_H

#include "Message.h"
#include "AlarmClock.h"

#ifdef ARDUINO_ARCH_AVR
#include <util/delay.h>
Expand Down Expand Up @@ -333,6 +334,26 @@ class Radio {
((Radio<SPIType,GDO0>*)instance)->handleInt();
}

class MinSendTimeout : public Alarm {
volatile bool wait;
public:
MinSendTimeout () : Alarm(0), wait(false) { async(true); }
virtual ~MinSendTimeout () {}
void waitTimeout () {
// wait until time out over
while( wait==true ) _delay_us(1);
set(millis2ticks(100));
// signal new wait cycle
wait = true;
// add to system clock
sysclock.add(*this);
}
virtual void trigger(__attribute__ ((unused)) AlarmClock& clock) {
// signal wait cycle over
wait = false;
}
} timeout;

private:
SPIType spi;

Expand Down Expand Up @@ -530,6 +551,8 @@ class Radio {
protected:
uint8_t sndData(uint8_t *buf, uint8_t size, uint8_t burst) {

timeout.waitTimeout();

sending = true;

// Going from RX to TX does not work if there was a reception less than 0.5
Expand Down

0 comments on commit 7632eac

Please sign in to comment.