diff --git a/rfapp/spectrum.c b/rfapp/spectrum.c old mode 100644 new mode 100755 index dee003e9..d6778076 --- a/rfapp/spectrum.c +++ b/rfapp/spectrum.c @@ -1,14 +1,10 @@ #include -#include -#include -#include #include #include #include #include -#include #include #include #include @@ -20,12 +16,9 @@ #include #include -#include #include #include #include -#include -#include #include #include @@ -49,10 +42,6 @@ static volatile int displayMode = DEFAULT_MODE; void spectrum_callback(uint8_t* buf, int bufLen) { TOGGLE(LED2); - if (displayMode == MODE_SPECTRUM) - lcdClear(); - else if (displayMode == MODE_WATERFALL) - lcdShift(0,1,0); for(int i = 0; i < 128; i++) // display 128 FFT magnitude points { @@ -61,7 +50,7 @@ void spectrum_callback(uint8_t* buf, int bufLen) if(i < 64) // negative frequencies v = buf[(bufLen/2)+64+i]; else // positive frequencies - v = buf[i-64]; + v = buf[i-63]; // fill display if (displayMode == MODE_SPECTRUM) @@ -74,14 +63,6 @@ void spectrum_callback(uint8_t* buf, int bufLen) lcdSetPixel(i,RESY-1,v); } } - - // text info - lcdSetCrsr(0,0); - lcdPrint("f="); - lcdPrint(IntToStr(freq/1000000,4,F_LONG)); - lcdPrintln("MHz "); - lcdPrintln("-5MHz 0 +5MHz"); - lcdDisplay(); } void spectrum_init() @@ -98,15 +79,17 @@ void spectrum_init() ON(EN_1V8); OFF(MIC_AMP_DIS); delayms(500); // doesn't work without - cpu_clock_set(204); // WARP SPEED! :-) si5351_init(); portapack_init(); - set_rx_mode(RECEIVER_CONFIGURATION_SPEC); specan_register_callback(spectrum_callback); // defaults: + // the frequency is either initialized to DEFAULT_FREQ or set by the frequency menu + // resetting it here would break the menu. + //freq = DEFAULT_FREQ; + displayMode = DEFAULT_MODE; } @@ -127,7 +110,24 @@ void spectrum_stop() //# MENU spectrum frequency void spectrum_frequency() { - freq=(int64_t)input_int("freq:",(int)(freq/1000000),50,4000,4)*1000000; + freq=(int64_t)input_int("freq:",(int)(freq/1000000),5,4000,4)*1000000; +} + +void display_draw() +{ + if (displayMode == MODE_SPECTRUM) + lcdClear(); + else if (displayMode == MODE_WATERFALL) + lcdShift(0,1,0); + + // text info + lcdSetCrsr(0,0); + lcdPrint("f="); + lcdPrint(IntToStr(freq/1000000,4,F_LONG)); + lcdPrintln("MHz "); + lcdPrintln("-5MHz 0 +5MHz"); + + lcdDisplay(); } //# MENU spectrum show @@ -139,50 +139,52 @@ void spectrum_show() set_freq(freq); while(1) { + display_draw(); + //getInputWaitRepeat does not seem to work? switch(getInputRaw()) { case BTN_UP: displayMode=MODE_WATERFALL; - while(getInputRaw()==BTN_UP) - ; + while(getInputRaw()==BTN_UP) + ; break; case BTN_DOWN: displayMode=MODE_SPECTRUM; - while(getInputRaw()==BTN_DOWN) - ; + while(getInputRaw()==BTN_DOWN) + ; break; case BTN_LEFT: - buttonPressTime = _timectr; + buttonPressTime = _timectr; freq -= 2000000; ssp1_set_mode_max2837(); set_freq(freq); - while(getInputRaw()==BTN_LEFT) - { - if (_timectr > buttonPressTime + FAST_CHANGE_DELAY/SYSTICKSPEED) - { - freq -= FAST_CHANGE_CHANGE; - ssp1_set_mode_max2837(); - set_freq(freq); - delayms(10); - } - } + while(getInputRaw()==BTN_LEFT){ + if (_timectr > buttonPressTime + FAST_CHANGE_DELAY/SYSTICKSPEED) + { + freq -= FAST_CHANGE_CHANGE; + ssp1_set_mode_max2837(); + set_freq(freq); + display_draw(); + delayms(10); + } + } break; case BTN_RIGHT: - buttonPressTime = _timectr; + buttonPressTime = _timectr; freq += 2000000; ssp1_set_mode_max2837(); set_freq(freq); - while(getInputRaw()==BTN_RIGHT) - { - if (_timectr > buttonPressTime + FAST_CHANGE_DELAY/SYSTICKSPEED) - { - freq += FAST_CHANGE_CHANGE; - ssp1_set_mode_max2837(); - set_freq(freq); - delayms(10); - } - } + while(getInputRaw()==BTN_RIGHT){ + if (_timectr > buttonPressTime + FAST_CHANGE_DELAY/SYSTICKSPEED) + { + freq += FAST_CHANGE_CHANGE; + ssp1_set_mode_max2837(); + set_freq(freq); + display_draw(); + delayms(10); + } + } break; case BTN_ENTER: spectrum_stop(); diff --git a/testapp/spectrum.c b/testapp/spectrum.c old mode 100644 new mode 100755 index 064c879a..d6778076 --- a/testapp/spectrum.c +++ b/testapp/spectrum.c @@ -1,14 +1,10 @@ #include -#include -#include -#include #include #include #include #include -#include #include #include #include @@ -20,12 +16,9 @@ #include #include -#include #include #include #include -#include -#include #include #include @@ -49,10 +42,6 @@ static volatile int displayMode = DEFAULT_MODE; void spectrum_callback(uint8_t* buf, int bufLen) { TOGGLE(LED2); - if (displayMode == MODE_SPECTRUM) - lcdClear(); - else if (displayMode == MODE_WATERFALL) - lcdShift(0,1,0); for(int i = 0; i < 128; i++) // display 128 FFT magnitude points { @@ -61,7 +50,7 @@ void spectrum_callback(uint8_t* buf, int bufLen) if(i < 64) // negative frequencies v = buf[(bufLen/2)+64+i]; else // positive frequencies - v = buf[i-64]; + v = buf[i-63]; // fill display if (displayMode == MODE_SPECTRUM) @@ -74,14 +63,6 @@ void spectrum_callback(uint8_t* buf, int bufLen) lcdSetPixel(i,RESY-1,v); } } - - // text info - lcdSetCrsr(0,0); - lcdPrint("f="); - lcdPrint(IntToStr(freq/1000000,4,F_LONG)); - lcdPrintln("MHz "); - lcdPrintln("-5MHz 0 +5MHz"); - lcdDisplay(); } void spectrum_init() @@ -98,11 +79,9 @@ void spectrum_init() ON(EN_1V8); OFF(MIC_AMP_DIS); delayms(500); // doesn't work without - cpu_clock_set(204); // WARP SPEED! :-) si5351_init(); portapack_init(); - set_rx_mode(RECEIVER_CONFIGURATION_SPEC); specan_register_callback(spectrum_callback); // defaults: @@ -131,7 +110,24 @@ void spectrum_stop() //# MENU spectrum frequency void spectrum_frequency() { - freq=(int64_t)input_int("freq:",(int)(freq/1000000),50,4000,4)*1000000; + freq=(int64_t)input_int("freq:",(int)(freq/1000000),5,4000,4)*1000000; +} + +void display_draw() +{ + if (displayMode == MODE_SPECTRUM) + lcdClear(); + else if (displayMode == MODE_WATERFALL) + lcdShift(0,1,0); + + // text info + lcdSetCrsr(0,0); + lcdPrint("f="); + lcdPrint(IntToStr(freq/1000000,4,F_LONG)); + lcdPrintln("MHz "); + lcdPrintln("-5MHz 0 +5MHz"); + + lcdDisplay(); } //# MENU spectrum show @@ -143,6 +139,8 @@ void spectrum_show() set_freq(freq); while(1) { + display_draw(); + //getInputWaitRepeat does not seem to work? switch(getInputRaw()) { @@ -167,6 +165,7 @@ void spectrum_show() freq -= FAST_CHANGE_CHANGE; ssp1_set_mode_max2837(); set_freq(freq); + display_draw(); delayms(10); } } @@ -182,6 +181,7 @@ void spectrum_show() freq += FAST_CHANGE_CHANGE; ssp1_set_mode_max2837(); set_freq(freq); + display_draw(); delayms(10); } }