2017-12-01 18:48:08 +00:00
|
|
|
/*! \file tuner.c
|
|
|
|
\brief Tuning application and RSSI tool.
|
2017-11-30 01:20:06 +00:00
|
|
|
|
2017-12-01 18:48:08 +00:00
|
|
|
This quick little tool allows the user to tune the radio between
|
|
|
|
configured and VFO frequencies.
|
2017-11-30 01:20:06 +00:00
|
|
|
|
2017-12-03 17:01:56 +00:00
|
|
|
+ and - change the channel, / shows the current working frequency,
|
|
|
|
and 7 measures the signal strength on the current channel.
|
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
The = button can be used to set a VFO frequency.
|
2017-11-30 01:20:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
#include<msp430.h>
|
2018-04-15 22:21:30 +00:00
|
|
|
#include<string.h>
|
2017-11-30 01:20:06 +00:00
|
|
|
#include "api.h"
|
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
//Draws the codeplug name.
|
|
|
|
static void draw(){
|
|
|
|
lcd_string(codeplug_name());
|
|
|
|
}
|
2017-11-30 01:20:06 +00:00
|
|
|
|
2017-12-01 18:48:08 +00:00
|
|
|
//! Enter the tuner tool.
|
|
|
|
void tuner_init(){
|
2017-11-30 01:20:06 +00:00
|
|
|
/* Begin by initializing the radio if we have one, or jumping to the
|
2017-11-30 16:05:07 +00:00
|
|
|
next app if we don't.
|
|
|
|
|
|
|
|
While the radio is on, we keep it in the IDLE state except for
|
|
|
|
once per second, when we briefly jump to receive mode to measure
|
|
|
|
the RSSI.
|
2017-11-30 01:20:06 +00:00
|
|
|
*/
|
|
|
|
if(has_radio){
|
|
|
|
radio_on();
|
|
|
|
radio_writesettings(0);
|
|
|
|
radio_writepower(0x25);
|
2017-12-03 03:49:33 +00:00
|
|
|
codeplug_setfreq();
|
|
|
|
radio_strobe(RF_SCAL);
|
2018-06-12 14:26:45 +00:00
|
|
|
draw();
|
2017-11-30 01:20:06 +00:00
|
|
|
}else{
|
|
|
|
app_next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//! Exit the radio tool.
|
2017-12-01 18:48:08 +00:00
|
|
|
int tuner_exit(){
|
2017-11-30 01:20:06 +00:00
|
|
|
/* Always turn the radio off at exit.
|
|
|
|
*/
|
|
|
|
radio_off();
|
|
|
|
|
|
|
|
//Allow the exit.
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-31 21:46:09 +00:00
|
|
|
|
|
|
|
//! Last character pressed in the tuner.
|
2018-04-15 21:41:13 +00:00
|
|
|
static int vfosetmode=0;
|
|
|
|
static int rssi=0x5;
|
2018-01-31 21:46:09 +00:00
|
|
|
|
2018-04-15 22:21:30 +00:00
|
|
|
|
|
|
|
int vfosetmode_bufferi;
|
|
|
|
char vfosetmode_buffer[9];
|
|
|
|
|
|
|
|
static void vfosetmode_apply(){
|
|
|
|
long f=atol(vfosetmode_buffer);
|
|
|
|
|
|
|
|
vfosetmode=0;
|
|
|
|
printf("Setting frequency to %ld\n",f);
|
|
|
|
codeplug_setvfofreq((float) f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vfosetmode_keypress(char ch){
|
|
|
|
//Numbers populate a buffer character.
|
|
|
|
if(ch>='0' && ch<='9')
|
|
|
|
vfosetmode_buffer[vfosetmode_bufferi++]=ch;
|
|
|
|
|
|
|
|
//Exit when we have all characters or = is pressed again.
|
|
|
|
if(ch=='=' || vfosetmode_bufferi==8){
|
|
|
|
vfosetmode_apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vfosetmode_draw(){
|
|
|
|
/* This is called four times a second when we are setting the VFO
|
|
|
|
frequency. Activate the mode by pressing the = button.
|
|
|
|
*/
|
|
|
|
clearperiods();
|
|
|
|
lcd_string(vfosetmode_buffer);
|
|
|
|
setperiod(5,1);
|
|
|
|
setperiod(2,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-31 21:46:09 +00:00
|
|
|
//! Tuner keypress callback.
|
2018-02-08 22:21:58 +00:00
|
|
|
int tuner_keypress(char ch){
|
2018-04-15 22:21:30 +00:00
|
|
|
if(vfosetmode){
|
|
|
|
vfosetmode_keypress(ch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-31 21:46:09 +00:00
|
|
|
switch(ch){
|
2018-04-15 21:41:13 +00:00
|
|
|
default:
|
|
|
|
draw();
|
|
|
|
break;
|
2018-01-31 21:46:09 +00:00
|
|
|
case '+': //Next channel.
|
|
|
|
codeplug_next();
|
|
|
|
codeplug_setfreq();
|
|
|
|
break;
|
|
|
|
case '-': //Previous channel.
|
|
|
|
codeplug_prev();
|
|
|
|
codeplug_setfreq();
|
|
|
|
break;
|
2018-04-15 21:41:13 +00:00
|
|
|
case '/': //Show the frequency.
|
|
|
|
lcd_number(codeplug_getfreq()/10);
|
|
|
|
break;
|
2018-04-15 22:21:30 +00:00
|
|
|
case '=': //Set a VFO frequency.
|
|
|
|
vfosetmode=1;
|
|
|
|
//Clear all eight digits, plus null terminator.
|
|
|
|
memset(vfosetmode_buffer,'0',9);
|
|
|
|
vfosetmode_bufferi=0;
|
2018-04-15 21:41:13 +00:00
|
|
|
break;
|
|
|
|
case '7': //Show snapshot of scalar RSSI.
|
|
|
|
lcd_number(rssi);
|
|
|
|
lcd_string("RSSI");
|
|
|
|
break;
|
2018-01-31 21:46:09 +00:00
|
|
|
}
|
2018-02-08 22:21:58 +00:00
|
|
|
|
|
|
|
return 1;//Redraw.
|
2018-01-31 21:46:09 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
|
2017-11-30 01:20:06 +00:00
|
|
|
//! Draw the screen and increase the count.
|
2017-12-01 18:48:08 +00:00
|
|
|
void tuner_draw(){
|
2017-11-30 16:05:07 +00:00
|
|
|
static int i=0;
|
2017-11-30 01:20:06 +00:00
|
|
|
|
2018-04-15 22:21:30 +00:00
|
|
|
//No sense using the radio when we don't yet know the frequency.
|
|
|
|
if(vfosetmode){
|
|
|
|
vfosetmode_draw();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
/* Every other frame, we grab the signal strength. Highest
|
|
|
|
stays. */
|
|
|
|
if(!(i&1))
|
|
|
|
rssi=radio_getrssi();
|
2017-12-01 18:48:08 +00:00
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
//Draw the new strength.
|
|
|
|
clearperiods();
|
|
|
|
switch(rssi&0xF0){
|
|
|
|
case 0xF0:
|
|
|
|
case 0xE0:
|
|
|
|
setperiod(0,1);
|
|
|
|
case 0xD0:
|
|
|
|
setperiod(1,1);
|
|
|
|
case 0xC0:
|
|
|
|
case 0xB0:
|
|
|
|
setperiod(2,1);
|
|
|
|
case 0xA0:
|
|
|
|
case 0x90:
|
|
|
|
setperiod(3,1);
|
|
|
|
case 0x80:
|
|
|
|
case 0x70:
|
|
|
|
setperiod(4,1);
|
|
|
|
case 0x60:
|
|
|
|
case 0x50:
|
|
|
|
setperiod(5,1);
|
|
|
|
case 0x40:
|
|
|
|
case 0x30:
|
|
|
|
setperiod(6,1);
|
|
|
|
case 0x20:
|
|
|
|
setperiod(7,1);
|
2017-11-30 01:20:06 +00:00
|
|
|
}
|
2018-04-15 21:41:13 +00:00
|
|
|
|
2017-11-30 01:20:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 21:41:13 +00:00
|
|
|
|