Skip to content

Commit

Permalink
Small bug fix. Public version v0.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsar123 committed Jul 31, 2017
1 parent 301eba4 commit 19438a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions config.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// Then comment it out again and upload the code one more time, for the actual functionality
//#define INITIALIZE
// Only for debugging (will use Serial interface to print messages):
#define DEBUG
//#define DEBUG
// Uncomment to use one internal LEDs as WiFi status (the other internal LED will only be used for warning signals)
//#define WIFI_LED

Expand Down Expand Up @@ -141,8 +141,8 @@ const int A0_LOW = 0;
#elif N_SWITCH == 3
//#define PHYS_SWITCH
#define INDOORS
const float T_1A = 22.5;
const float T_1B = 23.0;
const float T_1A = 23.0;
const float T_1B = 23.3;
const float T_2A = 6.5;
const float T_2B = 7.0;
const float Z_ANGLE = 1;
Expand Down Expand Up @@ -231,4 +231,4 @@ unsigned long int t_1, t_2, t_2_next;
#endif

Timezone Zone(Summer, Winter);

19 changes: 10 additions & 9 deletions get_time.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,32 @@ void get_time()
Serial.println(tmp);
#endif

// Summer time correction (seconds); needs to be added to the local winter time to make proper (either winter or summer) local time:
if (Zone.locIsDST(local))
dt_summer = 3600;
else
dt_summer = 0;

#ifdef INDOORS
// Figuring out when to turn the indoor light off for the night, and on in the morning
// +1 second to make T_1B moment inclusive:
int delta = (int)(3600 * (T_1B - T_1A)) + 1;
// Random moment to turn off the indoor light in the evening (from the T_1A...T_1B interval):
t_1 = t_midnight + (int)(3600 * T_1A) + random(delta);
t_1 = t_midnight + (int)(3600 * T_1A) - dt_summer + random(delta);
// +1 second to make T_2B moment inclusive:
delta = (int)(3600 * (T_2B - T_2A)) + 1;
// Random moment to turn on the indoor light in the morning (from the T_2A...T_2B interval):
if (t_2_next == 0)
t_2 = t_midnight + (int)(3600 * T_2A) + random(delta);
t_2 = t_midnight + (int)(3600 * T_2A) - dt_summer + random(delta);
else
// If this is not the first calculation since reboot, we use the last day's calculation for t_2:
t_2 = t_2_next;
t_2_next = t_midnight2 + (int)(3600 * T_2A) + random(delta);
t_2_next = t_midnight2 + (int)(3600 * T_2A) - dt_summer + random(delta);
#ifdef DEBUG
sprintf(tmp, "t_2=%d, t_1=%d, t_2_next=%d", t_2, t_1, t_2_next);
Serial.println(tmp);
#endif
#endif
// Summer time correction (seconds); needs to be added to the local winter time to make proper (either winter or summer) local time:
if (Zone.locIsDST(local))
dt_summer = 3600;
else
dt_summer = 0;

redo_times = 0;
}
Expand All @@ -153,4 +154,4 @@ int deviation()
{
return random(DARK_RAN) - (DARK_RAN - 1) / 2;
}


3 changes: 2 additions & 1 deletion smart.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void smart()
// How many seconds left till the next event:
left = event - local;
#ifdef INDOORS
//!!! Bug: should skip morning events when light doesn't turn on in the morning (t_sunrise_next < t_2_next)
// Turning an interior light off for the night:
if (Mode == 1)
if (local > t_1 || local < t_2)
Expand Down Expand Up @@ -69,4 +70,4 @@ void smart()

return;
}


0 comments on commit 19438a1

Please sign in to comment.