diff --git a/source/broadcast.c b/source/broadcast.c index 258a6ea..175d367 100644 --- a/source/broadcast.c +++ b/source/broadcast.c @@ -71,8 +71,6 @@ static void _stateInit(ACCESSORY_t *accy) driver_setFrequency(freq); - - driver_broadcastOn(true); ACCY_setTimeout(accy, 500); diff --git a/source/dds.h b/source/dds.h index 3cca595..d108199 100644 --- a/source/dds.h +++ b/source/dds.h @@ -7,7 +7,7 @@ #define TX_SYS_CLK 12000000 // 12MHZ #define DDS_CLK TX_SYS_CLK -#define RAMP_300KHZ 6710886 + #define FREQ_MAX_NUM 50 //Max number of frequencies allowed #define FREQ_MIN 0 diff --git a/source/display.c b/source/display.c index 8b71f96..a39b8d9 100644 --- a/source/display.c +++ b/source/display.c @@ -452,80 +452,29 @@ void Display_Wireless(uint8_t wireless) GL_DrawMonoBitmap(txControl, LCD_X_MID-90, LCD_Y_MAX-22, LCD_DRAW_SET); } -void Display_Mode(uint8_t Con_Mode1) -{ - - SYSTEM_DATA_t * sys = system_getSys(); - ACCESSORY_t *active = sys->activeAccessory; - - if (active != NULL) - { - switch (active->connected) - { - case ID_BROADCAST: - { - GL_DrawMonoBitmap(inductionIcon, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); - break; - } - - case ID_TX_SINGLE_DIRECT: - { - GL_DrawMonoBitmap(directConnectIcon5, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); - sprintf(sys->tmpString, "%d", active->portId); - FL_DrawString(sys->tmpString, LCD_X_MAX-40, LCD_Y_MIN, font12Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT); - break; - } - - case ID_TX_DUAL_DIRECT: - { - GL_DrawMonoBitmap(directConnectIcon3, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); - break; - } - - case ID_CLAMP: - { - GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); - break; - } - - case ID_CLAMP2: - { - GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); - FL_DrawString("V2", LCD_X_MAX-40, LCD_Y_MIN+30, font10Bold, LCD_DRAW_SET, FL_ALIGN_CENTER); - break; - } - - } - - } - - - return; - - - -} - -void Display_Level(PWR_MODE_t Level) + +//void Display_Level(PWR_MODE_t Level) +void displayLevel(void) { + PowerLevel_t level = driver_getPowerLevel(); GL_DrawRectangle( 70, LCD_Y_MIN+15, 90, LCD_Y_MIN + 1, 2, LCD_DRAW_SET); GL_DrawRectangle( 94, LCD_Y_MIN+15, 114, LCD_Y_MIN + 1, 2, LCD_DRAW_SET); GL_DrawRectangle(118, LCD_Y_MIN+15, 138, LCD_Y_MIN + 1, 2, LCD_DRAW_SET); GL_DrawRectangle(142, LCD_Y_MIN+15, 162, LCD_Y_MIN + 1, 2, LCD_DRAW_SET); - switch(Level) + switch(level) { - case LEVEL4: + case POWER_LEVEL_4: GL_DrawFilledRectangle(142, LCD_Y_MIN+15, 162, LCD_Y_MIN + 1, LCD_DRAW_SET); - case LEVEL3: + case POWER_LEVEL_3: GL_DrawFilledRectangle(118, LCD_Y_MIN+15, 138, LCD_Y_MIN + 1, LCD_DRAW_SET); - case LEVEL2: + case POWER_LEVEL_2: GL_DrawFilledRectangle( 94, LCD_Y_MIN+15, 114, LCD_Y_MIN + 1, LCD_DRAW_SET); - case LEVEL1: + case POWER_LEVEL_1: GL_DrawFilledRectangle( 70, LCD_Y_MIN+15, 90, LCD_Y_MIN + 1, LCD_DRAW_SET); } @@ -816,3 +765,108 @@ void Display_OnScreen_Diagnostics(void) // FL_DrawString(tempString, 0, 80, font10Bold, LCD_DRAW_SET, FL_ALIGN_LEFT); } + +static void displayFrequency(void) +{ + FREQUENCY_t *freq = driver_getFrequency(); + + if (freq->ldFrequency > 0) + { + Display_CD_Symbol(); // place a CD symbol in front in correct position + } + + uint32_t value = freq->frequency; + + if (value < 1000) + { + sprintf(tempString,"%dHz", value); + } + else + if (value < 10000 && value >= 1000 ) + { + sprintf(tempString,"%.2fkHz", (float32_t)value/1000.0 ); + } + else + if (value < 100000 && value >= 10000) + { + sprintf(tempString,"%.1fkHz",(float32_t)value/1000 ); + } + else + if (value > 100000) + { + sprintf(tempString,"%.0fkHz",(float32_t)value/1000 ); + } + + FL_DrawString(tempString, LCD_X_MAX+6, LCD_Y_MAX - 22, font18Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT); +} + +static void displayMode(void) +{ + + SYSTEM_DATA_t * sys = system_getSys(); + ACCESSORY_t *active = sys->activeAccessory; + + if (active != NULL) + { + switch (active->connected) + { + case ID_BROADCAST: + { + GL_DrawMonoBitmap(inductionIcon, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); + break; + } + + case ID_TX_SINGLE_DIRECT: + { + GL_DrawMonoBitmap(directConnectIcon5, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); + sprintf(sys->tmpString, "%d", active->portId); + FL_DrawString(sys->tmpString, LCD_X_MAX-40, LCD_Y_MIN, font12Bold, LCD_DRAW_SET, FL_ALIGN_RIGHT); + break; + } + + case ID_TX_DUAL_DIRECT: + { + GL_DrawMonoBitmap(directConnectIcon3, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); + break; + } + + case ID_CLAMP: + { + GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); + break; + } + + case ID_CLAMP2: + { + GL_DrawMonoBitmap(clampIcon2, LCD_X_MAX-60,LCD_Y_MIN + 2, LCD_DRAW_SET); + FL_DrawString("V2", LCD_X_MAX-40, LCD_Y_MIN+30, font10Bold, LCD_DRAW_SET, FL_ALIGN_CENTER); + break; + } + + } + + } + + + return; + +} + +void Display_Update(void) +{ + + LCD_Clear(); //clear the frameBuffer + + Display_USB_Status(); + + // display current mode information + displayMode(); + + displayLevel(); + + displayFrequency(); + + LCD_Update(); + +} + diff --git a/source/driver.c b/source/driver.c index ad11744..250faff 100644 --- a/source/driver.c +++ b/source/driver.c @@ -8,6 +8,11 @@ static SYSTEM_DATA_t *_sys = NULL; static TxDriver_t _driver; +static bool powerChangeAllowed(void) +{ + return ((_sys->systemTime - _driver.lastPowerChangeTime) > POWER_CHANGE_TIME); +} + TxDriver_t * driver_getDriver(void) { return &_driver; @@ -80,6 +85,16 @@ void driver_init(void) driver_setPSUVoltage(_driver.psuValueMax); driver_enablePower(true); + + + fgen_init(); + + // HACK: pick the first frequency for now + _driver.powerLevel = POWER_LEVEL_0; + _driver.frequency = fgen_getByIndex(0); + + _driver.lastPowerChangeTime = _sys->systemTime; + } void driver_broadcastOn(bool on) @@ -121,7 +136,6 @@ void driver_setDuty(uint32_t duty) void driver_setFrequency(FREQUENCY_t *freq) { - if (_sys->activeAccessory != NULL) { @@ -129,17 +143,17 @@ void driver_setFrequency(FREQUENCY_t *freq) if (freq != NULL) { - // TODO: accessory may select a different frequency + // accessory may select a different frequency _driver.frequency = freq; driver_setPower(_driver.powerLevel); } } - - } + + void driver_setPower(PowerLevel_t powerLevel) { if (_sys->activeAccessory != NULL) @@ -155,6 +169,37 @@ void driver_setPower(PowerLevel_t powerLevel) } } + _driver.lastPowerChangeTime = _sys->systemTime; + +} + +void driver_powerUp(void) +{ + // limit power change rate + if (!powerChangeAllowed()) return; + + PowerLevel_t level = _driver.powerLevel; + + if (level < POWER_LEVEL_4) + { + level++; + } + + driver_setPower(level); +} + +void driver_powerDown(void) +{ + if (!powerChangeAllowed()) return; + + PowerLevel_t level = _driver.powerLevel; + + if (level > POWER_LEVEL_0) + { + level--; + } + + driver_setPower(level); } void driver_setSafe(bool safe) @@ -174,11 +219,16 @@ void driver_setSafe(bool safe) } } -FREQUENCY_t *driver_getFrequency(void) +FREQUENCY_t* driver_getFrequency(void) { return _driver.frequency; } +PowerLevel_t driver_getPowerLevel(void) +{ + return _driver.powerLevel; +} + // safety monitor run from interrupt void driver_monitor(void) { @@ -191,6 +241,7 @@ void driver_service(void) { case DRIVER_STATE_INIT: { + break; } diff --git a/source/driver.h b/source/driver.h index 233d0b9..761b121 100644 --- a/source/driver.h +++ b/source/driver.h @@ -21,6 +21,8 @@ #define MAX_D_PSU V_36V #define MAX_CLAMP_PSU 255 +#define POWER_CHANGE_TIME 500 //m sec + typedef enum { POWER_LEVEL_0 = 0, @@ -50,6 +52,8 @@ typedef struct FREQUENCY_t *frequency; PowerLevel_t powerLevel; + uint32_t lastPowerChangeTime; + } TxDriver_t; TxDriver_t * driver_getDriver(void); @@ -66,5 +70,9 @@ void driver_setFrequency(FREQUENCY_t *freq); void driver_setPower(PowerLevel_t powerLevel); FREQUENCY_t *driver_getFrequency(void); void driver_setSafe(bool safe); +PowerLevel_t driver_getPowerLevel(); + +void driver_powerUp(void); +void driver_powerDown(void); #endif diff --git a/source/fgen.c b/source/fgen.c index 0a74c49..4f0428a 100644 --- a/source/fgen.c +++ b/source/fgen.c @@ -6,6 +6,7 @@ #include "eeprom.h" #include "arm_math.h" #include "soft_timer.h" +#include "utils.h" static fgen_t _fgen; @@ -341,6 +342,8 @@ static void loadDefaults(void) fgen_addFrequency(32770, 1, 1, FT_ACTIVE); fgen_addFrequency(65055, 1, 1, FT_ACTIVE); fgen_addFrequency(88779, 1, 1, FT_ACTIVE); + + EE_SaveData(); } @@ -371,6 +374,12 @@ static bool loadFrequencies(void) return success; } +void fgen_setFrequency(FREQUENCY_t *freq) +{ + +} + + void fgen_init(void) { uint32_t tmp; @@ -389,7 +398,7 @@ void fgen_init(void) resetPin.pin = PIN (PIN_RAMP_RST); dds_init(&_fgen.dds[DDS_RAMP], RAMP, resetPin); - stimer_delay(10); + delayms(10); // clear reset after delay for (int i=0; iitems[menu->selected].handler != NULL) + if (menu->items != NULL) { - menu->items[menu->selected].handler(NULL); + if (menu->items[menu->selected].handler != NULL) + { + menu->items[menu->selected].handler(NULL); + } } } } @@ -585,75 +588,6 @@ static void DrawMenuScrollBar(uint32_t displayIndex, uint32_t numItems) * Public Functions ******************************************************************************/ -void MENU_Init(void) -{ - //Init testMenu - TM_Init(); - - //Clear menu items - ClearMenuItems(mainMenu, MAIN_MENU_NUM_TX10); - ClearMenuItems(langMenu, LANG_MENU_NUM); - - _menuItemsIndex = 0; - - for (int i=0; i < MENU_STACK_SIZE; ++i) - { - _menuData.menuStack[i].selected = 0; - _menuData.menuStack[i].handler = NULL; - } - - //main menu - uint32_t i = 0; - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "System Information"); //System info screen - - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "Frequencies"); //Frequency Selection Menu - - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "Auto Shutdown"); //Auto Shutdown selection - - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "Language"); //Language Selection Menu -#if 0 - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "Link Radio"); //Link Radio Menu - - //no regulatory info on the Tx10 - mainMenu[i].pMonoIcon = 0; - strcpy(mainMenu[i++].text, "Regulatory Info"); //Reset - Needs a new name -#endif - - //check for array over run - if(i > MAIN_MENU_NUM_TX10) - { - while(1); - } - - //language menu - i = 0; - langMenu[i].pMonoIcon = 0; - strcpy(langMenu[i].text, languageNames[i++]); - - langMenu[i].pMonoIcon = 0; - strcpy(langMenu[i].text, languageNames[i++]); - - langMenu[i].pMonoIcon = 0; - strcpy(langMenu[i].text, languageNames[i++]); - - langMenu[i].pMonoIcon = 0; - strcpy(langMenu[i].text, languageNames[i++]); - - //check for array over run - if(i > LANG_MENU_NUM) - { - while(1); - } - - -} - - void Menu_init(void) { diff --git a/source/ports.c b/source/ports.c index b0e02bb..5e9a128 100644 --- a/source/ports.c +++ b/source/ports.c @@ -176,6 +176,11 @@ void ACCY_service(void) } } } + else + { + // if nothing active, set broadcast + ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A); + } } @@ -188,6 +193,13 @@ void ACCY_setActiveChannel(AccyChannelId_t channel) void ACCY_next(void) { + + if (sys.activeAccessory == NULL) + { + ACCY_setActive(&sys.ports[ACCY_PORT_INDUCTION], CHANNEL_A); + return; + } + // cycle through accessories and channels to find the next available AccessoryPortId_t currentPort = sys.activeAccessory->portId; AccyChannelId_t currentChannel = sys.activeAccessory->activeChannel; @@ -367,6 +379,9 @@ void ACCY_Init(void) sys.ports[ACCY_PORT_1].idVoltage = &sys.adc.V_ID1; sys.ports[ACCY_PORT_2].idVoltage = &sys.adc.V_ID2; + sys.activeAccessory = NULL; + sys.nextAccessory = NULL; + } void ACCY_Update(void)