-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCSettings.cpp
More file actions
174 lines (150 loc) · 3.66 KB
/
CSettings.cpp
File metadata and controls
174 lines (150 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "CSettings.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include<boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
CSettings::CSettings()
{
mFaceInterval = 20;
mSlideInterval = 20;
mRandomVidInterval = 5;
mSlideShow = false;
mRandomwVids = false;
mVoiceRecognition = false;
}
bool CSettings::LoadFile(std::string filename)
{
ifstream file(filename.c_str(), ios::in);
if (!file.is_open())
{
printf("Can't find config file.\n");
return(false);
}
string line;
int i = 1;
while (getline(file, line))
{
boost::algorithm::replace_all(line, "\r", "");
boost::algorithm::replace_all(line, "\n", "");
const char c[2] = ":";
char* tok;
tok = strtok((char*)line.c_str(), c);
if (tok != NULL)
{
std::string key;
std::string value;
key = tok;
tok = strtok(NULL, c);
if (tok != NULL)
{
value = tok;
if (key == "FaceInterval")
{
mFaceInterval = atoi(value.c_str());
}
else if (key == "Slideshow")
{
mSlideShow = false;
if (value == "1")
mSlideShow = true;
}
else if (key == "SlideInterval")
{
mSlideInterval = atoi(value.c_str());
}
else if (key == "RandomVideo")
{
mRandomwVids = false;
if (value == "1")
mRandomwVids = true;
}
else if (key == "RandomVideoInterval")
{
mRandomVidInterval = atoi(value.c_str());
}
else if (key == "VoiceRecognition")
{
mVoiceRecognition = false;
if (value == "1")
mVoiceRecognition = true;
}
}
}
++i;
}
file.close();
return(true);
}
bool CSettings::SaveFile(std::string filename)
{
ofstream ofile(filename.c_str(), ios::out);
if (!ofile.is_open())
{
printf("Can't write settings.txt.\n");
return(false);
}
ofile << "FaceInterval:" << mFaceInterval << endl;
ofile << "Slideshow:" << mSlideShow << endl;
ofile << "SlideInterval:" << mSlideInterval << endl;
ofile << "RandomVideo:" << mRandomwVids << endl;
ofile << "RandomVideoInterval:" << mRandomVidInterval << endl;
ofile << "VoiceRecognition:" << mVoiceRecognition << endl;
ofile.close();
return(true);
}
int CSettings::GetAudioSetting(int numid)
{
char message[1000];
char volCmd[1000];
int n;
FILE* cmd = NULL;
if (numid == 1)
{
sprintf(volCmd, "/home/pi/bmos/scripts/getmic.sh");
}
else if (numid == 2)
{
sprintf(volCmd, "/home/pi/bmos/scripts/getvolume.sh");
}
else
{
return(-1);
}
#ifndef WINDOWS
cmd = popen(volCmd, "r");
try
{
fscanf(cmd, "%d", &n);
}
catch (...)
{
n = -1;
}
pclose(cmd);
printf("Cmd: %s\n", volCmd);
printf("n: %d\n", n);
try
{
numid = n;
}
catch(...)
{
numid = -1;
}
#endif
return(numid);
}
int CSettings::SetAudioSetting(int numid, int val)
{
char volCmd[1000];
int n;
FILE* cmd = NULL;
sprintf(volCmd, "/home/pi/bmos/scripts/vol.sh %d %d", val, numid);
#ifndef WINDOWS
system(volCmd);
#endif
return(0);
}