Audio system on ersky9x ... another rewrite
Some flash saved on stock GPS calculations flash saving (around 100bytes, needs to be tested)
This commit is contained in:
+118
-81
@@ -141,6 +141,7 @@ AudioQueue audioQueue;
|
|||||||
AudioQueue::AudioQueue()
|
AudioQueue::AudioQueue()
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(AudioQueue));
|
memset(this, 0, sizeof(AudioQueue));
|
||||||
|
prioIdx = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audioTimerHandle(void)
|
void audioTimerHandle(void)
|
||||||
@@ -156,6 +157,7 @@ extern uint16_t Sine_values[];
|
|||||||
#define CODEC_ID_PCM_S16LE 1
|
#define CODEC_ID_PCM_S16LE 1
|
||||||
#define CODEC_ID_PCM_ALAW 6
|
#define CODEC_ID_PCM_ALAW 6
|
||||||
uint8_t pcmCodec;
|
uint8_t pcmCodec;
|
||||||
|
uint16_t pcmFreq;
|
||||||
|
|
||||||
void audioTask(void* pdata)
|
void audioTask(void* pdata)
|
||||||
{
|
{
|
||||||
@@ -168,27 +170,50 @@ void audioTask(void* pdata)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define WAV_BUFFER_SIZE 512
|
||||||
|
uint16_t wavSamplesArray[3*WAV_BUFFER_SIZE];
|
||||||
|
uint16_t * wavSamplesBuffer = &wavSamplesArray[0];
|
||||||
|
uint16_t * nextAudioData = NULL;
|
||||||
|
uint16_t nextAudioSize = 0;
|
||||||
|
|
||||||
void AudioQueue::wakeup()
|
void AudioQueue::wakeup()
|
||||||
{
|
{
|
||||||
#if defined(SDCARD) && !defined(SIMU)
|
#if defined(SDCARD) && !defined(SIMU)
|
||||||
static FIL wavFile;
|
static FIL wavFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (prioIdx >= 0) {
|
||||||
|
ridx = prioIdx;
|
||||||
|
prioIdx = -1;
|
||||||
|
toneStop();
|
||||||
|
nextAudioData = NULL;
|
||||||
|
memset(¤t, 0, sizeof(current));
|
||||||
|
if (state == AUDIO_PLAYING_WAV) {
|
||||||
|
state = AUDIO_RESUMING;
|
||||||
|
CoSetTmrCnt(audioTimer, 5/*10ms*/ + (WAV_BUFFER_SIZE * 1000) / pcmFreq, 0);
|
||||||
|
CoStartTmr(audioTimer);
|
||||||
|
}
|
||||||
|
else if (state == AUDIO_PLAYING_TONE) {
|
||||||
|
state = AUDIO_RESUMING;
|
||||||
|
CoSetTmrCnt(audioTimer, 5/*10ms*/, 0);
|
||||||
|
CoStartTmr(audioTimer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CoSetFlag(audioFlag);
|
||||||
|
}
|
||||||
|
}
|
||||||
#if defined(SDCARD) && !defined(SIMU)
|
#if defined(SDCARD) && !defined(SIMU)
|
||||||
if (current.file[0]) {
|
else if (current.file[0]) {
|
||||||
FRESULT result = FR_OK;
|
FRESULT result = FR_OK;
|
||||||
UINT read = 0;
|
UINT read = 0;
|
||||||
uint16_t * bufdata = wavSamplesBuffer;
|
|
||||||
if (current.file[1]) {
|
if (current.file[1]) {
|
||||||
|
wavSamplesBuffer = wavSamplesArray;
|
||||||
result = f_open(&wavFile, current.file, FA_OPEN_EXISTING | FA_READ);
|
result = f_open(&wavFile, current.file, FA_OPEN_EXISTING | FA_READ);
|
||||||
if (result == FR_OK) {
|
if (result == FR_OK) {
|
||||||
result = f_read(&wavFile, (uint8_t *)wavSamplesArray, WAV_HEADER_SIZE, &read);
|
result = f_read(&wavFile, (uint8_t *)wavSamplesArray, WAV_HEADER_SIZE, &read);
|
||||||
if (result == FR_OK && read == WAV_HEADER_SIZE && !memcmp(wavSamplesArray, "RIFF", 4)) {
|
if (result == FR_OK && read == WAV_HEADER_SIZE && !memcmp(wavSamplesArray, "RIFF", 4)) {
|
||||||
CoSetFlag(audioFlag);
|
|
||||||
bufdata = wavSamplesArray;
|
|
||||||
wavSamplesBuffer = wavSamplesArray + WAV_BUFFER_SIZE;
|
|
||||||
pcmCodec = wavSamplesArray[10];
|
pcmCodec = wavSamplesArray[10];
|
||||||
setFrequency(wavSamplesArray[12]);
|
pcmFreq = wavSamplesArray[12];
|
||||||
if (pcmCodec != CODEC_ID_PCM_S16LE) {
|
if (pcmCodec != CODEC_ID_PCM_S16LE) {
|
||||||
result = f_read(&wavFile, (uint8_t *)wavSamplesArray, 12, &read);
|
result = f_read(&wavFile, (uint8_t *)wavSamplesArray, 12, &read);
|
||||||
}
|
}
|
||||||
@@ -198,53 +223,73 @@ void AudioQueue::wakeup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
wavSamplesBuffer += WAV_BUFFER_SIZE;
|
||||||
|
if (wavSamplesBuffer >= wavSamplesArray + 3*WAV_BUFFER_SIZE)
|
||||||
|
wavSamplesBuffer = wavSamplesArray;
|
||||||
|
}
|
||||||
|
|
||||||
read = 0;
|
read = 0;
|
||||||
uint16_t bufsize = (pcmCodec == CODEC_ID_PCM_S16LE ? 2*WAV_BUFFER_SIZE : WAV_BUFFER_SIZE);
|
uint16_t bufsize = (pcmCodec == CODEC_ID_PCM_S16LE ? WAV_BUFFER_SIZE*sizeof(uint16_t) : WAV_BUFFER_SIZE);
|
||||||
if (result != FR_OK || f_read(&wavFile, (uint8_t *)bufdata, bufsize, &read) != FR_OK || read != bufsize) {
|
if (result != FR_OK || f_read(&wavFile, (uint8_t *)wavSamplesBuffer, bufsize, &read) != FR_OK || read == 0) {
|
||||||
|
toneStop();
|
||||||
current.file[0] = 0;
|
current.file[0] = 0;
|
||||||
current.file[1] = 0;
|
current.file[1] = 0;
|
||||||
if (pcmCodec == CODEC_ID_PCM_S16LE) {
|
|
||||||
DACC->DACC_TNCR = read/4;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DACC->DACC_TNCR = read/2;
|
|
||||||
}
|
|
||||||
toneStop();
|
|
||||||
f_close(&wavFile);
|
f_close(&wavFile);
|
||||||
CoSetFlag(audioFlag);
|
CoSetTmrCnt(audioTimer, (WAV_BUFFER_SIZE * 1000) / pcmFreq, 0);
|
||||||
|
CoStartTmr(audioTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pcmCodec == CODEC_ID_PCM_S16LE) {
|
if (pcmCodec == CODEC_ID_PCM_S16LE) {
|
||||||
read /= 2;
|
read /= 2;
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (; i<read; i++)
|
for (; i<read; i++)
|
||||||
bufdata[i] = ((uint16_t)0x8000 + ((int16_t)(bufdata[i]))) >> 4;
|
wavSamplesBuffer[i] = ((uint16_t)0x8000 + ((int16_t)(wavSamplesBuffer[i]))) >> 4;
|
||||||
for (; i<WAV_BUFFER_SIZE; i++)
|
for (; i<WAV_BUFFER_SIZE; i++)
|
||||||
bufdata[i] = 0x8000;
|
wavSamplesBuffer[i] = 0x8000;
|
||||||
}
|
}
|
||||||
else if (pcmCodec == CODEC_ID_PCM_ALAW) {
|
else if (pcmCodec == CODEC_ID_PCM_ALAW) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
for (i=read-1; i>=0; i--)
|
for (i=read-1; i>=0; i--)
|
||||||
bufdata[i] = alawTable[((uint8_t *)bufdata)[i]];
|
wavSamplesBuffer[i] = alawTable[((uint8_t *)wavSamplesBuffer)[i]];
|
||||||
for (i=read; i<WAV_BUFFER_SIZE; i++)
|
for (i=read; i<WAV_BUFFER_SIZE; i++)
|
||||||
bufdata[i] = 0x8000;
|
wavSamplesBuffer[i] = 0x8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read /= 2;
|
||||||
|
register Dacc *dacptr = DACC;
|
||||||
|
|
||||||
if (current.file[1]) {
|
if (current.file[1]) {
|
||||||
|
state = AUDIO_PLAYING_WAV;
|
||||||
|
setFrequency(pcmFreq);
|
||||||
|
dacptr->DACC_TPR = CONVERT_PTR(wavSamplesBuffer);
|
||||||
|
dacptr->DACC_TCR = read;
|
||||||
current.file[1] = 0;
|
current.file[1] = 0;
|
||||||
register Dacc *dacptr = DACC;
|
CoSetFlag(audioFlag);
|
||||||
dacptr->DACC_TPR = CONVERT_PTR(wavSamplesArray);
|
}
|
||||||
dacptr->DACC_TNPR = CONVERT_PTR(wavSamplesBuffer);
|
else if (read) {
|
||||||
dacptr->DACC_TCR = WAV_BUFFER_SIZE/2;
|
if (dacptr->DACC_TNCR == 0) {
|
||||||
dacptr->DACC_TNCR = WAV_BUFFER_SIZE/2;
|
dacptr->DACC_TNPR = CONVERT_PTR(wavSamplesBuffer);
|
||||||
toneStart();
|
dacptr->DACC_TNCR = read;
|
||||||
|
CoSetFlag(audioFlag);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nextAudioSize = read;
|
||||||
|
nextAudioData = wavSamplesBuffer;
|
||||||
|
toneStart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
if (current.duration > 0) {
|
else if (current.duration > 0) {
|
||||||
// TODO function for that ...
|
if (state != AUDIO_PLAYING_TONE) {
|
||||||
|
state = AUDIO_PLAYING_TONE;
|
||||||
|
register Dacc *dacptr = DACC;
|
||||||
|
dacptr->DACC_TPR = CONVERT_PTR(Sine_values);
|
||||||
|
dacptr->DACC_TNPR = CONVERT_PTR(Sine_values);
|
||||||
|
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||||
|
dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||||
|
}
|
||||||
setFrequency(current.freq * 6100 / 2);
|
setFrequency(current.freq * 6100 / 2);
|
||||||
if (current.freqIncr) {
|
if (current.freqIncr) {
|
||||||
CoSetTmrCnt(audioTimer, 5/*10ms*/, 0);
|
CoSetTmrCnt(audioTimer, 5/*10ms*/, 0);
|
||||||
@@ -252,14 +297,14 @@ void AudioQueue::wakeup()
|
|||||||
current.duration--;
|
current.duration--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CoSetTmrCnt(audioTimer, current.duration*5, 0);
|
CoSetTmrCnt(audioTimer, current.duration*2, 0);
|
||||||
current.duration = 0;
|
current.duration = 0;
|
||||||
}
|
}
|
||||||
toneStart();
|
toneStart();
|
||||||
CoStartTmr(audioTimer);
|
CoStartTmr(audioTimer);
|
||||||
}
|
}
|
||||||
else if (current.pause > 0) {
|
else if (current.pause > 0) {
|
||||||
CoSetTmrCnt(audioTimer, current.pause*5, 0);
|
CoSetTmrCnt(audioTimer, current.pause*2, 0);
|
||||||
current.pause = 0;
|
current.pause = 0;
|
||||||
toneStop();
|
toneStop();
|
||||||
CoStartTmr(audioTimer);
|
CoStartTmr(audioTimer);
|
||||||
@@ -272,14 +317,25 @@ void AudioQueue::wakeup()
|
|||||||
CoSetFlag(audioFlag);
|
CoSetFlag(audioFlag);
|
||||||
}
|
}
|
||||||
else if (background.duration > 0) {
|
else if (background.duration > 0) {
|
||||||
CoSetTmrCnt(audioTimer, background.duration*5, 0);
|
if (state != AUDIO_PLAYING_TONE) {
|
||||||
|
state = AUDIO_PLAYING_TONE;
|
||||||
|
register Dacc *dacptr = DACC;
|
||||||
|
dacptr->DACC_TPR = CONVERT_PTR(Sine_values);
|
||||||
|
dacptr->DACC_TNPR = CONVERT_PTR(Sine_values);
|
||||||
|
dacptr->DACC_TCR = 50 ; // words, 100 16 bit values
|
||||||
|
dacptr->DACC_TNCR = 50 ; // words, 100 16 bit values
|
||||||
|
}
|
||||||
|
CoSetTmrCnt(audioTimer, background.duration*2, 0);
|
||||||
background.duration = 0;
|
background.duration = 0;
|
||||||
setFrequency(background.freq * 6100 / 2);
|
setFrequency(background.freq * 6100 / 2);
|
||||||
toneStart();
|
toneStart();
|
||||||
CoStartTmr(audioTimer);
|
CoStartTmr(audioTimer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
state = 0;
|
state = AUDIO_SLEEPING;
|
||||||
|
#ifndef SIMU
|
||||||
|
CoLeaveMutexSection(audioMutex);
|
||||||
|
#endif
|
||||||
toneStop();
|
toneStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,8 +371,8 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag
|
|||||||
background.freq = tFreq;
|
background.freq = tFreq;
|
||||||
background.duration = tLen;
|
background.duration = tLen;
|
||||||
background.pause = tPause;
|
background.pause = tPause;
|
||||||
if (state == 0) {
|
if (!busy()) {
|
||||||
state = 1;
|
state = AUDIO_RESUMING;
|
||||||
CoSetFlag(audioFlag);
|
CoSetFlag(audioFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,32 +381,22 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag
|
|||||||
tFreq += g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator
|
tFreq += g_eeGeneral.speakerPitch + BEEP_OFFSET; // add pitch compensator
|
||||||
}
|
}
|
||||||
tLen = getToneLength(tLen);
|
tLen = getToneLength(tLen);
|
||||||
if ((tFlags & PLAY_NOW) || !busy()) {
|
|
||||||
state = 1;
|
|
||||||
current.file[0] = '\0';
|
|
||||||
current.freq = tFreq;
|
|
||||||
current.duration = tLen;
|
|
||||||
current.pause = tPause;
|
|
||||||
current.freqIncr = tFreqIncr;
|
|
||||||
widx = ridx;
|
|
||||||
CoSetFlag(audioFlag);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tFlags++;
|
|
||||||
}
|
|
||||||
|
|
||||||
tFlags &= 0x0f;
|
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
||||||
if (tFlags) {
|
if (next_widx != ridx) {
|
||||||
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
AudioFragment & fragment = fragments[widx];
|
||||||
if (next_widx != ridx) {
|
memset(&fragment, 0, sizeof(fragment));
|
||||||
AudioFragment & fragment = fragments[widx];
|
fragment.freq = tFreq;
|
||||||
memset(&fragment, 0, sizeof(fragment));
|
fragment.duration = tLen;
|
||||||
fragment.freq = tFreq;
|
fragment.pause = tPause;
|
||||||
fragment.duration = tLen;
|
fragment.repeat = tFlags & 0x0f;
|
||||||
fragment.pause = tPause;
|
fragment.freqIncr = tFreqIncr;
|
||||||
fragment.repeat = tFlags - 1;
|
if (tFlags & PLAY_NOW)
|
||||||
fragment.freqIncr = tFreqIncr;
|
prioIdx = widx;
|
||||||
widx = next_widx;
|
widx = next_widx;
|
||||||
|
if (!busy()) {
|
||||||
|
state = AUDIO_RESUMING;
|
||||||
|
CoSetFlag(audioFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,29 +412,20 @@ void AudioQueue::playFile(const char *filename, uint8_t flags)
|
|||||||
CoEnterMutexSection(audioMutex);
|
CoEnterMutexSection(audioMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((flags & PLAY_NOW) || !busy()) {
|
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
||||||
state = 1;
|
if (next_widx != ridx) {
|
||||||
memset(¤t, 0, sizeof(current));
|
AudioFragment & fragment = fragments[widx];
|
||||||
strcpy(current.file, filename);
|
memset(&fragment, 0, sizeof(fragment));
|
||||||
widx = ridx;
|
strcpy(fragment.file, filename);
|
||||||
CoSetFlag(audioFlag);
|
fragment.repeat = flags & 0x0f;
|
||||||
}
|
if (flags & PLAY_NOW)
|
||||||
else {
|
prioIdx = widx;
|
||||||
flags++;
|
widx = next_widx;
|
||||||
}
|
if (!busy()) {
|
||||||
|
state = AUDIO_RESUMING;
|
||||||
flags &= 0x0f;
|
CoSetFlag(audioFlag);
|
||||||
if (flags) {
|
|
||||||
uint8_t next_widx = (widx + 1) % AUDIO_QUEUE_LENGTH;
|
|
||||||
if (next_widx != ridx) {
|
|
||||||
AudioFragment & fragment = fragments[widx];
|
|
||||||
memset(&fragment, 0, sizeof(fragment));
|
|
||||||
strcpy(current.file, filename);
|
|
||||||
fragment.repeat = flags - 1;
|
|
||||||
widx = next_widx;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CoSetFlag(audioFlag);
|
|
||||||
|
|
||||||
#ifndef SIMU
|
#ifndef SIMU
|
||||||
CoLeaveMutexSection(audioMutex);
|
CoLeaveMutexSection(audioMutex);
|
||||||
|
|||||||
+7
-1
@@ -56,6 +56,11 @@ class AudioFragment : public ToneFragment {
|
|||||||
|
|
||||||
extern "C" void DAC_IRQHandler();
|
extern "C" void DAC_IRQHandler();
|
||||||
|
|
||||||
|
#define AUDIO_SLEEPING 0
|
||||||
|
#define AUDIO_RESUMING 1
|
||||||
|
#define AUDIO_PLAYING_TONE 2
|
||||||
|
#define AUDIO_PLAYING_WAV 3
|
||||||
|
|
||||||
class AudioQueue {
|
class AudioQueue {
|
||||||
|
|
||||||
friend void audioTask(void* pdata);
|
friend void audioTask(void* pdata);
|
||||||
@@ -73,7 +78,7 @@ class AudioQueue {
|
|||||||
|
|
||||||
bool busy()
|
bool busy()
|
||||||
{
|
{
|
||||||
return (state != 0);
|
return (state != AUDIO_SLEEPING);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -83,6 +88,7 @@ class AudioQueue {
|
|||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t ridx;
|
uint8_t ridx;
|
||||||
uint8_t widx;
|
uint8_t widx;
|
||||||
|
int8_t prioIdx;
|
||||||
AudioFragment fragments[AUDIO_QUEUE_LENGTH];
|
AudioFragment fragments[AUDIO_QUEUE_LENGTH];
|
||||||
ToneFragment background; // for vario
|
ToneFragment background; // for vario
|
||||||
|
|
||||||
|
|||||||
@@ -171,19 +171,21 @@ void initDac()
|
|||||||
NVIC_EnableIRQ(DACC_IRQn) ;
|
NVIC_EnableIRQ(DACC_IRQn) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t wavSamplesArray[2*WAV_BUFFER_SIZE]; /* 2 buffers of 100ms at 12kHz */
|
|
||||||
uint16_t *wavSamplesBuffer;
|
|
||||||
|
|
||||||
extern "C" void DAC_IRQHandler()
|
extern "C" void DAC_IRQHandler()
|
||||||
{
|
{
|
||||||
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
// Data for PDC must NOT be in flash, PDC needs a RAM source.
|
||||||
if (audioQueue.current.file[0]) {
|
if (audioQueue.state == AUDIO_PLAYING_WAV) {
|
||||||
CoEnterISR(); // Enter the interrupt
|
if (nextAudioData) {
|
||||||
CoSetFlag(audioFlag);
|
DACC->DACC_TNPR = CONVERT_PTR(nextAudioData);
|
||||||
CoExitISR(); // Exit the interrupt
|
DACC->DACC_TNCR = nextAudioSize;
|
||||||
wavSamplesBuffer = (wavSamplesBuffer == wavSamplesArray) ? wavSamplesArray+WAV_BUFFER_SIZE : wavSamplesArray;
|
nextAudioData = NULL;
|
||||||
DACC->DACC_TNPR = CONVERT_PTR(wavSamplesBuffer);
|
CoEnterISR(); // Enter the interrupt
|
||||||
DACC->DACC_TNCR = WAV_BUFFER_SIZE/2;
|
CoSetFlag(audioFlag);
|
||||||
|
CoExitISR(); // Exit the interrupt
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toneStop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DACC->DACC_TNPR = CONVERT_PTR(Sine_values);
|
DACC->DACC_TNPR = CONVERT_PTR(Sine_values);
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ extern void start_timer1( void ) ;
|
|||||||
extern void initDac( void ) ;
|
extern void initDac( void ) ;
|
||||||
extern void end_sound( void ) ;
|
extern void end_sound( void ) ;
|
||||||
|
|
||||||
#define WAV_BUFFER_SIZE 1200
|
extern uint16_t *nextAudioData;
|
||||||
extern uint16_t wavSamplesArray[2*WAV_BUFFER_SIZE]; /* 2 buffers of 100ms at 12kHz */
|
extern uint16_t nextAudioSize;
|
||||||
extern uint16_t *wavSamplesBuffer;
|
|
||||||
|
|
||||||
inline void toneStart()
|
inline void toneStart()
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-6
@@ -100,11 +100,19 @@ uint8_t frskyGetUserData(char *buffer, uint8_t bufSize)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FRSKY_HUB
|
#ifdef FRSKY_HUB
|
||||||
|
void extractLatitudeLongitude(uint32_t * latitude, uint32_t * longitude)
|
||||||
|
{
|
||||||
|
div_t qr = div(frskyData.hub.gpsLatitude_bp, 100);
|
||||||
|
*latitude = ((uint32_t)(qr.quot) * 1000000) + (((uint32_t)(qr.rem) * 10000 + frskyData.hub.gpsLatitude_ap) * 5) / 3;
|
||||||
|
|
||||||
|
qr = div(frskyData.hub.gpsLongitude_bp, 100);
|
||||||
|
*longitude = ((uint32_t)(qr.quot) * 1000000) + (((uint32_t)(qr.rem) * 10000 + frskyData.hub.gpsLongitude_ap) * 5) / 3;
|
||||||
|
}
|
||||||
|
|
||||||
inline void getGpsPilotPosition()
|
inline void getGpsPilotPosition()
|
||||||
{
|
{
|
||||||
frskyData.hub.pilotLatitude = ((uint32_t)(frskyData.hub.gpsLatitude_bp / 100) * 1000000) + (((uint32_t)(frskyData.hub.gpsLatitude_bp % 100) * 10000 + frskyData.hub.gpsLatitude_ap) * 5) / 3;
|
extractLatitudeLongitude(&frskyData.hub.pilotLatitude, &frskyData.hub.pilotLongitude);
|
||||||
frskyData.hub.pilotLongitude = ((uint32_t)(frskyData.hub.gpsLongitude_bp / 100) * 1000000) + (((uint32_t)(frskyData.hub.gpsLongitude_bp % 100) * 10000 + frskyData.hub.gpsLongitude_ap) * 5) / 3;
|
uint32_t lat = frskyData.hub.pilotLatitude / 10000;
|
||||||
uint32_t lat = (uint32_t)(frskyData.hub.gpsLatitude_bp / 100) * 100 + ((uint32_t)(frskyData.hub.gpsLatitude_bp % 100) * 5) / 3;
|
|
||||||
uint32_t angle2 = (lat*lat) / 10000;
|
uint32_t angle2 = (lat*lat) / 10000;
|
||||||
uint32_t angle4 = angle2 * angle2;
|
uint32_t angle4 = angle2 * angle2;
|
||||||
frskyData.hub.distFromEarthAxis = 139*(((uint32_t)10000000-((angle2*(uint32_t)123370)/81)+(angle4/25))/12500);
|
frskyData.hub.distFromEarthAxis = 139*(((uint32_t)10000000-((angle2*(uint32_t)123370)/81)+(angle4/25))/12500);
|
||||||
@@ -113,8 +121,9 @@ inline void getGpsPilotPosition()
|
|||||||
|
|
||||||
inline void getGpsDistance()
|
inline void getGpsDistance()
|
||||||
{
|
{
|
||||||
uint32_t lat = ((uint32_t)(frskyData.hub.gpsLatitude_bp / 100) * 1000000) + (((uint32_t)(frskyData.hub.gpsLatitude_bp % 100) * 10000 + frskyData.hub.gpsLatitude_ap) * 5) / 3;
|
uint32_t lat, lng;
|
||||||
uint32_t lng = ((uint32_t)(frskyData.hub.gpsLongitude_bp / 100) * 1000000) + (((uint32_t)(frskyData.hub.gpsLongitude_bp % 100) * 10000 + frskyData.hub.gpsLongitude_ap) * 5) / 3;
|
|
||||||
|
extractLatitudeLongitude(&lat, &lng);
|
||||||
|
|
||||||
// printf("lat=%d (%d), long=%d (%d)\n", lat, abs(lat - frskyData.hub.pilotLatitude), lng, abs(lng - frskyData.hub.pilotLongitude));
|
// printf("lat=%d (%d), long=%d (%d)\n", lat, abs(lat - frskyData.hub.pilotLatitude), lng, abs(lng - frskyData.hub.pilotLongitude));
|
||||||
|
|
||||||
@@ -1052,7 +1061,6 @@ void displayGpsCoord(uint8_t y, char direction, int16_t bp, int16_t ap)
|
|||||||
{
|
{
|
||||||
if (frskyData.hub.gpsFix >= 0) {
|
if (frskyData.hub.gpsFix >= 0) {
|
||||||
if (!direction) direction = '-';
|
if (!direction) direction = '-';
|
||||||
|
|
||||||
lcd_outdezAtt(10*FW, y, bp / 100, LEFT); // ddd before '.'
|
lcd_outdezAtt(10*FW, y, bp / 100, LEFT); // ddd before '.'
|
||||||
lcd_putc(lcdLastPos, y, '@');
|
lcd_putc(lcdLastPos, y, '@');
|
||||||
uint8_t mn = bp % 100;
|
uint8_t mn = bp % 100;
|
||||||
|
|||||||
@@ -643,9 +643,9 @@ void menuProcSd(uint8_t event)
|
|||||||
#if defined(PCBARM)
|
#if defined(PCBARM)
|
||||||
else if (result == STR_PLAY_FILE) {
|
else if (result == STR_PLAY_FILE) {
|
||||||
f_getcwd(lfn, SD_SCREEN_FILE_LENGTH);
|
f_getcwd(lfn, SD_SCREEN_FILE_LENGTH);
|
||||||
strcat_P(lfn, PSTR("/"));
|
strcat(lfn, "/");
|
||||||
strcat(lfn, reusableBuffer.sd.lines[index]);
|
strcat(lfn, reusableBuffer.sd.lines[index]);
|
||||||
audioQueue.playFile(lfn);
|
audioQueue.playFile(lfn, PLAY_NOW);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -276,7 +276,7 @@ bool check(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTa
|
|||||||
#define scrollUD 0
|
#define scrollUD 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(scrollRE || scrollLR || scrollUD || p1valdiff) g_LightOffCounter = g_eeGeneral.lightAutoOff*500; // on keypress turn the light on 5*100
|
if (scrollRE || scrollLR || scrollUD || p1valdiff) backlightOn(); // on keypress turn the light on
|
||||||
|
|
||||||
if (menuTab) {
|
if (menuTab) {
|
||||||
uint8_t attr = 0;
|
uint8_t attr = 0;
|
||||||
|
|||||||
+8
-6
@@ -1239,12 +1239,14 @@ void deleteExpoMix(uint8_t expo, uint8_t idx)
|
|||||||
{
|
{
|
||||||
pauseMixerCalculations();
|
pauseMixerCalculations();
|
||||||
if (expo) {
|
if (expo) {
|
||||||
memmove(expoaddress(idx), expoaddress(idx+1), (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
ExpoData *expo = expoaddress(idx);
|
||||||
memset(expoaddress(MAX_EXPOS-1), 0, sizeof(ExpoData));
|
memmove(expo, expo+1, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||||
|
memset(&g_model.expoData[MAX_EXPOS-1], 0, sizeof(ExpoData));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memmove(mixaddress(idx), mixaddress(idx+1), (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
MixData *mix = mixaddress(idx);
|
||||||
memset(mixaddress(MAX_MIXERS-1), 0, sizeof(MixData));
|
memmove(mix, mix+1, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
||||||
|
memset(&g_model.mixData[MAX_MIXERS-1], 0, sizeof(MixData));
|
||||||
}
|
}
|
||||||
resumeMixerCalculations();
|
resumeMixerCalculations();
|
||||||
STORE_MODELVARS;
|
STORE_MODELVARS;
|
||||||
@@ -1257,7 +1259,7 @@ void insertExpoMix(uint8_t expo, uint8_t idx)
|
|||||||
if (expo) {
|
if (expo) {
|
||||||
ExpoData *expo = expoaddress(idx);
|
ExpoData *expo = expoaddress(idx);
|
||||||
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||||
memset(expo,0,sizeof(ExpoData));
|
memset(expo, 0, sizeof(ExpoData));
|
||||||
expo->mode = 3; // pos&neg
|
expo->mode = 3; // pos&neg
|
||||||
expo->chn = s_currCh - 1;
|
expo->chn = s_currCh - 1;
|
||||||
expo->weight = 100;
|
expo->weight = 100;
|
||||||
@@ -1265,7 +1267,7 @@ void insertExpoMix(uint8_t expo, uint8_t idx)
|
|||||||
else {
|
else {
|
||||||
MixData *mix = mixaddress(idx);
|
MixData *mix = mixaddress(idx);
|
||||||
memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
||||||
memset(mix,0,sizeof(MixData));
|
memset(mix, 0, sizeof(MixData));
|
||||||
mix->destCh = s_currCh-1;
|
mix->destCh = s_currCh-1;
|
||||||
mix->srcRaw = (s_currCh > 4 ? s_currCh : channel_order(s_currCh));
|
mix->srcRaw = (s_currCh > 4 ? s_currCh : channel_order(s_currCh));
|
||||||
mix->weight = 100;
|
mix->weight = 100;
|
||||||
|
|||||||
+11
-6
@@ -36,9 +36,9 @@ extern "C" {
|
|||||||
#include <CoOS.h>
|
#include <CoOS.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MIXER_STACK_SIZE 300
|
#define MIXER_STACK_SIZE 500
|
||||||
#define MENUS_STACK_SIZE 300
|
#define MENUS_STACK_SIZE 1000
|
||||||
#define AUDIO_STACK_SIZE 300
|
#define AUDIO_STACK_SIZE 500
|
||||||
#define BT_STACK_SIZE 100
|
#define BT_STACK_SIZE 100
|
||||||
|
|
||||||
OS_TID mixerTaskId;
|
OS_TID mixerTaskId;
|
||||||
@@ -2398,7 +2398,7 @@ void perMain()
|
|||||||
|
|
||||||
// TODO port lightOnStickMove from er9x + flash saving, call checkBacklight()
|
// TODO port lightOnStickMove from er9x + flash saving, call checkBacklight()
|
||||||
if(g_LightOffCounter) g_LightOffCounter--;
|
if(g_LightOffCounter) g_LightOffCounter--;
|
||||||
if(evt) g_LightOffCounter = g_eeGeneral.lightAutoOff*500; // on keypress turn the light on 5*100
|
if(evt) backlightOn(); // on keypress turn the light on
|
||||||
|
|
||||||
if (getSwitch(g_eeGeneral.lightSw,0) || g_LightOffCounter)
|
if (getSwitch(g_eeGeneral.lightSw,0) || g_LightOffCounter)
|
||||||
BACKLIGHT_ON;
|
BACKLIGHT_ON;
|
||||||
@@ -2901,7 +2901,7 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
|
|||||||
clearKeyEvents(); //make sure no keys are down before proceeding
|
clearKeyEvents(); //make sure no keys are down before proceeding
|
||||||
|
|
||||||
lcdSetRefVolt(g_eeGeneral.contrast);
|
lcdSetRefVolt(g_eeGeneral.contrast);
|
||||||
g_LightOffCounter = g_eeGeneral.lightAutoOff*500; //turn on light for x seconds - no need to press key Issue 152
|
backlightOn();
|
||||||
|
|
||||||
#if defined(PCBARM)
|
#if defined(PCBARM)
|
||||||
|
|
||||||
@@ -2916,6 +2916,11 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void backlightOn()
|
||||||
|
{
|
||||||
|
g_LightOffCounter = ((uint16_t)g_eeGeneral.lightAutoOff*250) << 1;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(PCBARM)
|
#if defined(PCBARM)
|
||||||
void mixerTask(void * pdata)
|
void mixerTask(void * pdata)
|
||||||
{
|
{
|
||||||
@@ -2930,7 +2935,7 @@ void mixerTask(void * pdata)
|
|||||||
lastTMR = tmr10ms;
|
lastTMR = tmr10ms;
|
||||||
|
|
||||||
if (s_current_protocol < PROTO_NONE) {
|
if (s_current_protocol < PROTO_NONE) {
|
||||||
checkTrims();
|
if (tick10ms) checkTrims();
|
||||||
doMixerCalculations(tmr10ms, tick10ms);
|
doMixerCalculations(tmr10ms, tick10ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -616,6 +616,8 @@ extern uint8_t s_eeDirtyMsk;
|
|||||||
#define STORE_MODELVARS eeDirty(EE_MODEL)
|
#define STORE_MODELVARS eeDirty(EE_MODEL)
|
||||||
#define STORE_GENERALVARS eeDirty(EE_GENERAL)
|
#define STORE_GENERALVARS eeDirty(EE_GENERAL)
|
||||||
|
|
||||||
|
extern void backlightOn();
|
||||||
|
|
||||||
#if defined (PCBARM)
|
#if defined (PCBARM)
|
||||||
#define BACKLIGHT_ON (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
|
#define BACKLIGHT_ON (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
|
||||||
#define BACKLIGHT_OFF (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
|
#define BACKLIGHT_OFF (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user