-
Notifications
You must be signed in to change notification settings - Fork 19
Example Application
OpenAcousticDevices edited this page Nov 18, 2017
·
15 revisions
AudioMoth applications are written by editing the main.c
file. The example included in the repository represents a minimal application that handles default USB messages (allowing interaction with the simple Time Setter configuration tool.
The application starts by importing the standard Boolean header and the AudioMoth library header.
#include <stdbool.h>
#include "audioMoth.h"
It then provide all the mandatory empty interrupt handlers.
/* Required interrupt handles */
void AudioMoth_handleSwitchInterrupt(void) { };
void AudioMoth_handleMicrophoneInterrupt(int16_t sample) { };
void AudioMoth_handleDirectMemoryAccessInterrupt(bool primaryChannel, int16_t **nextBuffer) { };
void AudioMoth_usbApplicationPacketRequested(uint32_t messageType, uint8_t *transmitBuffer, uint32_t size) { };
void AudioMoth_usbApplicationPacketReceived(uint32_t messageType, uint8_t *receiveBuffer, uint8_t *transmitBuffer, uint32_t size) { };
The main
function then starts by initialing the AudioMoth device and checking the switch position.
/* Main function */
int main(void) {
/* Initialise device */
AudioMoth_initialise();
/* Check the switch position */
AM_switchPosition_t switchPosition = AudioMoth_getSwitchPosition();
If the switch is in the 'USB' position, the code calls AudioMoth_handleUSB
to handle all communication with the host computer. The AudioMoth library will automatically handle request time,
if (switchPosition == AM_SWITCH_USB) {
/* Handle the case that the switch is in USB position. Waits in low energy state until USB disconnected or switch moved */
AudioMoth_handleUSB();
} else {
/* Flash both LED */
AudioMoth_setBothLED(true);
AudioMoth_delay(100);
AudioMoth_setBothLED(false);
}
/* Power down and wake up in one second */
AudioMoth_powerDownAndWake(1, true);
}