From 41548163cf9b57ac67575f470e192bbb2ba8c798 Mon Sep 17 00:00:00 2001 From: phdlee Date: Tue, 17 Jul 2018 11:21:24 +0900 Subject: [PATCH] Support I2C S-Meter --- ubitx_20/ubitx_20.ino | 2 +- ubitx_20/ubitx_lcd_nextion.ino | 62 ++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/ubitx_20/ubitx_20.ino b/ubitx_20/ubitx_20.ino index 6e2f910..0281112 100644 --- a/ubitx_20/ubitx_20.ino +++ b/ubitx_20/ubitx_20.ino @@ -6,7 +6,7 @@ // So I put + in the sense that it was improved one by one based on Original Firmware. // This firmware has been gradually changed based on the original firmware created by Farhan, Jack, Jerry and others. -#define FIRMWARE_VERSION_INFO F("+v1.095") +#define FIRMWARE_VERSION_INFO F("+v1.097") #define FIRMWARE_VERSION_NUM 0x04 //1st Complete Project : 1 (Version 1.061), 2st Project : 2, 1.08: 3, 1.09 : 4 /** diff --git a/ubitx_20/ubitx_lcd_nextion.ino b/ubitx_20/ubitx_lcd_nextion.ino index db587dc..1ed8436 100644 --- a/ubitx_20/ubitx_lcd_nextion.ino +++ b/ubitx_20/ubitx_lcd_nextion.ino @@ -56,6 +56,53 @@ void LCD_Init(void) //initMeter(); //for Meter Display } +//=================================================================== +//I2C Signal Meter, Version 1.097 +// +//=================================================================== + +#define USE_I2CSMETER +//S-Meter Address +#define I2CMETER_ADDR 0x6A +//VALUE TYPE============================================ +//Signal +#define I2CMETER_CALCS 0x59 //Calculated Signal Meter +#define I2CMETER_UNCALCS 0x58 //Uncalculated Signal Meter + +//Power +#define I2CMETER_CALCP 0x57 //Calculated Power Meter +#define I2CMETER_UNCALCP 0x56 //UnCalculated Power Meter + +//SWR +#define I2CMETER_CALCR 0x55 //Calculated SWR Meter +#define I2CMETER_UNCALCR 0x54 //Uncalculated SWR Meter + +// 0xA0 ~ 0xCF : CW Decode Mode + 100Hz ~ +// 0xD0 ~ 0xF3 : RTTY Decode Mode + 100Hz ~ +// 0x10 ~ 0x30 : Spectrum Mode +int GetI2CSmeterValue(int valueType) +{ + if (valueType > 0) + { + Wire.beginTransmission(I2CMETER_ADDR); //j : S-Meter + Wire.write(valueType); //Y : Get Value Type + Wire.endTransmission(); + } + + Wire.requestFrom(I2CMETER_ADDR, 1); + for (int i = 0; i < 100; i++) + { + if (Wire.available() > 0) + { + return Wire.read(); + } + else + { + delay(1); + } + } +} + //=================================================================== //Begin of Nextion LCD Protocol // @@ -675,6 +722,10 @@ void sendResponseData(int protocolType, unsigned long startFreq, unsigned int se setFrequency(startFreq + (k * sendOption1)); //Wait time for charging //delay(10); + +#ifdef USE_I2CSMETER + readedValue = GetI2CSmeterValue(I2CMETER_UNCALCS); +#else //ADC readedValue = analogRead(ANALOG_SMETER); @@ -689,6 +740,7 @@ void sendResponseData(int protocolType, unsigned long startFreq, unsigned int se { readedValue=255; } +#endif } else { @@ -960,7 +1012,10 @@ void idle_process() if (((displayOption1 & 0x08) == 0x08 && (sdrModeOn == 0)) && (++checkCountSMeter > SMeterLatency)) { int newSMeter; - + +#ifdef USE_I2CSMETER + scaledSMeter = GetI2CSmeterValue(I2CMETER_CALCS); +#else //VK2ETA S-Meter from MAX9814 TC pin newSMeter = analogRead(ANALOG_SMETER) / 4; @@ -976,7 +1031,8 @@ void idle_process() break; } } - + +#endif checkCountSMeter = 0; //Reset Latency time } //end of S-Meter @@ -1001,7 +1057,7 @@ void SendUbitxData(void) EEPROM.get(EXTERNAL_DEVICE_OPT1, nextionDisplayOption); SendCommandUL(CMD_DISP_OPTION2, nextionDisplayOption); - SendCommandStr(CMD_VERSION, "+v1.095"); //Version + SendCommandStr(CMD_VERSION, "+v1.097"); //Version SendEEPromData(CMD_CALLSIGN, 0, userCallsignLength -1, 0); /*