|
|
@@ -74,7 +74,7 @@ int DaysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
|
|
|
int DaysInMonthLeapYear[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
|
|
|
bool leapYear = false; |
|
|
|
int stepsFor180Deg = 1600; // The stepper motor needs 200 single steps for 360 deg, equals 100 steps for 180 deg, 180 Deg in 1/16 steps equals 1600 1/16 steps |
|
|
|
int leapsFor180Deg = 5; // Determines how big the amount of single steps is to complete 180 degrees of rotation |
|
|
|
int leapsFor180Deg = 80; // Determines how big the amount of single steps is to complete 180 degrees of rotation, 80 ^= 1600/80 1/16 Steps tom complete 180 deg |
|
|
|
bool alarmSunriseFlag = false; |
|
|
|
bool alarmSunsetFlag = false; |
|
|
|
bool makeStepFlag = false; |
|
|
@@ -462,6 +462,7 @@ void set_time_and_date(timeAndDate *timeanddate){ |
|
|
|
int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){ |
|
|
|
int duration_h=0; |
|
|
|
int duration_m=0; |
|
|
|
int duration=0; |
|
|
|
|
|
|
|
duration_h = sunset->hours - sunrise->hours; |
|
|
|
duration_m = sunset->minutes - sunrise->minutes; |
|
|
@@ -471,7 +472,9 @@ int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){ |
|
|
|
duration_m = 60 - sunrise->minutes + sunset->minutes; |
|
|
|
} |
|
|
|
|
|
|
|
return (duration_h * 60 + duration_m) / leapsFor180Deg; |
|
|
|
duration = (duration_h * 60 + duration_m) / leapsFor180Deg; |
|
|
|
|
|
|
|
return duration; |
|
|
|
} |
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
@@ -586,7 +589,7 @@ int main(void) |
|
|
|
0 |
|
|
|
}; |
|
|
|
|
|
|
|
uint32_t timeToNextStep_m=0; |
|
|
|
uint32_t timeToNextStep=0; |
|
|
|
uint32_t alarmB_h = 0; |
|
|
|
uint32_t alarmB_m = 0; |
|
|
|
uint32_t alarmB_wd = 0; |
|
|
@@ -648,16 +651,18 @@ int main(void) |
|
|
|
calc_sunrise_sunset(&initialDate, &sunrise, &sunset, &tomorrowsDate); |
|
|
|
|
|
|
|
//Test code |
|
|
|
sunrise.hours = 14; |
|
|
|
sunrise.minutes = 0; |
|
|
|
sunrise.weekDay = 7; |
|
|
|
|
|
|
|
sunset.hours = 16; |
|
|
|
sunset.minutes = 00; |
|
|
|
sunset.weekDay = 7; |
|
|
|
sunrise.hours = 7; |
|
|
|
sunrise.minutes = 25; |
|
|
|
sunrise.weekDay = 1; |
|
|
|
|
|
|
|
sunset.hours = 18; |
|
|
|
sunset.minutes = 13; |
|
|
|
sunset.weekDay = 1; |
|
|
|
|
|
|
|
|
|
|
|
//Calculate the time for next motor step in minutes |
|
|
|
timeToNextStep_m = calc_interval_duration(&sunrise, &sunset); |
|
|
|
timeToNextStep = calc_interval_duration(&sunrise, &sunset); |
|
|
|
|
|
|
|
// Set Alarm for sunrise |
|
|
|
transmit_uart("Setting alarm for sunrise.\r\n"); |
|
|
@@ -693,9 +698,9 @@ int main(void) |
|
|
|
|
|
|
|
transmit_uart("|--------------------------------------------------------|\r\n\r\n"); |
|
|
|
// Increment alarm time with the precalculated timeToNextStep |
|
|
|
int minAdd_tmp=0; |
|
|
|
float minAdd_tmp=0; |
|
|
|
|
|
|
|
minAdd_tmp = alarmB_m + timeToNextStep_m; |
|
|
|
minAdd_tmp = alarmB_m + timeToNextStep; |
|
|
|
|
|
|
|
// Consider minutes overflow ^= hours + 1 |
|
|
|
if (minAdd_tmp > 60) { |
|
|
@@ -832,8 +837,8 @@ static void MX_RTC_Init(void) |
|
|
|
|
|
|
|
/** Initialize RTC and set the Time and Date |
|
|
|
*/ |
|
|
|
sTime.Hours = 13; |
|
|
|
sTime.Minutes = 56; |
|
|
|
sTime.Hours = 7; |
|
|
|
sTime.Minutes = 20; |
|
|
|
sTime.Seconds = 10; |
|
|
|
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; |
|
|
|
sTime.StoreOperation = RTC_STOREOPERATION_RESET; |
|
|
@@ -841,7 +846,7 @@ static void MX_RTC_Init(void) |
|
|
|
{ |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
sDate.WeekDay = RTC_WEEKDAY_SUNDAY; |
|
|
|
sDate.WeekDay = RTC_WEEKDAY_MONDAY; |
|
|
|
sDate.Month = RTC_MONTH_FEBRUARY; |
|
|
|
sDate.Date = 21; |
|
|
|
sDate.Year = 21; |