Merge master into morse-menu

This commit is contained in:
Reed Nightingale 2020-01-28 20:45:33 -08:00
commit 0a880fe8a6
8 changed files with 112 additions and 47 deletions

View File

@ -101,7 +101,12 @@ const uint8_t FreeSansBold9pt7bBitmaps[] PROGMEM = {
0x78, 0x1E, 0x03, 0x00, 0xC0, 0x70, 0x38, 0x0E, 0x00, 0xFE, 0xFE, 0x0E,
0x1C, 0x38, 0x38, 0x70, 0xE0, 0xFF, 0xFF, 0x37, 0x66, 0x66, 0x6E, 0xE6,
0x66, 0x66, 0x67, 0x30, 0xFF, 0xFF, 0x80, 0xCE, 0x66, 0x66, 0x67, 0x76,
0x66, 0x66, 0x6E, 0xC0, 0x71, 0x8E };
0x66, 0x66, 0x6E, 0xC0, 0x71, 0x8E, 0x0C, 0x00, 0xF0, 0x00, 0x8F, 0x10,
0x1C, 0xF3, 0x83, 0xFF, 0xFC, 0x7F, 0xFF, 0xE3, 0xF0, 0xFE, 0x1E, 0x07,
0xC1, 0xC0, 0x38, 0xF8, 0x01, 0xFF, 0x80, 0x1F, 0xF8, 0x01, 0xFF, 0x80,
0x1F, 0x1C, 0x03, 0x81, 0xE0, 0x78, 0x3F, 0x0F, 0xC7, 0xFF, 0xFE, 0x3F,
0xFF, 0xC3, 0xCF, 0x38, 0x08, 0xF1, 0x00, 0x0F, 0x00
};
const GFXglyph FreeSansBold9pt7bGlyphs[] PROGMEM = {
{ 0, 0, 0, 5, 0, 1 }, // 0x20 ' '
@ -198,11 +203,16 @@ const GFXglyph FreeSansBold9pt7bGlyphs[] PROGMEM = {
{ 1207, 4, 17, 7, 1, -12 }, // 0x7B '{'
{ 1216, 1, 17, 5, 2, -12 }, // 0x7C '|'
{ 1219, 4, 17, 7, 2, -12 }, // 0x7D '}'
{ 1228, 8, 2, 9, 0, -4 } }; // 0x7E '~'
{ 1228, 8, 2, 9, 0, -4 }, // 0x7E '~'
{ 1231, 20, 20, 22, 1, -12 }, // 0x7F gear icon
{ 1231, 0, 0, 10, 0, 1 }, // 0x80 10px space to match numbers
{ 1231, 0, 0, 4, 0, 1 }, // 0x81 4px space to match period
};
const GFXfont FreeSansBold9pt7b PROGMEM = {
(uint8_t *)FreeSansBold9pt7bBitmaps,
(GFXglyph *)FreeSansBold9pt7bGlyphs,
0x20, 0x7E, 22 };
// Approx. 1902 bytes
0x20, //first character
0x81, //last character
22 //yAdvance (newline)
};

View File

@ -38,8 +38,6 @@ static const unsigned int cwAdcDotTo = 600;
static const unsigned int cwAdcDashFrom = cwAdcDotTo + 1;
static const unsigned int cwAdcDashTo = 800;
static const unsigned int delayBeforeCWStartTime = 50;
/**
* Starts transmitting the carrier with the sidetone
* It assumes that we have called cwTxStart and not called cwTxStop
@ -93,7 +91,7 @@ char update_PaddleLatch(bool isUpdateKeyState) {
else{
if (KeyerMode_e::KEYER_STRAIGHT != globalSettings.keyerMode)
tmpKeyerControl = 0 ;
else if (paddle <= cwAdcSTTo)
else if (paddle <= cwAdcDashTo)
tmpKeyerControl = DIT_L ;
else
tmpKeyerControl = 0 ;
@ -156,8 +154,6 @@ void cwKeyer(void){
case KEYED_PREP:
//modified KD8CEC
if (!globalSettings.txActive){
//DelayTime Option
active_delay(delayBeforeCWStartTime * 2);
globalSettings.cwExpirationTimeMs = millis() + globalSettings.cwActiveTimeoutMs;
startTx(TuningMode_e::TUNE_CW);
}
@ -205,11 +201,7 @@ void cwKeyer(void){
// if we are here, it is only because the key is pressed
if (!globalSettings.txActive){
startTx(TuningMode_e::TUNE_CW);
//DelayTime Option
active_delay(delayBeforeCWStartTime * 2);
globalSettings.cwExpirationTimeMs = millis() + globalSettings.cwDitDurationMs;
globalSettings.cwExpirationTimeMs = millis() + globalSettings.cwActiveTimeoutMs;
}
cwKeydown();

View File

@ -11,7 +11,8 @@ struct Point ts_point;
/*
* This formats the frequency given in f
*/
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width)
{
memset(buff, 0, buff_size);
ultoa(freq, buff, DEC);
@ -20,10 +21,20 @@ void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
const uint8_t num_leading_digits_raw = num_digits % 3;
const uint8_t num_leading_digits = (0 == num_leading_digits_raw) ? 3 : num_leading_digits_raw;
if(0 == num_spacers){
return;
if(0 < fixed_width){
while(0 < fixed_width - num_digits - num_spacers){
if(0 == fixed_width % 4){
buff[0] = '\x81';//separator size
}
else{
buff[0] = '\x80';//digit size
}
--fixed_width;
++buff;
}
}
ultoa(freq, buff, DEC);
buff += num_leading_digits;
num_digits -= num_leading_digits;
for(int i = num_digits-1; i >= 0; --i){
@ -214,13 +225,6 @@ void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t
tft.drawCharGFX(x,y,c,color,bg,1);
}
void displayRawText(char *text, int x1, int y1, int color, int background){
tft.setTextColor(color,background);
tft.setCursor(x1,y1);
tft.setBound(0,320);
tft.print(text);
}
void displayRawText(char *text, int x1, int y1, int w, int color, int background){
tft.setTextColor(color,background);
tft.setCursor(x1,y1);
@ -228,7 +232,8 @@ void displayRawText(char *text, int x1, int y1, int w, int color, int background
tft.print(text);
}
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border) {
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border, TextJustification_e justification)
{
displayFillrect(x1, y1, w ,h, background);
displayRect(x1, y1, w ,h, border);
@ -237,7 +242,15 @@ void displayText(char *text, int x1, int y1, int w, int h, int color, int backgr
uint16_t width_out;
uint16_t height_out;
tft.getTextBounds(text,x1,y1,&x1_out,&y1_out,&width_out,&height_out,w);
if(TextJustification_e::Center == justification){
x1 += (w - ( (int32_t)width_out + (x1_out-x1)))/2;
}
else if(TextJustification_e::Right == justification){
x1 += w - ((int32_t)width_out + (x1_out-x1));
}
else{
x1 += 2;//Give a little bit of padding from the border
}
y1 += (ubitx_font->yAdvance + h - ( (int32_t)height_out))/2;
displayRawText(text,x1,y1,w,color,background);
}

View File

@ -7,6 +7,13 @@ struct Point {
};
extern struct Point ts_point;
enum TextJustification_e : uint8_t
{
Left,
Right,
Center
};
void displayInit();
void displayClear(unsigned int color);
void displayPixel(unsigned int x, unsigned int y, unsigned int c);
@ -15,10 +22,9 @@ void displayVline(unsigned int x, unsigned int y, unsigned int l, unsigned int c
void displayRect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c);
void displayFillrect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c);
void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg);
void displayRawText(char *text, int x1, int y1, int color, int background);
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border);
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border, TextJustification_e justification = TextJustification_e::Center);
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size);
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width = 0);
/* touch functions */
boolean readTouch();

View File

@ -69,7 +69,7 @@ void displayDialog(const char* title,
strncpy_P(b,title,sizeof(b));
displayText(b, LAYOUT_TITLE_X, LAYOUT_TITLE_Y, LAYOUT_TITLE_WIDTH, LAYOUT_TITLE_HEIGHT, COLOR_TEXT, COLOR_TITLE_BACKGROUND, COLOR_ACTIVE_BORDER);
strncpy_P(b,instructions,sizeof(b));
displayText(b, LAYOUT_INSTRUCTIONS_TEXT_X, LAYOUT_INSTRUCTIONS_TEXT_Y, LAYOUT_INSTRUCTIONS_TEXT_WIDTH, LAYOUT_INSTRUCTIONS_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND);
displayText(b, LAYOUT_INSTRUCTIONS_TEXT_X, LAYOUT_INSTRUCTIONS_TEXT_Y, LAYOUT_INSTRUCTIONS_TEXT_WIDTH, LAYOUT_INSTRUCTIONS_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Left);
strncpy_P(b,(const char*)F("Push Tune to Save"),sizeof(b));
displayText(b, LAYOUT_CONFIRM_TEXT_X, LAYOUT_CONFIRM_TEXT_Y, LAYOUT_CONFIRM_TEXT_WIDTH, LAYOUT_CONFIRM_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND);
}
@ -514,11 +514,11 @@ void drawMenu(const MenuItem_t* const items, const uint16_t num_items)
for(unsigned int i = 1; i < num_items; ++i){
memcpy_P(&mi,&items[i],sizeof(mi));
strncpy_P(b,mi.ItemName,sizeof(b));
displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (i-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER);
displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (i-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER, TextJustification_e::Left);
}
memcpy_P(&mi,&exitMenu,sizeof(mi));
strncpy_P(b,mi.ItemName,sizeof(b));
displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (num_items-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER);
displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (num_items-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER, TextJustification_e::Left);
}
void movePuck(unsigned int old_index, unsigned int new_index)

View File

@ -1,9 +1,10 @@
#include <Arduino.h>
#include "morse.h"
#include "nano_gui.h"
#include "settings.h"
#include "setup.h"
#include "ubitx.h"
#include "nano_gui.h"
#include "version.h"
static const unsigned int COLOR_TEXT = DISPLAY_WHITE;
static const unsigned int COLOR_BACKGROUND = DISPLAY_NAVY;
@ -22,6 +23,8 @@ static const unsigned int COLOR_ACTIVE_TEXT = DISPLAY_BLACK;
static const unsigned int COLOR_ACTIVE_BACKGROUND = DISPLAY_ORANGE;
static const unsigned int COLOR_ACTIVE_BORDER = DISPLAY_WHITE;
static const unsigned int COLOR_VERSION_TEXT = DISPLAY_LIGHTGREY;
static const unsigned int LAYOUT_VFO_LABEL_X = 0;
static const unsigned int LAYOUT_VFO_LABEL_Y = 10;
static const unsigned int LAYOUT_VFO_LABEL_WIDTH = 159;
@ -42,9 +45,14 @@ static const unsigned int LAYOUT_BUTTON_PITCH_Y = 40;
static const unsigned int LAYOUT_CW_TEXT_X = 0;
static const unsigned int LAYOUT_CW_TEXT_Y = LAYOUT_BUTTON_Y + 3*LAYOUT_BUTTON_PITCH_Y + 1;
static const unsigned int LAYOUT_CW_TEXT_WIDTH = 320;
static const unsigned int LAYOUT_CW_TEXT_WIDTH = 220;
static const unsigned int LAYOUT_CW_TEXT_HEIGHT = 36;
static const unsigned int LAYOUT_VERSION_TEXT_X = LAYOUT_CW_TEXT_X + LAYOUT_CW_TEXT_WIDTH + 1;
static const unsigned int LAYOUT_VERSION_TEXT_Y = LAYOUT_CW_TEXT_Y;
static const unsigned int LAYOUT_VERSION_TEXT_WIDTH = 320 - LAYOUT_CW_TEXT_WIDTH - 1;
static const unsigned int LAYOUT_VERSION_TEXT_HEIGHT = LAYOUT_CW_TEXT_HEIGHT;
static const unsigned int LAYOUT_TX_X = 280;
static const unsigned int LAYOUT_TX_Y = LAYOUT_MODE_TEXT_Y;
static const unsigned int LAYOUT_TX_WIDTH = 40;
@ -123,7 +131,7 @@ constexpr Button btn_set[BUTTON_TOTAL] PROGMEM = {
{LAYOUT_BUTTON_X + 0*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_15 , "15", '5', msIgnore},
{LAYOUT_BUTTON_X + 1*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_10 , "10", '1', msIgnore},
{LAYOUT_BUTTON_X + 2*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_BLANK_1, "", '\0', msIgnore},
{LAYOUT_BUTTON_X + 3*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_MNU, "MNU", 'M', msIgnore},
{LAYOUT_BUTTON_X + 3*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_MNU, "\x7F", 'M', msIgnore},
{LAYOUT_BUTTON_X + 4*LAYOUT_BUTTON_PITCH_X, LAYOUT_BUTTON_Y + 2*LAYOUT_BUTTON_PITCH_Y, LAYOUT_BUTTON_WIDTH, LAYOUT_BUTTON_HEIGHT, BUTTON_FRQ, "FRQ", 'F', msIgnore},
};
@ -244,11 +252,12 @@ void displayVFO(Vfo_e vfo){
}
}
c[1] = ':';
c[2] = ' ';
if (VFO_A == vfo){
getButton(BUTTON_VFOA, &button);
formatFreq(globalSettings.vfoA.frequency, c+2, sizeof(c)-2);
formatFreq(globalSettings.vfoA.frequency, c+3, sizeof(c)-3, 10);
if (VFO_A == globalSettings.activeVfo){
displayColor = COLOR_ACTIVE_VFO_TEXT;
@ -263,7 +272,7 @@ void displayVFO(Vfo_e vfo){
if (VFO_B == vfo){
getButton(BUTTON_VFOB, &button);
formatFreq(globalSettings.vfoB.frequency, c+2, sizeof(c)-2);
formatFreq(globalSettings.vfoB.frequency, c+3, sizeof(c)-3, 10);
if (VFO_B == globalSettings.activeVfo){
displayColor = COLOR_ACTIVE_VFO_TEXT;
@ -453,16 +462,29 @@ void enterFreq(){
switch(button.id){
case KEYS_OK:
{
long freq = atol(c);
if((LOWEST_FREQ/1000 <= freq) && (freq <= HIGHEST_FREQ/1000)){
freq *= 1000L;
setFrequency(freq);
uint32_t new_freq = atol(c);
if((LOWEST_FREQ/1000 <= new_freq) && (new_freq <= HIGHEST_FREQ/1000)){
new_freq *= 1000L;
uint32_t prev_freq = GetActiveVfoFreq();
//Transition from below to above the traditional threshold for USB
if(prev_freq < THRESHOLD_USB_LSB && new_freq >= THRESHOLD_USB_LSB){
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
}
//Transition from aboveo to below the traditional threshold for USB
if(prev_freq >= THRESHOLD_USB_LSB && new_freq < THRESHOLD_USB_LSB){
SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB);
}
if (VFO_A == globalSettings.activeVfo){
globalSettings.vfoA.frequency = freq;
globalSettings.vfoA.frequency = new_freq;
}
else{
globalSettings.vfoB.frequency = freq;
globalSettings.vfoB.frequency = new_freq;
}
setFrequency(new_freq);
saveVFOs();
}
exit = true;
@ -528,9 +550,14 @@ void drawCWStatus(){
itoa(globalSettings.cwSideToneFreq, c, 10);
strncat(b, c, sizeof(b) - strlen(b));
strncat_P(b,(const char*)F("hz"), sizeof(b) - strlen(b));
displayText(b, LAYOUT_CW_TEXT_X, LAYOUT_CW_TEXT_Y, LAYOUT_CW_TEXT_WIDTH, LAYOUT_CW_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND);
displayText(b, LAYOUT_CW_TEXT_X, LAYOUT_CW_TEXT_Y, LAYOUT_CW_TEXT_WIDTH, LAYOUT_CW_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Left);
}
void drawVersion()
{
strncpy_P(b,VERSION_STRING,sizeof(b));
displayText(b, LAYOUT_VERSION_TEXT_X, LAYOUT_VERSION_TEXT_Y, LAYOUT_VERSION_TEXT_WIDTH, LAYOUT_VERSION_TEXT_HEIGHT, COLOR_VERSION_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Right);
}
void drawTx(){
if (globalSettings.txActive){
@ -543,6 +570,7 @@ void drawTx(){
}
void drawStatusbar(){
drawCWStatus();
drawVersion();
}
void guiUpdate(){
@ -645,10 +673,13 @@ void cwToggle(struct Button *b){
}
void sidebandToggle(Button* button){
if(BUTTON_LSB == button->id)
if(BUTTON_LSB == button->id){
SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB);
else
}
else{
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
}
setFrequency(GetActiveVfoFreq());
struct Button button2;
getButton(BUTTON_USB, &button2);

4
version.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "version.h"
const char VERSION_STRING_PRIVATE [] PROGMEM = "R1.1.1";
const char* const VERSION_STRING = VERSION_STRING_PRIVATE;

9
version.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <avr/pgmspace.h>
/*
* VERSION_STRING is a PROGMEM string, so extract it before use, e.g.
* strncpy_P(char_buffer_out,VERSION_STRING,size_of_char_buffer_out);
*/
extern const char* const VERSION_STRING;