Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
A struct of all the function pointers necessary for a swadge mode. If a mode does not need a particular function, for example it doesn't do audio handling, it is safe to set the pointer to NULL. It just won't be called.
#include <swadge2024.h>
Data Fields | |
const char * | modeName |
This swadge mode's name, used in menus. This is not a function pointer. | |
wifiMode_t | wifiMode |
This is a setting, not a function pointer. Set it to NO_WIFI to save power by not using WiFi at all. Set it to ESP_NOW to send and receive packets to and from all Swadges in range. ESP_NOW_IMMEDIATE is the same as ESP_NOW but does not use a queue for incoming packets. | |
bool | overrideUsb |
If this is false, then the default TinyUSB driver will be installed (HID gamepad). If this is true, then the swadge mode can do whatever it wants with USB. | |
bool | usesAccelerometer |
If this is false, the accelerometer will not be initialized and accelGetAccelVec() will not work. If this is true, then the swadge will be initialized. | |
bool | usesThermometer |
If this is false, the thermometer will not be initialized and readTemperatureSensor() will not work. If this is true, then the swadge will be initialized. | |
bool | overrideSelectBtn |
If this is false, then PB_SELECT events will only be used to return to the main menu or open the quick settings menu. If this is true then PB_SELECT events will be passed to the Swadge mode and PB_SELECT will not return to the main menu or open the quick settings menu. | |
void(* | fnEnterMode )(void) |
This function is called when this mode is started. It should initialize variables and start the mode. | |
void(* | fnExitMode )(void) |
This function is called when the mode is exited. It should free any allocated memory. | |
void(* | fnMainLoop )(int64_t elapsedUs) |
This function is called from the main loop. It's pretty quick, but the timing may be inconsistent. | |
void(* | fnAudioCallback )(uint16_t *samples, uint32_t sampleCnt) |
This function is called whenever audio samples are read from the microphone (ADC) and are ready for processing. Samples are read at 8KHz. If this function is not NULL, then readBattmon() will not work. | |
void(* | fnBackgroundDrawCallback )(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum) |
This function is called when the display driver wishes to update a section of the display. | |
void(* | fnEspNowRecvCb )(const esp_now_recv_info_t *esp_now_info, const uint8_t *data, uint8_t len, int8_t rssi) |
This function is called whenever an ESP-NOW packet is received. | |
void(* | fnEspNowSendCb )(const uint8_t *mac_addr, esp_now_send_status_t status) |
This function is called whenever an ESP-NOW packet is sent. It is just a status callback whether or not the packet was actually sent. This will be called after calling espNowSend(). | |
int16_t(* | fnAdvancedUSB )(uint8_t *buffer, uint16_t length, uint8_t isGet) |
Advanced USB Functionality, for hooking existing advanced_usb interface. | |
fnDacCallback_t | fnDacCb |
This function is called to fill sample buffers for the DAC. If this is NULL, then globalMidiPlayerFillBuffer() will be used instead to fill sample buffers. | |
const char* modeName |
This swadge mode's name, used in menus. This is not a function pointer.
wifiMode_t wifiMode |
This is a setting, not a function pointer. Set it to NO_WIFI to save power by not using WiFi at all. Set it to ESP_NOW to send and receive packets to and from all Swadges in range. ESP_NOW_IMMEDIATE is the same as ESP_NOW but does not use a queue for incoming packets.
bool overrideUsb |
If this is false, then the default TinyUSB driver will be installed (HID gamepad). If this is true, then the swadge mode can do whatever it wants with USB.
bool usesAccelerometer |
If this is false, the accelerometer will not be initialized and accelGetAccelVec() will not work. If this is true, then the swadge will be initialized.
bool usesThermometer |
If this is false, the thermometer will not be initialized and readTemperatureSensor() will not work. If this is true, then the swadge will be initialized.
bool overrideSelectBtn |
void(* fnEnterMode) (void) |
This function is called when this mode is started. It should initialize variables and start the mode.
void(* fnExitMode) (void) |
This function is called when the mode is exited. It should free any allocated memory.
void(* fnMainLoop) (int64_t elapsedUs) |
This function is called from the main loop. It's pretty quick, but the timing may be inconsistent.
elapsedUs | The time elapsed since the last time this function was called. Use this value to determine when it's time to do things |
void(* fnAudioCallback) (uint16_t *samples, uint32_t sampleCnt) |
This function is called whenever audio samples are read from the microphone (ADC) and are ready for processing. Samples are read at 8KHz. If this function is not NULL, then readBattmon() will not work.
samples | A pointer to 12 bit audio samples |
sampleCnt | The number of samples read |
void(* fnBackgroundDrawCallback) (int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum) |
This function is called when the display driver wishes to update a section of the display.
x | the x coordinate that should be updated |
y | the x coordinate that should be updated |
w | the width of the rectangle to be updated |
h | the height of the rectangle to be updated |
up | update number |
numUp | update number denominator |
void(* fnEspNowRecvCb) (const esp_now_recv_info_t *esp_now_info, const uint8_t *data, uint8_t len, int8_t rssi) |
This function is called whenever an ESP-NOW packet is received.
esp_now_info | Information about the transmission, including The MAC addresses |
data | A pointer to the data received |
len | The length of the data received |
rssi | The RSSI for this packet, from 1 (weak) to ~90 (touching) |
void(* fnEspNowSendCb) (const uint8_t *mac_addr, esp_now_send_status_t status) |
This function is called whenever an ESP-NOW packet is sent. It is just a status callback whether or not the packet was actually sent. This will be called after calling espNowSend().
mac_addr | The MAC address which the data was sent to |
status | The status of the transmission |
int16_t(* fnAdvancedUSB) (uint8_t *buffer, uint16_t length, uint8_t isGet) |
Advanced USB Functionality, for hooking existing advanced_usb interface.
isGet
== 1, that is a "get" or an "IN" endpoint, where the Swadge sends data to the Host.isGet
== 0, that is a "set" or an "OUT" endpoint, where the Host sends data to the Swadge.buffer | Pointer to full command |
length | Total length of the buffer (command ID included) |
isGet | 0 if this is a SET_REPORT , 1 if this is a GET_REPORT |
fnDacCallback_t fnDacCb |
This function is called to fill sample buffers for the DAC. If this is NULL, then globalMidiPlayerFillBuffer() will be used instead to fill sample buffers.