Commits

Wagner Sartori Junior committed 8aa55e8

- arrumado alarme que não estava gravando em memória
- informações de _DEBUG_ via serial na classe varManager

  • Participants
  • Parent commits 2d24727

Comments (0)

Files changed (4)

File AlarmClock.cpp

 		timeAlarmSoundStarted	=	millis();
 
 		// also revert to application "Quote" and show the time;
-	        trunetClock.crtApp	=	APP_QUOTE;
+	    trunetClock.crtApp	=	APP_QUOTE;
 		trunetClock.displayTime(hour, minute, isAlarmEnabled, is24hourModeEnabled);
 	}
 	else if (hour != alarmHour || minute != alarmMin)
 		}
 }
 
-
-
 CAlarmClock alarmClock;
 
 

File TrunetClock.cpp

   varManager.setVarAddrLocation("alarmHour", 0);
   varManager.setVarAddrLocation("alarmMin", 1);
   varManager.setVarAddrLocation("alarmOnOff", 2);
-  varManager.setVarAddrLocation("brightnessLoc", 3);
-  varManager.setVarAddrLocation("speedLoc", 4);
-  varManager.setVarAddrLocation("snoozeTimeLoc", 5);
-  varManager.setVarAddrLocation("showDateLoc", 6);
-  varManager.setVarAddrLocation("showMessageLoc", 7);
-  varManager.setVarAddrLocation("mode24HourLoc", 8);
-  varManager.setVarAddrLocation("utcDiffLoc", 9);
+  varManager.setVarAddrLocation("brightness", 3);
+  varManager.setVarAddrLocation("speed", 4);
+  varManager.setVarAddrLocation("snoozeTime", 5);
+  varManager.setVarAddrLocation("showDate", 6);
+  varManager.setVarAddrLocation("showMessage", 7);
+  varManager.setVarAddrLocation("mode24Hour", 8);
+  varManager.setVarAddrLocation("utcDiff", 9);
 }
 
 //*********************************************************************************************************
 		} else {
 			displayTimeDate(alarmClock.hour, alarmClock.minute, alarmClock.day, alarmClock.month, alarmClock.year, alarmClock.isAlarmEnabled, alarmClock.is24hourModeEnabled);
 		}
-
-		// wait for the menu item to expire;
-		if (abs(millis() - timeBtnMenu) < TIME_KEEP_MENU_ACTIVE)
-		{
-			return;
-		}
 		
 		if (alarmClock.isAlarmSetting)
 		{
 			alarmClock.isAlarmTriggerEnabled	=	true;
 		}
 
+		// wait for the menu item to expire;
+		if (abs(millis() - timeBtnMenu) < TIME_KEEP_MENU_ACTIVE)
+		{
+			return;
+		}
+
 		isMenuActive	=	false;
 		alarmClock.isAlarmSetting	=	false;
 		item			=	0;		//*	when we time out, set back to the beginning
-		
+
 		// refresh the current time (after maybe an alarm set);
 		displayTimeDate(alarmClock.hour, alarmClock.minute, alarmClock.day, alarmClock.month, alarmClock.year, alarmClock.isAlarmEnabled, alarmClock.is24hourModeEnabled);
 	}
 }
 
 
-
 //*********************************************************************************************************
 // Read and write alarm status
 boolean TrunetClock::getAlarmOnOff()
 {
-	return boolean( EEread_RTC(alarmOnOffLoc) );
+	//return boolean( EEread_RTC(alarmOnOffLoc) );
+	return boolean(varManager.getVarValue("alarmOnOff"));
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveAlarmOnOff()
 {
-	EEwrite_RTC( alarmOnOffLoc, alarmClock.isAlarmEnabled); 
+	//EEwrite_RTC( alarmOnOffLoc, alarmClock.isAlarmEnabled);
+	varManager.setVarValue("alarmOnOff", alarmClock.isAlarmEnabled);
 }
 
 
 // Read and write alarm time (hour, minute);
 void TrunetClock::readAlarmTime()
 {
-	alarmClock.alarmMin	=	EEread_RTC( alarmMinsLoc );
-	alarmClock.alarmHour	=	EEread_RTC( alarmHoursLoc );
+	//alarmClock.alarmMin	=	EEread_RTC( alarmMinsLoc );
+	//alarmClock.alarmHour	=	EEread_RTC( alarmHoursLoc );
+	alarmClock.alarmHour = varManager.getVarValue("alarmHour");
+	alarmClock.alarmMin = varManager.getVarValue("alarmMin");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveAlarmTime()
 {
-	EEwrite_RTC( alarmMinsLoc,	alarmClock.alarmMin );
-	EEwrite_RTC( alarmHoursLoc,	alarmClock.alarmHour );
+	//EEwrite_RTC( alarmMinsLoc,	alarmClock.alarmMin );
+	//EEwrite_RTC( alarmHoursLoc,	alarmClock.alarmHour );
+	varManager.setVarValue("alarmHour", alarmClock.alarmHour);
+	varManager.setVarValue("alarmMin", alarmClock.alarmMin);
 #ifdef _DEBUG_
 	Serial.print("Alarm time saved to RTC RAM: ");
 	Serial.print(alarmClock.alarmHour);
 // Read and write LED brightness level;
 int TrunetClock::getBrightness()
 {
-	return EEread_RTC( brightnessLoc );
+	//return EEread_RTC( brightnessLoc );
+	return varManager.getVarValue("brightness");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveBrightness()
 {
-	EEwrite_RTC( brightnessLoc, nBrightness); 
+	//EEwrite_RTC( brightnessLoc, nBrightness);
+	varManager.setVarValue("brightness", nBrightness);
 #ifdef _DEBUG_
 	Serial.print("Saved brightness: ");
 	Serial.println(nBrightness);
 // Read and write snooze time
 int TrunetClock::getSnoozeTime()
 {
-	return EEread_RTC( snoozeTimeLoc ); 
+	//return EEread_RTC( snoozeTimeLoc );
+	return varManager.getVarValue("snoozeTime");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveSnoozeTime()
 {
-	EEwrite_RTC( snoozeTimeLoc, snoozeMins ); 
+	//EEwrite_RTC( snoozeTimeLoc, snoozeMins );
+	varManager.setVarValue("snoozeTime", snoozeMins);
 #ifdef _DEBUG_
 	Serial.print("Saved snooze time: ");
 	Serial.println(snoozeMins);
 // Read and write scrolling speed;
 int TrunetClock::getSpeed()
 {
-	return EEread_RTC( speedLoc ); 
+	//return EEread_RTC( speedLoc );
+	varManager.getVarValue("speed");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveSpeed()
 {
-	EEwrite_RTC( speedLoc, nSpeed); 
+	//EEwrite_RTC( speedLoc, nSpeed);
+	varManager.setVarValue("speed", nSpeed);
 #ifdef _DEBUG_
 	Serial.print("Saved speed: ");
 	Serial.println(nSpeed);
 // Read and write param indicating if the date is displayed between quotes;
 boolean TrunetClock::getShowDate()
 {
-	return boolean( EEread_RTC(showDateLoc) );
+	//return boolean( EEread_RTC(showDateLoc) );
+	return varManager.getVarValue("showDate");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveShowDate()
 {
-	EEwrite_RTC( showDateLoc, isDateEnabled); 
+	//EEwrite_RTC( showDateLoc, isDateEnabled);
+	varManager.setVarValue("showDate", isDateEnabled);
 #ifdef _DEBUG_
 	Serial.println("Saved show date");
 #endif
 // Read and write param indicating if a special message is displayed between quotes;
 boolean TrunetClock::getShowMessage()
 {
-	return boolean( EEread_RTC(showMessageLoc) );
+	//return boolean( EEread_RTC(showMessageLoc) );
+	return varManager.getVarValue("showMessage");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveShowMessage()
 {
-	EEwrite_RTC( showMessageLoc, isMessageEnabled); 
+	//EEwrite_RTC( showMessageLoc, isMessageEnabled);
+	varManager.setVarValue("showMessage", isMessageEnabled);
 #ifdef _DEBUG_
 	Serial.println("Saved show message");
 #endif
 // Read and write param indicating if a special message is displayed between quotes;
 boolean TrunetClock::get24HourMode()
 {
-	return boolean( EEread_RTC(mode24HourLoc) );
+	//return boolean( EEread_RTC(mode24HourLoc) );
+	return varManager.getVarValue("mode24Hour");
 }
 
 
 //*********************************************************************************************************
 void TrunetClock::save24HourMode()
 {
-	EEwrite_RTC( mode24HourLoc, alarmClock.is24hourModeEnabled); 
+	//EEwrite_RTC( mode24HourLoc, alarmClock.is24hourModeEnabled);
+	varManager.setVarValue("mode24Hour", alarmClock.is24hourModeEnabled);
 #ifdef _DEBUG_
 	Serial.println("Saved 24 hour mode");
 #endif
 // Read and write UTC difference;
 int TrunetClock::getUtcDiff()
 {
-	return EEread_RTC( utcDiffLoc );
+	//return EEread_RTC( utcDiffLoc );
+	return varManager.getVarValue("utcDiff");
 }
 
 //*********************************************************************************************************
 void TrunetClock::saveUtcDiff()
 {
-	EEwrite_RTC( utcDiffLoc, alarmClock.utcDiff); 
+	//EEwrite_RTC( utcDiffLoc, alarmClock.utcDiff);
+	varManager.setVarValue("utcDiff", alarmClock.utcDiff);
 #ifdef _DEBUG_
 	Serial.print("Saved UTC difference: ");
 	Serial.println(alarmClock.utcDiff);
 void TrunetClock::initSavedParams()
 {
 	readAlarmTime();
-	nSpeed				=	getSpeed();
-	nBrightness			=	getBrightness();
-	snoozeMins			=	getSnoozeTime();
-	alarmClock.isAlarmEnabled		=	getAlarmOnOff();
-	isDateEnabled		=	getShowDate();
-	isMessageEnabled	=	getShowMessage();
-	alarmClock.is24hourModeEnabled	=	get24HourMode();
+	nSpeed							= getSpeed();
+	nBrightness						= getBrightness();
+	snoozeMins						= getSnoozeTime();
+	alarmClock.isAlarmEnabled		= getAlarmOnOff();
+	isDateEnabled					= getShowDate();
+	isMessageEnabled				= getShowMessage();
+	alarmClock.is24hourModeEnabled 	= get24HourMode();
 
 	// (fc, Jul 5/10)
 	alarmClock.setUtcDiff(getUtcDiff());
 	
 	// (fc, Feb 2/10) when powered for the first time, the values are not there (they come back as nonsense);
 	// we need to initialize them with defaults and save them;
-	if (alarmClock.alarmHour > 23 || alarmClock.alarmMin > 59 || nSpeed > MAX_SPEED || nBrightness > MAX_BRIGHTNESS || snoozeMins > MAX_SNOOZE_MINUTES)
+	if (alarmClock.alarmHour > 23 ||
+		alarmClock.alarmMin > 59 ||
+		nSpeed > MAX_SPEED ||
+		nBrightness > MAX_BRIGHTNESS ||
+		snoozeMins > MAX_SNOOZE_MINUTES)
 	{
 		// at least one param came as out-of-bounds, probably because it was never written to memory;
 		// set all params with default values and save them;
-		nSpeed	=	DEFAULT_SPEED;
+		nSpeed = DEFAULT_SPEED;
 		saveSpeed();
 
 		nBrightness			=	DEFAULT_BRIGHTNESS;
 		saveUtcDiff();
 	}
 
-
 #ifdef _DEBUG_
 	Serial.println("Params restored from RTC RAM: ");
 	Serial.print("Alarm time: ");
 	}
 }
 
-//*********************************************************************************************************
-// adapted from Jeff Saltzman's PPAC;
-//
-// Read/write from/to the DS1307 EEPROM
-void TrunetClock::EEwrite_RTC(int loc, int value)
-{
-	RTC.set_sram_byte(byte(value), loc);
-	delay(10);
-}
-
-
-//*********************************************************************************************************
-int TrunetClock::EEread_RTC(int loc)
-{
-	return int(RTC.get_sram_byte(loc));
-}
-
-
-
-
 TrunetClock trunetClock;
 

File TrunetClock.h

 
 
 // alarm stops beeping after these many minutes;
-#define DEFAULT_SNOOZE_MINUTES	2
+#define DEFAULT_SNOOZE_MINUTES	5
 #define MAX_SNOOZE_MINUTES		5
 
 
 // value between 0 (slowest) and 4 (fastest); translates into delay from 50ms to 10ms;
 // delay	=	50 - nSpeed * 10;
 #define MAX_SPEED		4
-#define DEFAULT_SPEED	3
+#define DEFAULT_SPEED	4
 
 
 // default time zone (for UTC);
 #define DEFAULT_UTC_DIFF	-3
 
-
-//*********************************************************************************************************
-// store settings in RTC's memory at these locations (thanks Jeff);
-//
-#define	alarmHoursLoc	0		// alarm hours storage location
-#define	alarmMinsLoc	1		// alarm minutes storage location
-#define	alarmOnOffLoc	2		// alarmOn storage location
-#define	alarmModeLoc	3		// alarmMode storage location
-#define	brightnessLoc	4		// brightness level storage location
-#define	clockAMPMLoc	5		// clock AMPM vs 24hr storage location
-#define	speedLoc	6		// speed storage location
-#define	snoozeTimeLoc	7		// snooze time storage location
-#define	showDateLoc	8		// "show date" storage location
-#define	showMessageLoc	9		// "show message" storage location
-#define	mode24HourLoc	10		// 12/24 hour mode
-#define	utcDiffLoc	11		// utc difference (in hours);
-
-
-
 //*********************************************************************************************************
 class TrunetClock
 {

File VarManager/VarManager.cpp

  *      Author: trunet
  */
 
+#ifdef _DEBUG_
+#include <WProgram.h>
+#endif
 #include <string.h>
 #include <EEPROM/EEPROM.h>
 #include "../DS1307/DS1307.h"
 
 int VarManager::getVarValue(char name[MAXVARLEN]) {
 	varElement *variable;
+	int val = 255;
+
+#ifdef _DEBUG_
+	Serial.print("GETTING: ");
+	Serial.println(name);
+#endif
 
 	for(variable=VarManager::varList;variable!=0;variable=variable->next) {
 		if (strcmp(variable->name, name) == 0) {
+#ifdef _DEBUG_
+			Serial.print("ACHOU EM: ");
+			Serial.println(variable->addr);
+#endif
 			if (variable->value == 255) {
 				switch (VarManager::varPersistence) {
 					case 1:
-						return EEPROM.read(variable->addr);
+						val = EEPROM.read(variable->addr);
+						variable->value = val;
 						break;
 					case 2:
-						return RTC.get_sram_byte(variable->addr);
+						val = RTC.get_sram_byte(variable->addr);
+						variable->value = val;
 						break;
 				}
 			}
 		}
 	}
-	return 255;
+#ifdef _DEBUG_
+	Serial.print("val: ");
+	Serial.println(val);
+#endif
+
+	return val;
 }
 
 void VarManager::setVarValue(char name[MAXVARLEN], int value) {
 	varElement *variable;
+
+#ifdef _DEBUG_
+	Serial.print("SETTING: ");
+	Serial.println(name);
+#endif
+
 	for(variable=VarManager::varList;variable!=0;variable=variable->next) {
 		if (strcmp(variable->name, name) == 0) {
+#ifdef _DEBUG_
+			Serial.print("ACHOU EM: ");
+			Serial.println(variable->addr);
+#endif
 			switch (VarManager::varPersistence) {
 				case 1:
+#ifdef _DEBUG_
+					Serial.print("val: ");
+					Serial.println(value);
+#endif
 					EEPROM.write(variable->addr, value);
 					break;
 				case 2:
+#ifdef _DEBUG_
+					Serial.print("val: ");
+					Serial.println(value);
+#endif
 					RTC.set_sram_byte(variable->addr, value);
 					break;
 			}