Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Macros | |
#define | RETRY_TIME_US 3000000 |
#define | FAILURE_RESTART_US 8000000 |
#define | P2P_LOG(...) |
Functions | |
void | p2pInitialize (p2pInfo *p2p, uint8_t modeId, p2pConCbFn conCbFn, p2pMsgRxCbFn msgRxCbFn, int8_t connectionRssi) |
Initialize the p2p connection protocol. | |
void | p2pSetAsymmetric (p2pInfo *p2p, uint8_t incomingModeId) |
Set the p2p connection protocol to listen for a different mode ID from its own. | |
void | p2pStartConnection (p2pInfo *p2p) |
Start the connection process by sending broadcasts and notify the mode. | |
void | p2pDeinit (p2pInfo *p2p) |
Stop up all timers. | |
void | p2pSendMsg (p2pInfo *p2p, const uint8_t *payload, uint16_t len, p2pMsgTxCbFn msgTxCbFn) |
Send a message from one Swadge to another. This must not be called before the CON_ESTABLISHED event occurs. Message addressing, ACKing, and retries all happen automatically. | |
void | p2pRecvCb (p2pInfo *p2p, const uint8_t *mac_addr, const uint8_t *data, uint8_t len, int8_t rssi) |
This function must be called whenever an ESP NOW packet is received. | |
void | p2pSetDataInAck (p2pInfo *p2p, const uint8_t *ackData, uint8_t ackDataLen) |
Set data to be automatically used as the payload all future ACKs, until the data is cleared. | |
void | p2pClearDataInAck (p2pInfo *p2p) |
Clear any data which was set to be used as the payload in the next ACK. | |
void | p2pSendCb (p2pInfo *p2p, const uint8_t *mac_addr, esp_now_send_status_t status) |
This must be called by whatever function is registered to the Swadge mode's fnEspNowSendCb. | |
playOrder_t | p2pGetPlayOrder (p2pInfo *p2p) |
After the swadge is connected to another, return whether this Swadge is player 1 or player 2. This can be used to determine client/server roles. | |
void | p2pSetPlayOrder (p2pInfo *p2p, playOrder_t order) |
Override whether the Swadge is player 1 or player 2. You probably shouldn't do this, but you might want to for single player modes. | |
#define RETRY_TIME_US 3000000 |
#define FAILURE_RESTART_US 8000000 |
#define P2P_LOG | ( | ... | ) |
void p2pInitialize | ( | p2pInfo * | p2p, |
uint8_t | modeId, | ||
p2pConCbFn | conCbFn, | ||
p2pMsgRxCbFn | msgRxCbFn, | ||
int8_t | connectionRssi ) |
Initialize the p2p connection protocol.
p2p | The p2pInfo struct with all the state information |
modeId | 8 bit mode ID. Must be unique per-swadge mode. |
conCbFn | A function pointer which will be called when connection events occur |
msgRxCbFn | A function pointer which will be called when a packet is received for the swadge mode |
connectionRssi | The strength needed to start a connection with another swadge. A positive value means swadges are quite close. I've seen RSSI go as low as -70. 0 is practically touching |
void p2pSetAsymmetric | ( | p2pInfo * | p2p, |
uint8_t | incomingModeId ) |
Set the p2p connection protocol to listen for a different mode ID from its own.
p2p | The p2pInfo struct with all the state information |
incomingModeId | The unique mode ID used by the other end of this connection |
void p2pStartConnection | ( | p2pInfo * | p2p | ) |
Start the connection process by sending broadcasts and notify the mode.
p2p | The p2pInfo struct with all the state information |
void p2pDeinit | ( | p2pInfo * | p2p | ) |
Stop up all timers.
p2p | The p2pInfo struct with all the state information |
void p2pSendMsg | ( | p2pInfo * | p2p, |
const uint8_t * | payload, | ||
uint16_t | len, | ||
p2pMsgTxCbFn | msgTxCbFn ) |
Send a message from one Swadge to another. This must not be called before the CON_ESTABLISHED event occurs. Message addressing, ACKing, and retries all happen automatically.
p2p | The p2pInfo struct with all the state information |
payload | A byte array to be copied to the payload for this message |
len | The length of the byte array |
msgTxCbFn | A callback function when this message is ACKed or dropped |
void p2pRecvCb | ( | p2pInfo * | p2p, |
const uint8_t * | mac_addr, | ||
const uint8_t * | data, | ||
uint8_t | len, | ||
int8_t | rssi ) |
This function must be called whenever an ESP NOW packet is received.
p2p | The p2pInfo struct with all the state information |
mac_addr | The MAC of the swadge that sent the data |
data | The data |
len | The length of the data |
rssi | The rssi of the received data |
void p2pSetDataInAck | ( | p2pInfo * | p2p, |
const uint8_t * | ackData, | ||
uint8_t | ackDataLen ) |
Set data to be automatically used as the payload all future ACKs, until the data is cleared.
This data will not be transmitted until the next ACK is sent, whenever that is. Normally an ACK does not contain any payload data, but an application can have a more efficient continuous request and response flow by embedding the response in the ACK.
p2p | The p2pInfo struct with all the state information |
ackData | The data to be included in the next ACK, will be copied here |
ackDataLen | The length of the data to be included in the next ACK |
void p2pClearDataInAck | ( | p2pInfo * | p2p | ) |
Clear any data which was set to be used as the payload in the next ACK.
p2p | The p2pInfo struct with all the state information |
void p2pSendCb | ( | p2pInfo * | p2p, |
const uint8_t * | mac_addr, | ||
esp_now_send_status_t | status ) |
This must be called by whatever function is registered to the Swadge mode's fnEspNowSendCb.
This is called after an attempted transmission. If it was successful, and the message should be acked, start a retry timer. If it wasn't successful, just try again
p2p | The p2pInfo struct with all the state information |
mac_addr | unused |
status | Whether the transmission succeeded or failed |
playOrder_t p2pGetPlayOrder | ( | p2pInfo * | p2p | ) |
After the swadge is connected to another, return whether this Swadge is player 1 or player 2. This can be used to determine client/server roles.
p2p | The p2pInfo struct with all the state information |
void p2pSetPlayOrder | ( | p2pInfo * | p2p, |
playOrder_t | order ) |
Override whether the Swadge is player 1 or player 2. You probably shouldn't do this, but you might want to for single player modes.
p2p | The p2pInfo struct with all the state information |
order | The order to set |