@@ -51,6 +51,11 @@ int i = 0;
5151 int OAT = 0 ;
5252 int Humidity = 0 ;
5353
54+ // Backup battery data
55+ unsigned int BAT_Voltage = 0 ;
56+ byte BAT_Status = 0 ;
57+ int BAT_Temperature = 0 ;
58+
5459 unsigned int Airspeed = 0 ;
5560// int VerticalSpeed = 0;
5661 int AoA = 0 ;
@@ -77,16 +82,20 @@ const unsigned int CAN_AoA_Msg_ID = 41; // CAN Msg ID in DEC
7782const unsigned int CAN_OAT_Msg_ID = 42 ; // CAN Msg ID in DEC
7883const unsigned int CAN_RAW_Msg_ID = 43 ; // CAN Msg ID in DEC
7984const unsigned int CAN_QNH_Msg_ID = 46 ; // CAN Msg ID in DEC
85+ const unsigned int CAN_BAT_Msg_ID = 86 ; // CAN Msg ID in DEC
8086const unsigned int CAN_Air_Period = 300 ; // How often message sent in milliseconds
8187const unsigned int CAN_AoA_Period = 200 ; // How often message sent in milliseconds
8288const unsigned int CAN_OAT_Period = 2000 ; // How often message sent in milliseconds
8389const unsigned int CAN_RAW_Period = 500 ; // How often message sent in milliseconds
8490const unsigned int CAN_QNH_Period = 5000 ;
91+ const unsigned int CAN_BAT_Period = 3000 ; // How often message sent in milliseconds
8592unsigned long CAN_Air_Timestamp = 0 ; // when was the last message sent
8693unsigned long CAN_AoA_Timestamp = 0 ; // when was the last message sent
8794unsigned long CAN_OAT_Timestamp = 0 ; // when was the last message sent
8895unsigned long CAN_RAW_Timestamp = 0 ; // when was the last message sent
8996unsigned long CAN_QNH_Timestamp = 0 ;
97+ unsigned long CAN_BAT_Timestamp = 0 ; // when was the last message sent
98+
9099int QNH_MemOffset = 0 ;
91100
92101unsigned char len = 0 ;
@@ -98,6 +107,8 @@ MCP_CAN CAN(CAN_CS_PIN); // Set CS pin
98107void setup ()
99108{
100109 Wire.begin (); // wake up I2C bus
110+ pinMode (7 , INPUT_PULLUP );
111+ pinMode (9 , INPUT_PULLUP );
101112 delay (50 );
102113 Serial.begin (115200 );
103114
@@ -238,15 +249,40 @@ if (millis() > CAN_RAW_Timestamp + CAN_RAW_Period + random(0, 50)) {
238249// QNH is stored in this module as well as Display modules where it can be changed.
239250// Latest change in the Display module overwrites the QNH value on all devices.
240251// The QNH gets re-broadcasted in case one of the units goes down
241- if (millis () > CAN_QNH_Timestamp + CAN_QNH_Period) {
252+ // !!!!!!!!!!!!!! QNH re-broadcasting has been removed as unnnecesary !!!!!!!!!!!!!
253+ // !!!!!!!!!!!! re-broadcasting code left commented out pending testing !!!!!!!!!!!
254+ /* if (millis() > CAN_QNH_Timestamp + CAN_QNH_Period) {
242255
243256 Send_QNH();
244257 CAN_QNH_Timestamp = millis();
245258
246259}
260+ */
261+
262+ /*
263+ * The section below does not belong to Module A (air pressure data)
264+ * The data below is most suitable for EMS module
265+ * EMS module does not have analog inputs left available
266+ * so the backup battery data will be capured bu this module until EMS module expanded (one day)
267+ */
247268
269+ // Send Backup Battery data
270+ if (millis () > CAN_BAT_Timestamp + CAN_BAT_Period + random (0 , 100 )) {
271+
272+ Get_BAT ();
273+
274+ canMsg[0 ] = BAT_Voltage;
275+ canMsg[1 ] = BAT_Voltage >> 8 ;
248276
277+ canMsg[2 ] = BAT_Status;
278+
279+ canMsg[3 ] = BAT_Temperature;
280+
281+ CAN .sendMsgBuf (CAN_BAT_Msg_ID, 0 , 4 , canMsg);
282+
283+ CAN_BAT_Timestamp = millis ();
249284
285+ }
250286
251287
252288}
0 commit comments