| Wheelchair Control for Windows Mobile Diploma Thesis, Author: Ondrej Vozda, FEEC BUT, 2013

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
SettingsClass.cs
1 ﻿using System;
2 using System.Net;
3 using System.IO;
4
5 namespace WheelchairControlWM
6 {
10 [Serializable]
11 public class SettingsClass
12 {
13 #region Constants
14
18 private const String DEFAULT_CONFIG_FILE_ADDRESS = @"\WheelchairControlSettings.ini";
19
20 #endregion
21
22 #region Private variables
23
27 private IPAddress targetIp = null;
28
32 private Byte gain = 0;
33
37 private Boolean resetIdleTimer = true;
38
42 private Boolean enableRemoteStart = true;
43
44 #endregion
45
46 #region Properties
47
51 public IPAddress TargetIP
52 {
53 get { return targetIp; }
54 set { targetIp = value; }
55 }
56
60 public Byte Gain
61 {
62 get { return gain; }
63 set { gain = value; }
64 }
65
69 public Boolean ResetIdleTimerEnabled
70 {
71 get { return resetIdleTimer; }
72 set { resetIdleTimer = value; }
73 }
74
78 public Boolean RemoteStartEnabled
79 {
80 get { return enableRemoteStart; }
81 set { enableRemoteStart = value; }
82 }
83
84 #endregion
85
91 public SettingsClass()
92 {
93 StreamReader reader = null;
94
95 try
96 {
97 reader = new StreamReader(DEFAULT_CONFIG_FILE_ADDRESS);
98
99 //Read IP
100 targetIp = IPAddress.Parse(reader.ReadLine());
101
102 //Read gain
103 gain = Byte.Parse(reader.ReadLine());
104
105 //Read idle timer enable status
106 resetIdleTimer = Boolean.Parse(reader.ReadLine());
107
108 //Read remote start enable status
109 enableRemoteStart = Boolean.Parse(reader.ReadLine());
110 }
111 catch (Exception)
112 {
113 //Use ActiveSync default address
114 if(targetIp == null)
115 targetIp = IPAddress.Parse("169.254.2.0");
116
117 //Other values assigned during initialization
118 }
119 finally
120 {
121 if (reader != null)
122 reader.Close();
123 }
124 }
125
130 public void Save()
131 {
132 StreamWriter writer = null;
133
134 try
135 {
136 //New file writer, always overwrites old file!
137 writer = new StreamWriter(DEFAULT_CONFIG_FILE_ADDRESS, false);
138
139 //Write IP
140 writer.WriteLine(targetIp.ToString());
141
142 //Write gain
143 writer.WriteLine(gain.ToString());
144
145 //Write idle timer enable status
146 writer.WriteLine(resetIdleTimer.ToString());
147
148 //Write remote start enable status
149 writer.WriteLine(enableRemoteStart.ToString());
150 }
151 catch (Exception)
152 {
153 //Pass exception
154 throw;
155 }
156 finally
157 {
158 if(writer != null)
159 writer.Close();
160 }
161 }
162 }
163 }