From c21e3ea8355a76d79569e643e48b26021e1b6c48 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Sun, 30 Apr 2017 22:45:32 +0200 Subject: [PATCH] - fixed presence pulse timings, according to andrewradke feedback (https://github.com/neuoy/OneWireArduinoSlave/issues/4) - visual studio intellisense fix --- LowLevel.h | 10 ++++++++++ OneWireIO.vcxproj | 2 +- OneWireSlave.cpp | 7 ++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/LowLevel.h b/LowLevel.h index 19943f1..58d0ec7 100644 --- a/LowLevel.h +++ b/LowLevel.h @@ -3,6 +3,16 @@ #include +#ifdef VS_INTELLISENSE +static inline void UserTimer_Init(void) +{ +} +static inline void UserTimer_Run(short skipTicks) +{ +} +#define UserTimer_Stop() {} +#endif + #if ARDUINO >= 100 #include "Arduino.h" // for delayMicroseconds, digitalPinToBitMask, etc #else diff --git a/OneWireIO.vcxproj b/OneWireIO.vcxproj index b8076b1..18ab5ab 100644 --- a/OneWireIO.vcxproj +++ b/OneWireIO.vcxproj @@ -46,7 +46,7 @@ Disabled true D:\Outils\Arduino\hardware\arduino\avr\cores\arduino;D:\Outils\Arduino\hardware\tools\avr\avr\include;C:\Program Files %28x86%29\Arduino\hardware\arduino\avr\cores\arduino;C:\Program Files %28x86%29\Arduino\hardware\tools\avr\avr\include - _MBCS;%(PreprocessorDefinitions);ARDUINO=160;__AVR__;UBRRH;__AVR_ATmega328__ + _MBCS;%(PreprocessorDefinitions);ARDUINO=160;__AVR__;UBRRH;__AVR_ATmega328__;VS_INTELLISENSE true diff --git a/OneWireSlave.cpp b/OneWireSlave.cpp index 851b3a2..a7b752e 100644 --- a/OneWireSlave.cpp +++ b/OneWireSlave.cpp @@ -14,8 +14,8 @@ namespace const unsigned long ResetMinDuration = 480; const unsigned long ResetMaxDuration = 900; - const unsigned long PresenceWaitDuration = 30; - const unsigned long PresenceDuration = 300; + const unsigned long PresenceWaitDuration = 15; + const unsigned long PresenceDuration = 200; const unsigned long ReadBitSamplingTime = 25; @@ -415,7 +415,8 @@ void OneWireSlave::waitReset_() lastReset_ = now; pin_.detachInterrupt(); - setTimerEvent_(PresenceWaitDuration - (micros() - now), &OneWireSlave::beginPresence_); + unsigned long alreadyElapsedTime = micros() - now; + setTimerEvent_(alreadyElapsedTime < PresenceWaitDuration ? PresenceWaitDuration - alreadyElapsedTime : 0, &OneWireSlave::beginPresence_); endWrite_(true, false); if (clientReceiveCallback_ != 0) clientReceiveCallback_(RE_Reset, 0);