Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi Pico support and organizational changes #155

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding dead radio code for future iteration and use
JonathanSafer committed Jan 22, 2024
commit a461db7fb336f521729f38a57ff150aa3eb16320
39 changes: 39 additions & 0 deletions main/sensors/radio/radio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*************************************************
* This is an interface for all radio functions
*
*************************************************/

#pragma once

#include <Arduino.h>

class Radio
{
public:
/**
* @brief Send a message to the ground station
*
* @param message
*/
void print(String message);

/**
* @brief Send a message to the with an endline to the ground station
*
* @param message
*/
void println(String message);

/**
* @brief Receive a message from the ground station
*
* @return String
*/
String receive();

/**
* @brief Setup the radio
*
*/
void setup();
};
144 changes: 144 additions & 0 deletions main/sensors/radio/rfm9x.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/***************************************************
* This is the radio implementation for the RFM9X
*
**************************************************/

#include "radio.h"

#include <RadioLib.h>

/*
RadioLib RF69 Transmit with Interrupts Example

This example transmits FSK packets with one second delays
between them. Each packet contains up to 64 bytes
of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)

For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231

For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/

// RF69 has the following connections:
// CS pin: 11
// lets try to ignore these two pins for now. In the future, DIO could be useful and maybe there should be a joint RESET for all SPI devices
// DIO0 pin: 2
// RESET pin: 3

// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;

// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;

// this function is called when a complete packet
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
void setFlag(void) {
// we sent a packet, set the flag
transmittedFlag = true;
}

void Radio::setup() {

RFM95 radio = new Module(8, 26, 27, 4294967295UL, SPI);

// initialize RFM95 with default settings
Serial.print(F("[RFM95] Initializing ... "));
int state = radio.begin(915.0);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}

// set the function that will be called
// when packet transmission is finished
radio.setPacketSentAction(setFlag);

// NOTE: some RF69 modules use high power output,
// those are usually marked RF69H(C/CW).
// To configure RadioLib for these modules,
// you must call setOutputPower() with
// second argument set to true.
/*
Serial.print(F("[RF69] Setting high power module ... "));
state = radio.setOutputPower(20, true);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
*/

// start transmitting the first packet
Serial.print(F("[RF69] Sending first packet ... "));

// you can transmit C-string or Arduino string up to
// 64 characters long
transmissionState = radio.startTransmit("Hello World!");

// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}

void Radio::println(String message) {
// check if the previous transmission finished
if(transmittedFlag) {
// reset flag
transmittedFlag = false;

if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()

} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);

}

// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
//TODO: radio.finishTransmit();

// wait a second before transmitting again
delay(1000);

// send another one
Serial.print(F("[RF69] Sending another packet ... "));

// you can transmit C-string or Arduino string up to
// 64 characters long
// TODO: we should check message length here

//TODO: transmissionState = radio.startTransmit(message);

// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
transmissionState = radio.startTransmit(byteArr, 8);
*/
}
}