-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmfdpage.cpp
More file actions
190 lines (177 loc) · 6.91 KB
/
mfdpage.cpp
File metadata and controls
190 lines (177 loc) · 6.91 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <map>
#include <iostream>
#include <math.h>
#include "include/out.h"
#include "include/data.h"
#include "include/fms.h"
#include "include/in.h"
#include "include/config.h"
#include "include/mfdpage.h"
#include "include/mfdpage_fms.h"
#include "include/mfdpage_flight.h"
#include "include/mfdpage_weather.h"
#include "include/mfdpage_std.h"
#include "include/mfdpage_time.h"
#include "include/mfdpage_led.h"
#include "include/SDK/XPLMProcessing.h"
#include "include/SDK/XPLMDataAccess.h"
using std::map;
using std::string;
// mfdpages
mfdpages_t::mfdpages_t(out_t* out,in_t* in,data_t* dataconnection,fms_t* fms_ref)
{
a_in = in;
a_out = out;
a_dataconnection = dataconnection;
a_fms_ref = fms_ref;
}
mfdpages_t::~mfdpages_t(void)
{
debug_out(debug, "mfdpages: deleting all the mfd pages");
a_in->delete_all_pages();
}
void mfdpages_t::load(void)
{
a_in->delete_all_pages(); // delete all the existing pages
config_t * a_config = config_t::getInstance();
map<string,string> config=a_config->get_config();
map<string,int> buttons;
buttons["mfdpages_button1"] = 1; buttons["mfdpages_button2"] = 2;
buttons["mfdpages_button3"] = 3; buttons["mfdpages_button4"] = 4;
// Add any custom page
for (map<string,int>::iterator it = buttons.begin(); it != buttons.end(); ++it) {
string button_config = (*it).first;
int button_num = (*it).second;
string s;
string pages = config[button_config];
stringstream stream(pages);
while( getline(stream, s, ',') ) {
if (s.find("fms.") != std::string::npos) a_in->add_page(new mfdpage_t(s.c_str(), a_out, a_dataconnection,button_num,"fms",a_fms_ref));
else if (s.find("flight.") != std::string::npos) a_in->add_page(new mfdpage_t(s.c_str(), a_out, a_dataconnection,button_num,"flight",NULL));
else if (s.find("weather.") != std::string::npos) a_in->add_page(new mfdpage_t(s.c_str(), a_out, a_dataconnection,button_num,"weather",NULL));
else if (s.find("std.") != std::string::npos) a_in->add_page(new mfdpage_t(s.c_str(), a_out, a_dataconnection,button_num,"std",NULL));
else debug_out(warn,"mfdpages: unknown mfdpage class for %s",s.c_str());
}
}
// Add the time page
mfdpage_t* time_page = new mfdpage_t("time", a_out, a_dataconnection,0,"time",NULL);
a_in->add_page(time_page);
time_page->set_active(true);
// Add the led (invisible) page
mfdpage_t* led_page = new mfdpage_t("led", a_out, a_dataconnection,0,"led",NULL);
a_in->add_page(led_page);
led_page->set_active(true);
// Add the FMS refresh (invisible) page
mfdpage_t* fms_refresh_page = new mfdpage_t("fms.refresh", a_out, a_dataconnection,0,"fms",a_fms_ref);
a_in->add_page(fms_refresh_page);
fms_refresh_page->set_active(true);
// Add the welcome page
mfdpage_t* welcome_page = new mfdpage_t("welcome", a_out, a_dataconnection,0,"std",NULL);
a_in->add_page(welcome_page);
welcome_page->set_active(true);
}
////////////////////////////
// mfdpage
mfdpage_t::mfdpage_t(const char* name, out_t* outputdevice, data_t* dataconnection, int button,string type,fms_t* fms_ref)
: a_visible(false), a_outdevice(outputdevice), a_dataconnection(dataconnection)
{
a_button = button;
a_type = type;
a_fms_ref = fms_ref;
if (!name || !strlen(name)) a_name.assign(" -unnamed page- ");
else a_name.assign(name);
a_dataconnection->add_listener(this);
map<int, string> sources;
if (type == "fms") a_page = new mfdpage_fms_t(a_name,a_fms_ref);
if (type == "flight") a_page = new mfdpage_flight_t(a_name);
if (type == "weather") a_page = new mfdpage_weather_t(a_name);
if (type == "std") a_page = new mfdpage_std_t(a_name);
if (type == "time") a_page = new mfdpage_time_t(a_name);
if (type == "led") a_page = new mfdpage_led_t(a_name,outputdevice);
a_template = a_page->get_template(name,sources);
set_datasources(&sources);
debug_out(info,"mfdpage: created page %s for button %d, class %s, refresh %d seconds",a_name.c_str(),button,type.c_str(),a_page->refresh_interval(name));
last_page_update = 0;
}
mfdpage_t::~mfdpage_t(void)
{
remove_datasources();
a_dataconnection->remove_listener(this);
debug_out(debug, "mfdpage: deleted mfdpage {%s} (self: %p)", a_name.c_str(), this);
}
const std::string& mfdpage_t::name(void)
{
return a_name;
}
void mfdpage_t::set_active(bool active)
{
a_visible = active;
if (active) {
for (map<int, object_t*>::iterator it = a_datasources.begin(); it != a_datasources.end(); ++it)
{
(*it).second->mark_dirty();
}
} else { // reset the timestamp for last update so to refresh when cycled back to the page
last_page_update = 0;
}
}
void mfdpage_t::set_datasources(std::map<int, std::string>* sources)
{
if (!sources) return;
a_datasources.clear();
for (map<int, string>::iterator it = sources->begin(); it != sources->end(); ++it)
{
object_t* src;
src = a_dataconnection->add_datasource((*it).second.c_str());
if (src) a_datasources[(*it).first] = src;
}
}
void mfdpage_t::remove_datasources(void)
{
for (map<int, object_t*>::iterator it = a_datasources.begin(); it != a_datasources.end(); ++it)
{
a_dataconnection->remove_datasource((*it).second);
}
a_datasources.clear();
}
bool mfdpage_t::has_object(object_t* source)
{
for (map<int, object_t*>::iterator it = a_datasources.begin(); it != a_datasources.end(); ++it)
{
if ((*it).second->name().c_str() == source->name()) {
return true;
}
}
return false;
}
bool mfdpage_t::refresh(object_t* source)
{
debug_out(all,"mfdpage: page %s (%d) received the updated '%s': %s",a_name.c_str(),a_visible,source->name().c_str(),(const char*)(*source));
a_page->do_refresh(source);
if (a_type == "time" || a_type == "led") return true; // time is always visible
if (!a_visible) return false;
return true;
}
void mfdpage_t::final_refresh(void)
{
time_t now = time(NULL);
debug_out(all, "mfdpage: requested joystick refresh for %s", a_name.c_str());
if (now < (last_page_update + a_page->refresh_interval(a_name)) ) return; // not the time to update
last_page_update=now;
debug_out(debug, "mfdpage: refreshing joystick display (%s)", a_name.c_str());
a_data = a_page->refresh_template(a_name,a_datasources,a_template);
if (a_type == "time") {
debug_out(verbose, "mfdpage: updating time %02d:%02d - %d/%d/%d", a_page->a_time["hour"],a_page->a_time["minute"],a_page->a_date["year"], a_page->a_date["month"], a_page->a_date["day"]);
a_outdevice->a_joystick->set_time(true, a_page->a_time["hour"],a_page->a_time["minute"]);
a_outdevice->a_joystick->set_date(a_page->a_date["year"], a_page->a_date["month"], a_page->a_date["day"]);
} else { // print something on the MFD
a_outdevice->a_joystick->set_textdata(a_data.c_str());
a_outdevice->a_joystick->print();
}
}