This repository was archived by the owner on May 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmain.cpp
More file actions
101 lines (88 loc) · 3.03 KB
/
Copy pathmain.cpp
File metadata and controls
101 lines (88 loc) · 3.03 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
/**
* @file main.cpp
* @author Cassandra "ZZ Cat" Robinson (nicad.heli.flier@gmail.com)
* @brief This is the main development file for CRSF for Arduino.
*
* @copyright Copyright (c) 2024, Cassandra "ZZ Cat" Robinson. All rights reserved.
*
* @section License GNU Affero General Public License v3.0
* This source file is a part of the CRSF for Arduino library.
* CRSF for Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CRSF for Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CRSF for Arduino. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "Arduino.h"
#include "CRSFforArduino.hpp"
CRSFforArduino *crsf = nullptr;
void onReceiveRcChannels(serialReceiverLayer::rcChannels_t *rcChannels);
void setup()
{
Serial.begin(115200);
while (!Serial)
{
delay(10);
}
crsf = new CRSFforArduino();
if (!crsf->begin())
{
Serial.println("CRSF for Arduino failed to initialise.");
delete crsf;
crsf = nullptr;
while (1)
{
delay(10);
}
}
crsf->setRcChannelsCallback(onReceiveRcChannels);
}
void loop()
{
crsf->update();
}
void onReceiveRcChannels(serialReceiverLayer::rcChannels_t *rcChannels)
{
static unsigned long lastPrint = millis();
if (millis() - lastPrint >= 100)
{
lastPrint = millis();
static bool initialised = false;
static bool lastFailSafe = false;
if (rcChannels->failsafe != lastFailSafe || !initialised)
{
initialised = true;
lastFailSafe = rcChannels->failsafe;
Serial.print("FailSafe: ");
Serial.println(lastFailSafe ? "Active" : "Inactive");
}
if (rcChannels->failsafe == false)
{
Serial.print("RC Channels <A: ");
Serial.print(crsf->rcToUs(rcChannels->value[0]));
Serial.print(", E: ");
Serial.print(crsf->rcToUs(rcChannels->value[1]));
Serial.print(", T: ");
Serial.print(crsf->rcToUs(rcChannels->value[2]));
Serial.print(", R: ");
Serial.print(crsf->rcToUs(rcChannels->value[3]));
Serial.print(", Aux1: ");
Serial.print(crsf->rcToUs(rcChannels->value[4]));
Serial.print(", Aux2: ");
Serial.print(crsf->rcToUs(rcChannels->value[5]));
Serial.print(", Aux3: ");
Serial.print(crsf->rcToUs(rcChannels->value[6]));
Serial.print(", Aux4: ");
Serial.print(crsf->rcToUs(rcChannels->value[7]));
Serial.println(">");
}
}
}