Guys,
One of the functions I’m implementing on a Cobra is a programmable thermostat. A friend of mine suggested me to use Hashtables to store the various times/temps but I can’t figure out the time part. Also, I’m not sure how to persist this to a file on SD storage.
Here’s the code i have so far:
private double Setpoint()
{
Hashtable _Mon = new Hashtable();
_Mon.Add("07:00", 21.00);
_Mon.Add("09:00", 20.00);
_Mon.Add("19:00", 21.00);
_Mon.Add("23:00", 16.00);
Hashtable _Tue = new Hashtable();
_Tue.Add("07:00", 21.00);
_Tue.Add("09:00", 20.00);
_Tue.Add("19:00", 21.00);
_Tue.Add("23:00", 16.00);
Hashtable _Wed = new Hashtable();
_Wed.Add("07:00", 21.00);
_Wed.Add("09:00", 20.00);
_Wed.Add("19:00", 21.00);
_Wed.Add("23:00", 16.00);
Hashtable _Thu = new Hashtable();
_Thu.Add("07:00", 21.00);
_Thu.Add("09:00", 20.00);
_Thu.Add("19:00", 21.00);
_Thu.Add("23:00", 16.00);
Hashtable _Fri = new Hashtable();
_Fri.Add("07:00", 21.00);
_Fri.Add("09:00", 20.00);
_Fri.Add("19:00", 21.00);
_Fri.Add("23:00", 16.00);
Hashtable _Sat = new Hashtable();
_Sat.Add("09:00", 21.00);
_Sat.Add("23:00", 16.00);
Hashtable _Sun = new Hashtable();
_Sun.Add("09:00", 21.00);
_Sun.Add("23:00", 16.00);
Hashtable _weekdays = new Hashtable();
_weekdays.Add("Monday", _Mon);
_weekdays.Add("Tuesday", _Tue);
_weekdays.Add("Wednesday", _Wed);
_weekdays.Add("Thursday", _Thu);
_weekdays.Add("Friday", _Fri);
_weekdays.Add("Saturday", _Sat);
_weekdays.Add("Sunday", _Sun);
Hashtable today = _weekdays[DateTime.Now.DayOfWeek.ToString()] as Hashtable;
double setpoint = 0.0;
foreach (DictionaryEntry time in today)
{
// Find the setpoint in today's hashtable depending on the current time
}
Console.WriteLine("setpoint= " + setpoint);
return setpoint;
}
For example, if it is now Wednesday 14:45h, setpoint should be 20.00
From 23:00 till 7:00 it should return 16.00
Any suggestion or improvement is very welcome. I’m not a C# guru, but trying to learn as fast as I can.
Thanks in advance