Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
swadgeMode_t Struct Reference

Detailed Description

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.
 

Field Documentation

◆ modeName

const char* modeName

This swadge mode's name, used in menus. This is not a function pointer.

◆ wifiMode

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.

◆ overrideUsb

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.

◆ usesAccelerometer

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.

◆ usesThermometer

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.

◆ overrideSelectBtn

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.

◆ fnEnterMode

void(* fnEnterMode) (void)

This function is called when this mode is started. It should initialize variables and start the mode.

◆ fnExitMode

void(* fnExitMode) (void)

This function is called when the mode is exited. It should free any allocated memory.

◆ fnMainLoop

void(* fnMainLoop) (int64_t elapsedUs)

This function is called from the main loop. It's pretty quick, but the timing may be inconsistent.

Parameters
elapsedUsThe time elapsed since the last time this function was called. Use this value to determine when it's time to do things

◆ fnAudioCallback

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.

Parameters
samplesA pointer to 12 bit audio samples
sampleCntThe number of samples read

◆ fnBackgroundDrawCallback

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.

Parameters
xthe x coordinate that should be updated
ythe x coordinate that should be updated
wthe width of the rectangle to be updated
hthe height of the rectangle to be updated
upupdate number
numUpupdate number denominator

◆ fnEspNowRecvCb

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.

Parameters
esp_now_infoInformation about the transmission, including The MAC addresses
dataA pointer to the data received
lenThe length of the data received
rssiThe RSSI for this packet, from 1 (weak) to ~90 (touching)

◆ fnEspNowSendCb

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().

Parameters
mac_addrThe MAC address which the data was sent to
statusThe status of the transmission

◆ fnAdvancedUSB

int16_t(* fnAdvancedUSB) (uint8_t *buffer, uint16_t length, uint8_t isGet)

Advanced USB Functionality, for hooking existing advanced_usb interface.

  • if isGet == 1, that is a "get" or an "IN" endpoint, where the Swadge sends data to the Host.
  • if isGet == 0, that is a "set" or an "OUT" endpoint, where the Host sends data to the Swadge.
Parameters
bufferPointer to full command
lengthTotal length of the buffer (command ID included)
isGet0 if this is a SET_REPORT, 1 if this is a GET_REPORT
Returns
The number of bytes returned to the host

◆ fnDacCb

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.


The documentation for this struct was generated from the following file: