/[ThermoControl]/trunk/libThermoControl/Controller.cs
ViewVC logotype

Contents of /trunk/libThermoControl/Controller.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations) (download)
Wed Nov 13 02:22:43 2013 UTC (7 years, 7 months ago) by william
File size: 3876 byte(s)

1 #define LOG_DEBUG
2
3 using System;
4 using System.Collections.Generic;
5 using System.Diagnostics;
6 using System.Linq;
7 using System.Text;
8
9 namespace libThermoControl
10 {
11 public interface IController
12 {
13 //int CurrentTemperature { get; }
14 void SetDefaultTemperature();
15 void SetTemperature(int temp);
16 }
17 public class Controller : IController
18 {
19 public Controller()
20 {
21
22 }
23 #region IController members
24 //private int _CurrentTemperature;
25 //public int CurrentTemperature { get { return _CurrentTemperature; } private set { _CurrentTemperature = value; } }
26
27 public void SetDefaultTemperature()
28 {
29 //int temp_current = CurrentTemperature;
30 //int temp_default = Configuration.DEFAULT_TEMP;
31 //int temp_offset = temp_default - temp_current;
32 //LogDebugMessage("Controller.ResetTemperature():");
33 //LogDebugMessage("\tCurrent: {0}", temp_current);
34 //LogDebugMessage("\tDefault: {0}", temp_default);
35 //LogDebugMessage("\tOffset: {0}", temp_offset);
36 SetTemperature(Configuration.DEFAULT_TEMP);
37 }
38 public void SetTemperature(int temp)
39 {
40 if (temp < Configuration.MIN_TEMP || temp > Configuration.MAX_TEMP)
41 {
42 throw new ArgumentOutOfRangeException(string.Format("Cannot set temperature to: '{0}' ... Range is: '{1}' to '{2}'",temp, Configuration.MIN_TEMP, Configuration.MAX_TEMP));
43 }
44 int temp_current = Configuration.CurrentTemp;
45 int temp_offset = temp - temp_current;
46 //LogDebugMessage("Controller.SetTemperature(int temp):");
47 //LogDebugMessage("\tCurrent: {0}", temp_current);
48 //LogDebugMessage("\ttemp: {0}", temp);
49 //LogDebugMessage("\tOffset: {0}", temp_offset);
50 ChangeTemp(temp, temp_offset);
51 }
52 #endregion
53
54 private void ChangeTemp(int temp, int temp_offset)
55 {
56 LogDebugMessage("Controller.ChangeTemp(int temp, int temp_offset):");
57 LogDebugMessage("\tSetting Temperature to: {0} ({1})", temp, temp_offset);
58 if (OffsetIsNegative(temp_offset))
59 {
60 //LogDebugMessage("\tOffset is Negative");
61 string button = ThermistatControls.GetButtonByValue(ACControls.TEMP_TIMER_DOWN).ButtonName;
62 for (int i = 0; i < Math.Abs(temp_offset); i++)
63 {
64 //System.Hardware.IR.Blaster.LMRemoteKeyMap.Blast(Configuration.THERMISTAT_DEVICE, button);
65 Blaster.BlastCommand(Configuration.THERMISTAT_DEVICE, button);
66 }
67 }
68 else
69 {
70 //LogDebugMessage("\tOffset is Positive");
71 string button = ThermistatControls.GetButtonByValue(ACControls.TEMP_TIMER_UP).ButtonName;
72 for (int i = 0; i < Math.Abs(temp_offset); i++)
73 {
74 //System.Hardware.IR.Blaster.LMRemoteKeyMap.Blast(Configuration.THERMISTAT_DEVICE, button);
75 Blaster.BlastCommand(Configuration.THERMISTAT_DEVICE, button);
76 }
77 }
78 Configuration.CurrentTemp = temp;
79 }
80
81 private bool OffsetIsNegative(int temp_offset)
82 {
83 return (Math.Abs(temp_offset) != temp_offset);
84 }
85
86 [Conditional("LOG_DEBUG")]
87 private void LogDebugMessage(string format)
88 {
89 LogDebugMessage(format, new object[0]);
90 }
91 [Conditional("LOG_DEBUG")]
92 private void LogDebugMessage(string format, params object[] args)
93 {
94 Console.WriteLine(format, args);
95 }
96 }
97 }

  ViewVC Help
Powered by ViewVC 1.1.22