ZZ-Cat / CRSFforArduino

An Arduino Library for communicating with ExpressLRS and TBS Crossfire receivers.
GNU Affero General Public License v3.0
161 stars 27 forks source link

feat(serial receiver interface): :sparkles: Introduce three new callbacks #134

Closed ddanilchenko closed 2 months ago

ddanilchenko commented 3 months ago
 ...
   outputSerial.begin(CRSF_BAUD_RATE, SERIAL_8N1, TX_PIN2, RX_PIN2);

    // Initialise CRSF for Arduino.
    crsfInput0 = new CRSFforArduino(&inputSerial0, RX_PIN0, TX_PIN0);
    if (!crsfInput0->begin())
    {
        crsfInput0->end();
        delete crsfInput0;
        crsfInput0 = nullptr;

        Serial.println("CRSF0 for Arduino initialisation failed!");
        while (1)
        {
            delay(10);
        }
    }

    rcChannelCount = rcChannelCount > crsfProtocol::RC_CHANNEL_COUNT ? crsfProtocol::RC_CHANNEL_COUNT : rcChannelCount;

    crsfInput0->setLinkStatisticsCallback(onLinkStatisticsUpdate0);

    crsfInput0->setRawDataCallback(onRawDataCallback0);
    crsfInput0->setLinkUpCallback(onLink0UpCallback);
    crsfInput0->setLinkDownCallback(onLink0DownCallback);

...

void onLinkStatisticsUpdate0(serialReceiverLayer::link_statistics_t linkStatistics)
{
    if (millis() - lastUpdateLQ0 >= LINK_QUALITY_UPDATE_INTERVAL)
    {
        lastUpdateLQ0 = millis();
        Serial.print("Link Statistics0: ");
        Serial.print("RSSI: ");
        Serial.print(linkStatistics.rssi);
        Serial.print(", Link Quality: ");
        Serial.print(linkStatistics.lqi);
        Serial.print(", Signal-to-Noise Ratio: ");
        Serial.print(linkStatistics.snr);
        Serial.print(", Transmitter Power: ");
        Serial.println(linkStatistics.tx_power);
    }
}

...

void onRawDataCallback0(int8_t byteReceived)
{
    Serial.println("primary channel passthrough");
    outputSerial.write(byteReceived);
}

...

void onLink0DownCallback()
{
  Serial.println("main link is down");
}

void onLink0UpCallback()
{
    Serial.println("main link is up");
}
ZZ-Cat commented 2 months ago

Before I run my CodeQL and Quality Control workflows on this, can you change the base branch from Main-Trunk to Version-1.1.0-Development?

Also, in your Pull Request description, can you clarify what each callback does and their purpose?

ddanilchenko commented 2 months ago

Before I run my CodeQL and Quality Control workflows on this, can you change the base branch from Main-Trunk to Version-1.1.0-Development?

Also, in your Pull Request description, can you clarify what each callback does and their purpose?

done. modified the initial comment for the PR. please have as look. a few words about onrawdatareceived. the main purpose of it is to add possibility of handling raw data received by the instance of the SerialReceiver class. in my case i used it to implement seamless integration with fc, e.g. read data from rx, handle crsf packages and bypass raw data to fc.