Skip to content

Commit

Permalink
add extended Keys (mode, band, tunestep) and i2clcd working
Browse files Browse the repository at this point in the history
  • Loading branch information
phdlee committed Apr 17, 2018
1 parent 0e245fc commit f600c18
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 171 deletions.
15 changes: 13 additions & 2 deletions ubitx_20/ubitx.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

//Depending on the type of LCD mounted on the uBITX, uncomment one of the options below.
//You must select only one.
#define UBITX_DISPLAY_LCD1602P //LCD mounted on unmodified uBITX
//#define UBITX_DISPLAY_LCD1602P //LCD mounted on unmodified uBITX
//#define UBITX_DISPLAY_LCD1602I //I2C type 16 x 02 LCD
//#define UBITX_DISPLAY_LCD1602I_CUST //I2C type 16 x 02 Custom Tiny Library
#define UBITX_DISPLAY_LCD1602I_CUST //I2C type 16 x 02 Custom Tiny Library
//#define UBITX_DISPLAY_LCD2004P //24 x 04 LCD
//#define UBITX_DISPLAY_LCD2004I //I2C type 24 x 04 LCD

//#define EXTEND_KEY_GROUP1 //MODE, BAND(-), BAND(+), STEP
//#define EXTEND_KEY_GROUP2 //Numeric (0~9), Point(.), Enter //Not supported in Version 1.0x

//==============================================================================
// Hardware, Define PIN Usage
//==============================================================================
Expand Down Expand Up @@ -93,9 +96,17 @@
#define printLineF1(x) (printLineF(1, x))
#define printLineF2(x) (printLineF(0, x))

#define FUNCTION_KEY_ADC 80 //MODE, BAND(-), BAND(+), STEP
#define FKEY_PRESS 120
#define FKEY_MODE 0
#define FKEY_BANDUP 1
#define FKEY_BANDDOWN 2
#define FKEY_STEP 3

extern unsigned long frequency;
extern byte WsprMSGCount;
extern byte sMeterLevels[9];
extern int KeyValues[16][2]; //ADC value Ranges for Extend Key

extern void printLine1(const char *c);
extern void printLine2(const char *c);
Expand Down
113 changes: 112 additions & 1 deletion ubitx_20/ubitx_20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ byte line2DisplayStatus = 0; //0:Clear, 1 : menu, 1: DisplayFrom Idle,
char lcdMeter[17];
byte sMeterLevels[9];

int KeyValues[16][2];
/*= {
{1023, 1025}, //1
{707, 711}, //5
{570, 574}, //9
{493, 500}, //13
{932, 936}, //2
{860, 864}, //3
{800, 805}, //4
{672, 676}, //6
{642, 646}, //7
{616, 620}, //8
{552, 556}, //10
{535, 539}, //11
{520, 524}, //12
{438, 442}, //14
{403, 407}, //15
{378, 382} //16
};
*/

byte isIFShift = 0; //1 = ifShift, 2 extend
int ifShiftValue = 0; //

Expand Down Expand Up @@ -603,7 +628,87 @@ void checkPTT(){
if (digitalRead(PTT) == 1 && inTx == 1)
stopTx();
}
#ifdef EXTEND_KEY_GROUP1
void checkButton(){
//only if the button is pressed
int keyStatus = getBtnStatus();
if (keyStatus == -1)
return;

delay(50);
keyStatus = getBtnStatus(); //will be remove 3 lines
if (keyStatus == -1)
return;

if (keyStatus == FKEY_PRESS) //Menu Key
doMenu();
else if (keyStatus <= FKEY_STEP) //EXTEND KEY GROUP #1
{
if (keyStatus == FKEY_MODE) //Press Mode Key
{
if (cwMode == 1)
{
cwMode = 2;
}
else if (cwMode == 2)
{
cwMode = 0;
isUSB = 0;
}
else if (isUSB == 0)
{
isUSB = 1;
}
else
{
cwMode = 1;
}
}
//else if (keyStatus == FKEY_BANDDOWN) //Press Mode Key
//{
// setNextHamBandFreq(frequency, -1); //Prior Band
//}
else if (keyStatus == FKEY_BANDUP || keyStatus == FKEY_BANDDOWN) //Press Mode Key
{

char currentBandIndex = -1;

//Save Band Information
if (tuneTXType == 2 || tuneTXType == 3 || tuneTXType == 102 || tuneTXType == 103) { //only ham band move
currentBandIndex = getIndexHambanBbyFreq(frequency);

if (currentBandIndex >= 0) {
saveBandFreqByIndex(frequency, modeToByte(), currentBandIndex);
}
}

setNextHamBandFreq(frequency, keyStatus == FKEY_BANDDOWN ? -1 : 1); //Prior Band
}
else if (keyStatus == FKEY_STEP) //FKEY_BANDUP
{
if (++tuneStepIndex > 5)
tuneStepIndex = 1;

EEPROM.put(TUNING_STEP, tuneStepIndex);
printLine2ClearAndUpdate();
}

FrequencyToVFO(1);
SetCarrierFreq();
setFrequency(frequency);
//delay_background(delayTime, 0);
updateDisplay();
}

//wait for the button to go up again
while(keyStatus == getBtnStatus()) {
delay(10);
Check_Cat(0);
}
//delay(50);//debounce
}

#else
void checkButton(){
//only if the button is pressed
if (!btnDown())
Expand All @@ -621,7 +726,7 @@ void checkButton(){
}
//delay(50);//debounce
}

#endif

/************************************
Replace function by KD8CEC
Expand Down Expand Up @@ -832,6 +937,12 @@ void initSettings(){
sMeterLevels[i + 1] = EEPROM.read(S_METER_LEVELS + i);
}

//KeyValues
for (byte i = 0; i < 16; i++) {
KeyValues[i][0] = EEPROM.read(EXTENDED_KEY_RANGE + (i * 2));
KeyValues[i][1] = EEPROM.read(EXTENDED_KEY_RANGE + (i * 2) + 1);
}

//User callsign information
if (EEPROM.read(USER_CALLSIGN_KEY) == 0x59)
userCallsignLength = EEPROM.read(USER_CALLSIGN_LEN); //MAXIMUM 18 LENGTH
Expand Down
2 changes: 1 addition & 1 deletion ubitx_20/ubitx_eemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
// 256 ~ 1023 (EEProm Section #1)
// 255 ~ 101 (EEProm Section #2)
//==============================================================================
#define EXTENDED_KEY_RANGE 196 //Extended Key, KEY RANGE (MODE, BAND+, BAND-, TUNE_STEP, NUM0~NUM9, POINT, ENTER
#define S_METER_LEVELS 230 //LEVEL0 ~ LEVEL7


#define ADVANCED_FREQ_OPTION1 240 //Bit0: use IFTune_Value, Bit1 : use Stored enabled SDR Mode, Bit2 : dynamic sdr frequency
#define IF1_CAL 241
#define ENABLE_SDR 242
Expand Down
91 changes: 6 additions & 85 deletions ubitx_20/ubitx_lcd_1602i.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

//John(VK2ETA) Code
#include <LiquidCrystal_I2C.h>
#define I2C_DISPLAY_ADDRESS 0x27
#define I2C_DISPLAY_ADDRESS 0x3F //0x27
LiquidCrystal_I2C lcd(I2C_DISPLAY_ADDRESS,16,2); // set the LCD as a 16 chars and 2 line display

//LiquidCrystal_I2C lcd(0x27,16,2)
Expand All @@ -60,95 +60,13 @@ LiquidCrystal_I2C lcd(I2C_DISPLAY_ADDRESS,16,2); // set the LCD as a 16 chars a
char c[30], b[30];
char printBuff[2][17]; //mirrors what is showing on the two lines of the display

const PROGMEM uint8_t meters_bitmap[] = {
B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000 , //custom 1
B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000 , //custom 2
B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100 , //custom 3
B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110 , //custom 4
B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 , //custom 5
B01000, B11100, B01000, B00000, B10111, B10101, B10101, B10111 //custom 6
};

PGM_P p_metes_bitmap = reinterpret_cast<PGM_P>(meters_bitmap);

const PROGMEM uint8_t lock_bitmap[8] = {
0b01110,
0b10001,
0b10001,
0b11111,
0b11011,
0b11011,
0b11111,
0b00000};
PGM_P plock_bitmap = reinterpret_cast<PGM_P>(lock_bitmap);


// initializes the custom characters
// we start from char 1 as char 0 terminates the string!
void initMeter(){
uint8_t tmpbytes[8];
byte i;

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(plock_bitmap + i);
lcd.createChar(0, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i);
lcd.createChar(1, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i + 8);
lcd.createChar(2, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i + 16);
lcd.createChar(3, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i + 24);
lcd.createChar(4, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i + 32);
lcd.createChar(5, tmpbytes);

for (i = 0; i < 8; i++)
tmpbytes[i] = pgm_read_byte(p_metes_bitmap + i + 40);
lcd.createChar(6, tmpbytes);
}

void LCD_Init(void)
{
lcd.begin(16, 2);
initMeter(); //for Meter Display
lcd.backlight();
}

//by KD8CEC
//0 ~ 25 : 30 over : + 10
void drawMeter(int needle) {
//5Char + O over
int i;

for (i = 0; i < 5; i++) {
if (needle >= 5)
lcdMeter[i] = 5; //full
else if (needle > 0)
lcdMeter[i] = needle; //full
else //0
lcdMeter[i] = 0x20;

needle -= 5;
}

if (needle > 0)
lcdMeter[5] = 6;
else
lcdMeter[5] = 0x20;
}



// The generic routine to display one line on the LCD
void printLine(unsigned char linenmbr, const char *c) {
if ((displayOption1 & 0x01) == 0x01)
Expand All @@ -164,7 +82,10 @@ void printLine(unsigned char linenmbr, const char *c) {
}
}
}

void LCD_CreateChar(int aaa, int bbb)
{

}
void printLineF(char linenmbr, const __FlashStringHelper *c)
{
int i;
Expand Down
Loading

0 comments on commit f600c18

Please sign in to comment.