-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added skyzone onboard ESP32-PICO target (#71)
* Added skyzone onboard ESP32-PICO target * Pass current time into module loop to avoid extra calls to millis() * Rename DIY skyzone target to avoid confusion * Undef redefined boot delay to avoid throwing compiler warning
- Loading branch information
Showing
19 changed files
with
274 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "module_base.h" | ||
|
||
void | ||
ModuleBase::Init() | ||
{ | ||
delay(VRX_BOOT_DELAY); | ||
} | ||
|
||
void | ||
ModuleBase::SendIndexCmd(uint8_t index) | ||
{ | ||
} | ||
|
||
void | ||
ModuleBase::SetRecordingState(uint8_t recordingState, uint16_t delay) | ||
{ | ||
} | ||
|
||
void | ||
ModuleBase::Loop(uint32_t now) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
|
||
#define VRX_BOOT_DELAY 0 | ||
|
||
class ModuleBase | ||
{ | ||
public: | ||
void Init(); | ||
void SendIndexCmd(uint8_t index); | ||
void SetRecordingState(uint8_t recordingState, uint16_t delay); | ||
void Loop(uint32_t now); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#include "skyzone_msp.h" | ||
#include "logging.h" | ||
#include <Arduino.h> | ||
|
||
SkyzoneMSP::SkyzoneMSP(Stream *port) | ||
{ | ||
m_port = port; | ||
} | ||
|
||
void | ||
SkyzoneMSP::Init() | ||
{ | ||
ModuleBase::Init(); | ||
m_delay = 0; | ||
} | ||
|
||
void | ||
SkyzoneMSP::SendIndexCmd(uint8_t index) | ||
{ | ||
uint8_t retries = 3; | ||
while (GetChannelIndex() != index && retries > 0) | ||
{ | ||
SetChannelIndex(index); | ||
retries--; | ||
} | ||
} | ||
|
||
uint8_t | ||
SkyzoneMSP::GetChannelIndex() | ||
{ | ||
MSP msp; | ||
mspPacket_t* packet = new mspPacket_t; | ||
packet->reset(); | ||
packet->makeCommand(); | ||
packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; | ||
|
||
// Send request, then wait for a response back from the VRX | ||
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT); | ||
|
||
if (receivedResponse) | ||
{ | ||
packet = msp.getReceivedPacket(); | ||
return packet->readByte(); | ||
} | ||
|
||
DBGLN("Skyzone module: Exceeded timeout while waiting for channel index response"); | ||
return CHANNEL_INDEX_UNKNOWN; | ||
} | ||
|
||
void | ||
SkyzoneMSP::SetChannelIndex(uint8_t index) | ||
{ | ||
MSP msp; | ||
mspPacket_t packet; | ||
packet.reset(); | ||
packet.makeCommand(); | ||
packet.function = MSP_ELRS_BACKPACK_SET_CHANNEL_INDEX; | ||
packet.addByte(index); // payload | ||
|
||
msp.sendPacket(&packet, m_port); | ||
} | ||
|
||
uint8_t | ||
SkyzoneMSP::GetRecordingState() | ||
{ | ||
MSP msp; | ||
mspPacket_t* packet = new mspPacket_t; | ||
packet->reset(); | ||
packet->makeCommand(); | ||
packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE; | ||
|
||
// Send request, then wait for a response back from the VRX | ||
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT); | ||
|
||
if (receivedResponse) | ||
{ | ||
packet = msp.getReceivedPacket(); | ||
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE; | ||
} | ||
|
||
DBGLN("Skyzone module: Exceeded timeout while waiting for recording state response"); | ||
return VRX_DVR_RECORDING_UNKNOWN; | ||
} | ||
|
||
void | ||
SkyzoneMSP::SetRecordingState(uint8_t recordingState, uint16_t delay) | ||
{ | ||
DBGLN("SetRecordingState = %d delay = %d", recordingState, delay); | ||
|
||
m_recordingState = recordingState; | ||
m_delay = delay * 1000; // delay is in seconds, convert to milliseconds | ||
m_delayStartMillis = millis(); | ||
|
||
if (m_delay == 0) | ||
{ | ||
SendRecordingState(); | ||
} | ||
} | ||
|
||
void | ||
SkyzoneMSP::SendRecordingState() | ||
{ | ||
DBGLN("SendRecordingState = %d delay = %d", m_recordingState, m_delay); | ||
|
||
MSP msp; | ||
mspPacket_t packet; | ||
packet.reset(); | ||
packet.makeCommand(); | ||
packet.function = MSP_ELRS_BACKPACK_SET_RECORDING_STATE; | ||
packet.addByte(m_recordingState); | ||
packet.addByte(m_delay & 0xFF); // delay byte 1 | ||
packet.addByte(m_delay >> 8); // delay byte 2 | ||
|
||
msp.sendPacket(&packet, m_port); | ||
} | ||
|
||
void | ||
SkyzoneMSP::Loop(uint32_t now) | ||
{ | ||
// Handle delay timer for SendRecordingState() | ||
if (m_delay != 0) | ||
{ | ||
if (now - m_delayStartMillis >= m_delay) | ||
{ | ||
SendRecordingState(); | ||
m_delay = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "msp.h" | ||
#include "msptypes.h" | ||
#include "module_base.h" | ||
#include <Arduino.h> | ||
|
||
#undef VRX_BOOT_DELAY | ||
#define VRX_BOOT_DELAY 2000 | ||
|
||
#define VRX_RESPONSE_TIMEOUT 500 | ||
#define VRX_UART_BAUD 115200 // skyzone uses 115k baud between the ESP32-PICO and their MCU | ||
|
||
#define CHANNEL_INDEX_UNKNOWN 255 | ||
#define VRX_DVR_RECORDING_ACTIVE 1 | ||
#define VRX_DVR_RECORDING_INACTIVE 0 | ||
#define VRX_DVR_RECORDING_UNKNOWN 255 | ||
|
||
class SkyzoneMSP : public ModuleBase | ||
{ | ||
public: | ||
SkyzoneMSP(Stream *port); | ||
void Init(); | ||
void SendIndexCmd(uint8_t index); | ||
uint8_t GetChannelIndex(); | ||
void SetChannelIndex(uint8_t index); | ||
uint8_t GetRecordingState(); | ||
void SetRecordingState(uint8_t recordingState, uint16_t delay); | ||
void Loop(uint32_t now); | ||
|
||
private: | ||
void SendRecordingState(); | ||
|
||
Stream *m_port; | ||
uint8_t m_recordingState; | ||
uint16_t m_delay; | ||
uint32_t m_delayStartMillis; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.