add extended Keys (mode, band, tunestep) and i2clcd working

This commit is contained in:
phdlee 2018-04-17 21:26:29 +09:00
parent 0e245fc488
commit f600c18541
6 changed files with 173 additions and 171 deletions

View File

@ -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
//==============================================================================
@ -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);

View File

@ -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; //
@ -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())
@ -621,7 +726,7 @@ void checkButton(){
}
//delay(50);//debounce
}
#endif
/************************************
Replace function by KD8CEC
@ -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

View File

@ -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

View File

@ -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)
@ -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)
@ -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;

View File

@ -39,7 +39,7 @@
But keep it as long as the original author of the code.
Ian KD8CEC
**************************************************************************/
#define I2C_DISPLAY_ADDRESS 0x27
#define I2C_DISPLAY_ADDRESS 0x3F //0x27
#define En B00000100 // Enable bit
#define Rw B00000010 // Read/Write bit
@ -135,10 +135,22 @@ void LCD_Send(uint8_t value, uint8_t mode)
write4bits((lownib)|mode);
}
// Turn the (optional) backlight off/on
void noBacklight(void) {
_backlightval=LCD_NOBACKLIGHT;
expanderWrite(0);
}
void backlight(void) {
_backlightval=LCD_BACKLIGHT;
expanderWrite(0);
}
void LCD1602_Init()
{
//I2C Init
_Addr;
_Addr = I2C_DISPLAY_ADDRESS;
_cols = 16;
_rows = 2;
_backlightval = LCD_NOBACKLIGHT;
@ -180,6 +192,8 @@ void LCD1602_Init()
delayMicroseconds(1000); // this command takes a long time!
LCD_Command(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT);
backlight();
}
void LCD_Print(const char *c)
@ -219,92 +233,12 @@ LiquidCrystal lcd(8,9,10,11,12,13);
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)
{
LCD1602_Init();
initMeter(); //for Meter Display
}
//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) {

View File

@ -162,12 +162,37 @@ void drawMeter(int needle)
//returns true if the button is pressed
int btnDown(void){
#ifdef EXTEND_KEY_GROUP1
if (analogRead(FBUTTON) > FUNCTION_KEY_ADC)
return 0;
else
return 1;
#else
if (digitalRead(FBUTTON) == HIGH)
return 0;
else
return 1;
#endif
}
#ifdef EXTEND_KEY_GROUP1
int getBtnStatus(void){
int readButtonValue = analogRead(FBUTTON);
if (analogRead(FBUTTON) < FUNCTION_KEY_ADC)
return FKEY_PRESS;
else
{
for (int i = 0; i < 16; i++)
if (KeyValues[i][0] <= readButtonValue && KeyValues[i][1] >= readButtonValue)
return i;
}
return -1;
}
#endif
int enc_prev_state = 3;
/**