Beispiel #1
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void AutoMonitorTimerCallBack(void)
{
	INPUT_MSG_STRUCT mn_msg;

	debug("Auto Monitor Timer callback: activated.\r\n");

	// Check if the USB is currently handling an active connection
	if (g_usbMassStorageState == USB_CONNECTED_AND_PROCESSING)
	{
		AssignSoftTimer(AUTO_MONITOR_TIMER_NUM, (uint32)(g_unitConfig.autoMonitorMode * TICKS_PER_MIN), AutoMonitorTimerCallBack);
	}
	else
	{
		// Make sure the Auto Monitor timer is disabled
		ClearSoftTimer(AUTO_MONITOR_TIMER_NUM);

		// Check if the unit is not already monitoring
		if (g_sampleProcessing != ACTIVE_STATE)
		{
			if (CheckAndDisplayErrorThatPreventsMonitoring(OVERLAY))
			{
				AssignSoftTimer(AUTO_MONITOR_TIMER_NUM, (uint32)(g_unitConfig.autoMonitorMode * TICKS_PER_MIN), AutoMonitorTimerCallBack);
			}
			else // Safe to enter monitor mode
			{
				// Enter monitor mode with the current mode
				SETUP_MENU_WITH_DATA_MSG(MONITOR_MENU, g_triggerRecord.opMode);
				JUMP_TO_ACTIVE_MENU();
			}
		}
	}
}
Beispiel #2
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void LcdPwTimerCallBack(void)
{
	debug("LCD Power Timer callback: activated.\r\n");

	g_lcdPowerFlag = DISABLED;

	PowerControl(LCD_CONTRAST_ENABLE, OFF);
	ClearLcdDisplay();
	ClearControlLinesLcdDisplay();
	LcdClearPortReg();
	PowerControl(LCD_POWER_ENABLE, OFF);

	if (g_sampleProcessing == ACTIVE_STATE)
	{
		debug("LCD Power Timer callback: disabling Monitor Update Timer.\r\n");
		ClearSoftTimer(MENU_UPDATE_TIMER_NUM);
	}
}
Beispiel #3
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void HandleUserPowerOffDuringTimerMode(void)
{
	INPUT_MSG_STRUCT mn_msg;
	uint8 choice;

	// Simulate a keypress if the user pressed the off key, which doesn't register as a keypess
	KeypressEventMgr();

	MessageBox(getLangText(STATUS_TEXT), getLangText(UNIT_IS_IN_TIMER_MODE_TEXT), MB_OK);
	choice = MessageBox(getLangText(WARNING_TEXT), getLangText(CANCEL_TIMER_MODE_Q_TEXT), MB_YESNO);

	// User decided to cancel Timer mode
	if (choice == MB_FIRST_CHOICE)
	{
		g_unitConfig.timerMode = DISABLED;

		// Disable the Power Off timer
		ClearSoftTimer(POWER_OFF_TIMER_NUM);

		// Save Unit Config
		SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);

		OverlayMessage(getLangText(STATUS_TEXT), getLangText(TIMER_MODE_DISABLED_TEXT), 2 * SOFT_SECS);
	}
	else // User decided to stay in Timer mode
	{
		choice = MessageBox(getLangText(STATUS_TEXT), getLangText(POWER_UNIT_OFF_EARLY_Q_TEXT), MB_YESNO);

		if (choice == MB_FIRST_CHOICE)
		{
			MessageBox(getLangText(STATUS_TEXT), getLangText(POWERING_UNIT_OFF_NOW_TEXT), MB_OK);
			MessageBox(getLangText(STATUS_TEXT), getLangText(PLEASE_PRESS_ENTER_TEXT), MB_OK);

			// Turn unit off/sleep
			debug("Timer mode: Shutting down unit early due to user request. Powering off now...\r\n");
			PowerUnitOff(SHUTDOWN_UNIT); // Return unnecessary
		}
	}

	SETUP_MENU_MSG(MAIN_MENU);
	JUMP_TO_ACTIVE_MENU();
}
Beispiel #4
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void ModemResetTimerCallback(void)
{
	if (g_modemResetStage == 0)
	{
		// If for some reason this executes, make sure the timer is disabled
		ClearSoftTimer(MODEM_RESET_TIMER_NUM);
	}
	else if (g_modemResetStage == 1)
	{
		SET_DTR;

		AssignSoftTimer(MODEM_RESET_TIMER_NUM, (uint32)(3 * TICKS_PER_SEC), ModemResetTimerCallback);
		g_modemResetStage = 2;
	}
	else if (g_modemResetStage == 2)
	{
		UartPuts((char*)(CMDMODE_CMD_STRING), CRAFT_COM_PORT);
		AssignSoftTimer(MODEM_RESET_TIMER_NUM, (uint32)(3 * TICKS_PER_SEC), ModemResetTimerCallback);
		g_modemResetStage = 3;
	}
	else if (g_modemResetStage == 3)
	{
		UartPuts((char*)(CMDMODE_CMD_STRING), CRAFT_COM_PORT);
		AssignSoftTimer(MODEM_RESET_TIMER_NUM, (uint32)(3 * TICKS_PER_SEC), ModemResetTimerCallback);
		g_modemResetStage = 4;
	}
	else if (g_modemResetStage == 4)
	{
		UartPuts((char*)(ATH_CMD_STRING), CRAFT_COM_PORT);
		UartPuts((char*)&g_CRLF, CRAFT_COM_PORT);
		AssignSoftTimer(MODEM_RESET_TIMER_NUM, (uint32)(3 * TICKS_PER_SEC), ModemResetTimerCallback);
		g_modemResetStage = 5;
	}
	else if (g_modemResetStage == 5)
	{
		ModemInitProcess();
		g_modemResetStage = 0;
	}
}
Beispiel #5
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void AssignSoftTimer(uint16 timerNum, uint32 timeout, void* callback)
{
	if (timerNum >= NUM_OF_SOFT_TIMERS)
	{
		debugErr("AssignSoftTimer Error: Timer Number not valid: %d\r\n", timerNum);
		return;
	}

	// Check that the timeout condition is set for some time in the future
	if (timeout > 0)
	{
		g_rtcTimerBank[timerNum].state = TIMER_ASSIGNED;
		g_rtcTimerBank[timerNum].tickStart = g_lifetimeHalfSecondTickCount;
		g_rtcTimerBank[timerNum].timePeriod = g_lifetimeHalfSecondTickCount + timeout;
		g_rtcTimerBank[timerNum].timeoutValue = timeout;
		g_rtcTimerBank[timerNum].callback = callback;
	}
	else // Timeout is zero, go ahead and clear the timer just in case it's already set/active
	{
		ClearSoftTimer(timerNum);
	}

	return;
}
Beispiel #6
0
///----------------------------------------------------------------------------
///	Function Break
///----------------------------------------------------------------------------
void ProcessTimerModeSettings(uint8 mode)
{
	//uint8 dayOfWeek = 0;
	uint8 startDay = 0;
	uint8 startHour = 0;
	uint16 minutesLeft = 0;
	DATE_TIME_STRUCT currentTime = GetCurrentTime();
	uint8 status = ValidateTimerModeSettings();

	// Check if the timer mode settings check failed or if the timer mode setting has been disabled
	if ((status == FAILED) || (g_unitConfig.timerMode == DISABLED))
	{
		g_unitConfig.timerMode = DISABLED;
		SaveRecordData(&g_unitConfig, DEFAULT_RECORD, REC_UNIT_CONFIG_TYPE);

		// Disable the Power Off timer in case it's set
		ClearSoftTimer(POWER_OFF_TIMER_NUM);

		if (mode == PROMPT)
		{
			sprintf((char*)g_spareBuffer, "%s %s", getLangText(TIMER_SETTINGS_INVALID_TEXT), getLangText(TIMER_MODE_DISABLED_TEXT));
			MessageBox(getLangText(ERROR_TEXT), (char*)g_spareBuffer, MB_OK);
		}
	}
	else // status == PASSED || status == IN_PROGRESS
	{
		// Calculate timer mode active run time in minutes
		TimerModeActiveMinutes();

		// Init start day based on the start date provided by the user
		startDay = g_unitConfig.timerStartDate.day;

		// Check if in progress, requiring extra logic to determine alarm settings
		if (status == IN_PROGRESS)
		{
			// Check if the stop time is greater than the start time
			if ((g_unitConfig.timerStopTime.hour > g_unitConfig.timerStartTime.hour) ||
			((g_unitConfig.timerStopTime.hour == g_unitConfig.timerStartTime.hour) &&
			(g_unitConfig.timerStopTime.min > g_unitConfig.timerStartTime.min)))
			{
				// Advance the start day
				startDay++;

				// Check if the start day is beyond the total days in the current month
				if (startDay > g_monthTable[(uint8)(g_unitConfig.timerStartDate.month)].days)
				{
					// Set the start day to the first day of next month
					startDay = 1;
				}
			}
		}

		// Check for specialty case hourly mode and in progress, requiring extra logic to determine alarm settings
		if ((g_unitConfig.timerModeFrequency == TIMER_MODE_HOURLY) && (status == IN_PROGRESS))
		{
			// Check if another hour time slot to run again today
			if (currentTime.hour != g_unitConfig.timerStopTime.hour)
			{
				// Start day remains the same
				startDay = g_unitConfig.timerStartDate.day;

				// Check if current hour time slot has not started
				if (currentTime.min < g_unitConfig.timerStartTime.min)
				{
					// Set alarm for the same hour
					startHour = currentTime.hour;
				}
				else
				{
					// Set alarm for the next hour
					startHour = currentTime.hour + 1;
					
					// Account for end of day boundary
					if (startHour > 23)
					{
						startHour = 0;

						// Advance the start day
						startDay++;

						// Check if the start day is beyond the total days in the current month
						if (startDay > g_monthTable[(uint8)(g_unitConfig.timerStartDate.month)].days)
						{
							// Set the start day to the first day of next month
							startDay = 1;
						}
					}
				}
				
				EnableExternalRtcAlarm(startDay, startHour, g_unitConfig.timerStartTime.min, 0);
			}
			else // This is the last hour time slot to run today, set alarm for next day
			{
				// startDay calculated correctly in above previous status == IN_PROGRESS logic
				EnableExternalRtcAlarm(startDay, g_unitConfig.timerStartTime.hour, g_unitConfig.timerStartTime.min, 0);
			}
		}
		else // All other timer modes
		{
			EnableExternalRtcAlarm(startDay, g_unitConfig.timerStartTime.hour, g_unitConfig.timerStartTime.min, 0);
		}

		if (status == PASSED)
		{
			if (mode == PROMPT)
			{
				sprintf((char*)g_spareBuffer, "%s %s", getLangText(TIMER_MODE_NOW_ACTIVE_TEXT), getLangText(PLEASE_POWER_OFF_UNIT_TEXT));
				MessageBox(getLangText(STATUS_TEXT), (char*)g_spareBuffer, MB_OK);
			}

			// Check if start time is greater than the current time
			if (((g_unitConfig.timerStartTime.hour * 60) + g_unitConfig.timerStartTime.min) >
			((currentTime.hour * 60) + currentTime.min))
			{
				// Take the difference between start time and current time
				minutesLeft = (uint16)(((g_unitConfig.timerStartTime.hour * 60) + g_unitConfig.timerStartTime.min) -
				((currentTime.hour * 60) + currentTime.min));
			}
			else // Current time is after the start time, meaning the start time is the next day
			{
				// Take the difference between 24 hours and the current time plus the start time
				minutesLeft = (uint16)((24 * 60) - ((currentTime.hour * 60) + currentTime.min) +
				((g_unitConfig.timerStartTime.hour * 60) + g_unitConfig.timerStartTime.min));
			}

			// Check if the start time is within the next minute
			if (minutesLeft <= 1)
			{
				OverlayMessage(getLangText(WARNING_TEXT), getLangText(POWERING_UNIT_OFF_NOW_TEXT), 2 * SOFT_SECS);

				// Need to shutdown the unit now, otherwise the start time window will be missed
				PowerUnitOff(SHUTDOWN_UNIT); // Return unnecessary
			}
			else // More than 1 minute left before the start time
			{
				// Make sure the unit turns off one minute before the start time if the user forgets to turn the unit off
				minutesLeft -= 1;

				// Need to handle state where timer mode is going active but unit hasn't power cycled into timer mode yet
				g_allowQuickPowerOffForTimerModeSetup = YES;

				// Set the Power off soft timer to prevent the unit from staying on past the Timer mode start time
				AssignSoftTimer(POWER_OFF_TIMER_NUM, (uint32)(minutesLeft * 60 * 2), PowerOffTimerCallback);
			}
		}
		else // status == IN_PROGRESS
		{
			if (mode == PROMPT)
			{
				sprintf((char*)g_spareBuffer, "%s", getLangText(TIMER_MODE_NOW_ACTIVE_TEXT));
				MessageBox(getLangText(STATUS_TEXT), (char*)g_spareBuffer, MB_OK);
			}

			// Check if specialty mode hourly
			if (g_unitConfig.timerModeFrequency == TIMER_MODE_HOURLY)
			{
				if (currentTime.min	< g_unitConfig.timerStopTime.min)
				{
					minutesLeft = (g_unitConfig.timerStopTime.min - currentTime.min);
				}
				else
				{
					minutesLeft = (60 + g_unitConfig.timerStopTime.min - currentTime.min);
				}
				
				if (minutesLeft > 58)
				minutesLeft = 58;
			}
			// Check if the current time is greater than the stop time, indicating that midnight boundary was crossed
			else if (((currentTime.hour * 60) + currentTime.min) > ((g_unitConfig.timerStopTime.hour * 60) + g_unitConfig.timerStopTime.min))
			{
				// Calculate the time left before powering off to be 24 + the stop time minus the current time
				minutesLeft = (uint16)(((24 * 60) + (g_unitConfig.timerStopTime.hour * 60) + g_unitConfig.timerStopTime.min) -
				((currentTime.hour * 60) + currentTime.min));
			}
			else // Current time is less than start time, operating within the same day
			{
				// Calculate the time left before powering off to be the stop time minus the current time
				minutesLeft = (uint16)(((g_unitConfig.timerStopTime.hour * 60) + g_unitConfig.timerStopTime.min) -
				((currentTime.hour * 60) + currentTime.min));
			}

			// Make sure timeout value is not zero
			if (minutesLeft == 0) minutesLeft = 1;

			debug("Timer Mode: In progress, minutes left before power off: %d (Expired secs this min: %d)\r\n", minutesLeft, currentTime.sec);

			// Setup soft timer to turn system off when timer mode is finished for the day
			AssignSoftTimer(POWER_OFF_TIMER_NUM, (uint32)((minutesLeft * 60 * 2) - (currentTime.sec	* 2)), PowerOffTimerCallback);
		}
	}
}