5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #include "pulses/multi.h"
24 uint8_t storageDirtyMsk
;
25 tmr10ms_t storageDirtyTime10ms
;
27 #if defined(RTC_BACKUP_RAM)
28 uint8_t rambackupDirtyMsk
;
29 tmr10ms_t rambackupDirtyTime10ms
;
32 void storageDirty(uint8_t msk
)
34 storageDirtyMsk
|= msk
;
35 storageDirtyTime10ms
= get_tmr10ms();
37 #if defined(RTC_BACKUP_RAM)
38 rambackupDirtyMsk
= storageDirtyMsk
;
39 rambackupDirtyTime10ms
= storageDirtyTime10ms
;
45 watchdogSuspend(500/*5s*/);
51 if (pulsesStarted()) {
55 pauseMixerCalculations();
58 void postRadioSettingsLoad()
61 if (is_memclear(g_eeGeneral
.ownerRegistrationID
, PXX2_LEN_REGISTRATION_ID
)) {
67 #if defined(EXTERNAL_ANTENNA) && defined(INTERNAL_MODULE_PXX1)
68 void onAntennaSelection(const char * result
)
70 if (result
== STR_USE_INTERNAL_ANTENNA
) {
71 globalData
.externalAntennaEnabled
= false;
73 else if (result
== STR_USE_EXTERNAL_ANTENNA
) {
74 globalData
.externalAntennaEnabled
= true;
77 checkExternalAntenna();
81 void onAntennaSwitchConfirm(const char * result
)
83 if (result
== STR_OK
) {
84 // Switch to external antenna confirmation
85 globalData
.externalAntennaEnabled
= true;
89 void checkExternalAntenna()
91 if (isModuleXJT(INTERNAL_MODULE
)) {
92 if (g_eeGeneral
.antennaMode
== ANTENNA_MODE_EXTERNAL
) {
93 globalData
.externalAntennaEnabled
= true;
95 else if (g_eeGeneral
.antennaMode
== ANTENNA_MODE_PER_MODEL
&& g_model
.moduleData
[INTERNAL_MODULE
].pxx
.antennaMode
== ANTENNA_MODE_EXTERNAL
) {
96 if (!globalData
.externalAntennaEnabled
) {
97 POPUP_CONFIRMATION(STR_ANTENNACONFIRM1
, onAntennaSwitchConfirm
);
98 SET_WARNING_INFO(STR_ANTENNACONFIRM2
, sizeof(TR_ANTENNACONFIRM2
), 0);
101 else if (g_eeGeneral
.antennaMode
== ANTENNA_MODE_ASK
|| (g_eeGeneral
.antennaMode
== ANTENNA_MODE_PER_MODEL
&& g_model
.moduleData
[INTERNAL_MODULE
].pxx
.antennaMode
== ANTENNA_MODE_ASK
)) {
102 globalData
.externalAntennaEnabled
= false;
103 POPUP_MENU_ADD_ITEM(STR_USE_INTERNAL_ANTENNA
);
104 POPUP_MENU_ADD_ITEM(STR_USE_EXTERNAL_ANTENNA
);
105 POPUP_MENU_START(onAntennaSelection
);
108 globalData
.externalAntennaEnabled
= false;
112 globalData
.externalAntennaEnabled
= false;
117 void postModelLoad(bool alarms
)
120 if (is_memclear(g_model
.modelRegistrationID
, PXX2_LEN_REGISTRATION_ID
)) {
121 memcpy(g_model
.modelRegistrationID
, g_eeGeneral
.ownerRegistrationID
, PXX2_LEN_REGISTRATION_ID
);
125 #if defined(HARDWARE_INTERNAL_MODULE)
126 if (!isInternalModuleAvailable(g_model
.moduleData
[INTERNAL_MODULE
].type
)) {
127 memclear(&g_model
.moduleData
[INTERNAL_MODULE
], sizeof(ModuleData
));
129 #if defined(MULTIMODULE)
130 else if (isModuleMultimodule(INTERNAL_MODULE
))
131 multiPatchCustom(INTERNAL_MODULE
);
135 if (!isExternalModuleAvailable(g_model
.moduleData
[EXTERNAL_MODULE
].type
)) {
136 memclear(&g_model
.moduleData
[EXTERNAL_MODULE
], sizeof(ModuleData
));
138 #if defined(MULTIMODULE)
139 else if (isModuleMultimodule(EXTERNAL_MODULE
))
140 multiPatchCustom(EXTERNAL_MODULE
);
146 customFunctionsReset();
150 for (int i
=0; i
<MAX_TELEMETRY_SENSORS
; i
++) {
151 TelemetrySensor
& sensor
= g_model
.telemetrySensors
[i
];
152 if (sensor
.type
== TELEM_TYPE_CALCULATED
&& sensor
.persistent
) {
153 telemetryItems
[i
].value
= sensor
.persistentValue
;
154 telemetryItems
[i
].timeout
= 0; // make value visible even before the first new value is received)
157 telemetryItems
[i
].timeout
= TELEMETRY_SENSOR_TIMEOUT_UNAVAILABLE
;
163 resumeMixerCalculations();
164 if (pulsesStarted()) {
175 referenceModelAudioFiles();
178 #if defined(PCBHORUS)
183 LUA_LOAD_MODEL_SCRIPTS();
188 void storageFlushCurrentModel()
192 for (int i
=0; i
<MAX_TELEMETRY_SENSORS
; i
++) {
193 TelemetrySensor
& sensor
= g_model
.telemetrySensors
[i
];
194 if (sensor
.type
== TELEM_TYPE_CALCULATED
&& sensor
.persistent
&& sensor
.persistentValue
!= telemetryItems
[i
].value
) {
195 sensor
.persistentValue
= telemetryItems
[i
].value
;
196 storageDirty(EE_MODEL
);
200 if (g_model
.potsWarnMode
== POTS_WARN_AUTO
) {
201 for (int i
=0; i
<NUM_POTS
+NUM_SLIDERS
; i
++) {
202 if (!(g_model
.potsWarnEnabled
& (1 << i
))) {
203 SAVE_POT_POSITION(i
);
206 storageDirty(EE_MODEL
);