Skip to content

Commit

Permalink
tidyup
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHD committed Sep 13, 2018
1 parent 5ddcbf9 commit 3561b6e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683919638829322514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683828320629331514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683919638829322514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683828320629331514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -27,7 +27,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683919638829322514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683828320629331514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -38,7 +38,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683919638829322514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1683828320629331514" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
Binary file modified OTRadioLink.zip
Binary file not shown.
43 changes: 28 additions & 15 deletions content/OTRadioLink/utility/OTRadValve_ValveMotorDirectV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ KIND, either express or implied. See the Licence for the
specific language governing permissions and limitations
under the Licence.
Author(s) / Copyright (s): Damon Hart-Davis 2015--2016
Deniz Erbilgin 2016
Author(s) / Copyright (s): Damon Hart-Davis 2015--2018
Deniz Erbilgin 2016
*/

/*
Expand All @@ -40,27 +40,33 @@ namespace OTRadValve

#ifdef ARDUINO_ARCH_AVR

// A default value for the nSLEEP motor drive pin when used with hardware drivers that do not use it.
// Triggers a static_assert in DRV8850HardwareDriver and also causes fastDigitalWrite to throw an error.
// Default for nSLEEP motor drive pin for h/w drivers that don't use it.
// Triggers a static_assert in DRV8850HardwareDriver
// and also causes fastDigitalWrite to throw an error.
// TODO probably belongs somewhere else.
static constexpr uint8_t MOTOR_DRIVE_NSLEEP_UNUSED = 255;

// Implementation for V1 (REV7/DORM1) motor.
// Usually not instantiated except within ValveMotorDirectV1.
// Creating multiple instances (trying to drive same motor) almost certainly a BAD IDEA.
// Creating multiple instances (trying to drive same motor)
// almost certainly a BAD IDEA.
#define ValveMotorDirectV1HardwareDriver_DEFINED
template <uint8_t MOTOR_DRIVE_ML_DigitalPin, uint8_t MOTOR_DRIVE_MR_DigitalPin, uint8_t MOTOR_DRIVE_MI_AIN_DigitalPin, uint8_t MOTOR_DRIVE_MC_AIN_DigitalPin, uint8_t>
class ValveMotorDirectV1HardwareDriver final : public ValveMotorDirectV1HardwareDriverBase
{
private:
// Last recorded direction.
// Helpful to record shaft-encoder and other behaviour correctly around direction changes.
// Marked volatile and stored as uint8_t to help thread-safety, and potentially save space.
// Helpful to record shaft-encoder and other behaviour correctly
// around direction changes.
// Marked volatile and stored as uint8_t to help thread-safety,
// and potentially save space.
volatile uint8_t last_dir;
// Maximum current reading allowed when closing the valve (against the spring).
static constexpr uint16_t maxCurrentReadingClosing = 600;
// Maximum current reading allowed when opening the valve (retracting the pin, no resisting force).
// Keep this as low as possible to reduce the chance of skipping the end-stop and game over...
// Maximum current reading allowed when opening the valve
// (retracting the pin, no resisting force).
// Keep this as low as possible to reduce the chance of
// skipping the end-stop and game over...
// DHD20151229: at 500 Shenzhen sample unit without outer case (so with more flex) was able to drive past end-stop.
static constexpr uint16_t maxCurrentReadingOpening = 450; // DHD20151023: 400 seemed marginal.
public:
Expand Down Expand Up @@ -121,7 +127,8 @@ OTV0P2BASE::serialPrintlnAndFlush();
const uint8_t prev_dir = last_dir;

// *** MUST NEVER HAVE L AND R LOW AT THE SAME TIME else board may be destroyed at worst. ***
// Operates as quickly as reasonably possible, eg to move to stall detection quickly...
// Operates as quickly as reasonably possible,
// eg to move to stall detection quickly...
// TODO: consider making atomic to block some interrupt-related accidents...
// TODO: note that the mapping between L/R and open/close not yet defined.
// DHD20150205: 1st cut REV7 all-in-in-valve, seen looking down from valve into base, cw => close (ML=HIGH), ccw = open (MR=HIGH).
Expand Down Expand Up @@ -190,10 +197,15 @@ OTV0P2BASE::serialPrintlnAndFlush();
};

// Actuator/driver for direct local (radiator) valve motor control.
// * lowBattOpt allows monitoring of supply voltage to avoid some activities with low batteries; can be NULL
// * minimiseActivityOpt callback returns true if unnecessary activity should be suppressed
// to avoid disturbing occupants, eg when room dark and occupants may be sleeping; can be NULL
// * binaryOnly if true, use simplified valve control logic that only aims for fully open or closed
// * lowBattOpt allows monitoring of supply voltage to avoid
// some activities with low batteries; can be NULL
// * minimiseActivityOpt callback returns true if
// unnecessary activity should be suppressed
// to avoid disturbing occupants,
// eg when room dark and occupants may be sleeping;
// can be NULL
// * binaryOnly if true, use simplified valve control logic
// that only aims for fully open or closed
#define ValveMotorDirectV1_DEFINED
template
<
Expand Down Expand Up @@ -276,7 +288,8 @@ class ValveMotorDirectV1 : public OTRadValve::AbstractRadValve

// Minimally wiggles the motor to give tactile feedback and/or show to be working.
// May take a significant fraction of a second.
// Finishes with the motor turned off, and a bias to closing the valve.
// Finishes with the motor turned off,
// and a bias to closing the valve.
// Logically const as nominally leaving the valve position unchanged.
virtual void wiggle() const override
{ const_cast<logic_type*>(&logic)->wiggle(); }
Expand Down
9 changes: 6 additions & 3 deletions content/OTRadioLink/utility/OTV0P2BASE_RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ extern volatile uint_least16_t _daysSince1999LT;

// Persist software RTC information to non-volatile (EEPROM) store.
// This does not attempt to store full precision of time down to seconds,
// but enough to help avoid the clock slipping too much during (say) a battery change.
// but enough to help avoid the clock slipping too much during
// (say) a battery change.
// There is no point calling this more than (say) once per minute,
// though it will simply return relatively quickly from redundant calls.
// The RTC data is stored so as not to wear out AVR EEPROM for at least several years.
// The RTC data is stored so as not to wear out AVR EEPROM
// for at least several years.
void persistRTC();

// Restore software RTC information from non-volatile (EEPROM) store, if possible.
// Returns true if the persisted data seemed valid and was restored, in full or part.
// Returns true if the persisted data seemed valid and was restored,
// in full or part.
bool restoreRTC();


Expand Down
34 changes: 19 additions & 15 deletions content/OTRadioLink/utility/OTV0P2BASE_SensorTemperaturePot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ KIND, either express or implied. See the Licence for the
specific language governing permissions and limitations
under the Licence.
Author(s) / Copyright (s): Damon Hart-Davis 2013--2016
Author(s) / Copyright (s): Damon Hart-Davis 2013--2018
*/

/*
Expand Down Expand Up @@ -97,7 +97,8 @@ class SensorTemperaturePotMock final : public SensorTemperaturePotBase

// Set WARM/FROST and BAKE start/cancel callbacks.
// If not NULL, are called when the pot is adjusted appropriately.
// Typically at most one of these callbacks would be made on any appropriate pot adjustment.
// Typically at most one of these callbacks would be made
// on any appropriate pot adjustment.
// void setWFBCallbacks(void (*warmModeCallback_)(bool), void (*bakeStartCallback_)(bool))
// { warmModeCallback = warmModeCallback_; bakeStartCallback = bakeStartCallback_; }
void setWFBCallbacks(void (*)(bool), void (*)(bool)) {}
Expand Down Expand Up @@ -151,7 +152,8 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase

// WARM/FROST and BAKE start/cancel callbacks.
// If not NULL, are called when the pot is adjusted appropriately.
// Typically at most one of these callbacks would be made on any appropriate pot adjustment.
// Typically at most one of these callbacks would be made
// on any appropriate pot adjustment.
void (*warmModeCallback)(bool) = NULL;
void (*bakeStartCallback)(bool) = NULL;

Expand Down Expand Up @@ -183,10 +185,6 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase
: SensorTemperaturePotBase(_computeLoEndStop(minExpected, maxExpected), _computeHiEndStop(minExpected, maxExpected))
{ }

// Force a read/poll of the temperature pot and return the value sensed [0,255] (cold to hot).
// Potentially expensive/slow.
// This value has some hysteresis applied to reduce noise.
// Not thread-safe nor usable within ISRs (Interrupt Service Routines).
// Force a read/poll of the temperature pot and return the value sensed [0,255] (cold to hot).
// Potentially expensive/slow.
// This value has some hysteresis applied to reduce noise.
Expand All @@ -199,6 +197,7 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase
// No need to wait for voltage to stabilise as pot top end
// directly driven by IO_POWER_UP (or to Vcc, due to REV7 error!).
if(needsPeriphEnable) { OTV0P2BASE::power_intermittent_peripherals_enable(false); }
OTV0P2BASE::nap(WDTO_15MS); // Wait to allow pot to settle.
const uint16_t tpRaw = OTV0P2BASE::analogueNoiseReducedRead(ADC_input, DEFAULT); // Vcc reference.
if(needsPeriphEnable) { OTV0P2BASE::power_intermittent_peripherals_disable(); }

Expand All @@ -210,7 +209,8 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase
if((uint8_t)newRaw != (uint8_t)oldRaw) { addEntropyToPool((uint8_t)newRaw, 1); }

// Capture reduced-noise value with a little hysteresis.
// Only update the value if changed significantly so as to reduce noise.
// Only update the value if changed significantly.
// so as to reduce noise.
// Too much hysteresis may make the dial difficult to use,
// especially if the rotation is physically constrained.
const uint8_t oldValue = this->value;
Expand All @@ -224,10 +224,12 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase
this->value = rn;

// Smart responses to adjustment/movement of temperature pot.
// Possible to get reasonable functionality without using MODE button.
// Possible to get reasonable functionality without using
// MODE button.
//
// Ignore first reading which might otherwise cause spurious mode change, etc.
if((uint16_t)~0U != (uint16_t)raw) // Ignore if raw not yet set for the first time.
// Ignore first reading which might otherwise cause
// spurious mode change, etc.
if((uint16_t)~0U != (uint16_t)raw)
{
// Force FROST mode when dial turned right down to bottom.
if(rn < this->loEndStop) { if(NULL != warmModeCallback) { warmModeCallback(false); } }
Expand All @@ -238,8 +240,9 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase
// Force WARM mode when dial/temperature turned up.
else if(rn > oldValue) { if(NULL != warmModeCallback) { warmModeCallback(true); } }

// Report that the user operated the pot, ie part of the manual UI.
// Do this regardless of whether a specific mode change was invoked.
// Report that user operated the pot, ie part of the manual UI.
// Do this regardless of whether a specific mode change
// was invoked.
if(NULL != occupancyOpt) { occupancyOpt->markAsOccupied(); }
}
}
Expand All @@ -260,11 +263,12 @@ class SensorTemperaturePot final : public SensorTemperaturePotBase

// Set WARM/FROST and BAKE start/cancel callbacks.
// If not NULL, are called when the pot is adjusted appropriately.
// Typically at most one of these callbacks would be made on any appropriate pot adjustment.
// Typically at most one of these callbacks would be made on any
// appropriate pot adjustment.
void setWFBCallbacks(void (*warmModeCallback_)(bool), void (*bakeStartCallback_)(bool))
{ warmModeCallback = warmModeCallback_; bakeStartCallback = bakeStartCallback_; }

// Return last value fetched by read(); undefined before first read()).
// Return last value fetched by read(); undefined before first read().
// Fast.
// Not thread-safe nor usable within ISRs (Interrupt Service Routines).
uint16_t getRaw() const { return(raw); }
Expand Down

0 comments on commit 3561b6e

Please sign in to comment.