/** @file functions.c * @brief Diverse Funktionen * * */ #include "functions.h" uint8_t Dummy; uint8_t ee_Dummy EEMEM = 0x55; ///< Dummy for Address 0 uint8_t ee_Trx1 EEMEM = 0; ///< TRX 1 uint8_t ee_Trx2 EEMEM = 0; ///< TRX 2 uint8_t ee_KeyerMode EEMEM = 1; ///< Iambic A, Iambic B oder Ultimatic uint8_t ee_SidetoneEnabled EEMEM = 1; ///< Mithörton eingeschaltet uint8_t ee_WpMBpM EEMEM = 0; ///< WpM oder BpM Anzeige uint8_t ee_Reverse EEMEM = 0; ///< linkes/rechtes Paddle vertauschen uint8_t ee_MemButtonMode EEMEM = 0; ///< Funktion des ersten Tasters (MEM5) uint8_t ee_Ratio EEMEM = 30; ///< Punkt/Strich Verhältnis 1:3 uint8_t ee_Weight EEMEM = 50; ///< Punkt/Strich Gewichtung uint8_t ee_Memory EEMEM = 0; ///< Punkt/Strich Speicher uint16_t ee_SidetoneFreq EEMEM = 600; ///< Frequenz des Mithörtons uint8_t ee_WpM EEMEM = 12; ///< Geschwindigkeit WpM uint8_t ee_RiseTime EEMEM = 5; ///< Anstiegszeit Sinuston uint8_t ee_RiseTimeCounter EEMEM = 5; ///< Anzahl Sinusschwingungen für den Anstieg uint8_t ee_DebounceTime EEMEM = 6; ///< Entprellzeit für Straight Key Eingang /** @fn void DelayMilliSeconds(uint16_t ms) * @brief Zeitschleife von 1-65535 Millisekunden * @param ms Anzahl Millisekunden * @retval none */ void DelayMilliSeconds(uint16_t ms) { volatile static uint16_t ctr; ResetMilliSeconds(); do { ATOMIC_BLOCK(ATOMIC_FORCEON) { ctr = t_delayms; } CheckPaddles(); } while (ctr < ms); } /** @fn uint16_t GetMilliSeconds(void) * @brief Zählerwert für Zeitschleifen auslesen * @param none * @retval Millisekunden */ uint16_t GetMilliSeconds(void) { volatile static uint16_t ctr; ATOMIC_BLOCK(ATOMIC_FORCEON) { ctr = t_delayms; } return ctr; } /** @fn void ResetMilliSeconds(void) * @brief Setzt den Millisekundenzähler für Zeitschleifen auf 0 * @param none * @retval none */ void ResetMilliSeconds(void) { ATOMIC_BLOCK(ATOMIC_FORCEON) { t_delayms = 0; } } /** @fn void IntEnable(void) * @brief Register wieder herstellen und Interrupts erlauben * @param none * @retval none */ void IntEnable(void) { SREG = sreg_tmp; sei(); } /** @fn void IntDisable(void) * @brief Register sichern und Interrupts verbieten * @param none * @retval none */ void IntDisable(void) { sreg_tmp = SREG; cli(); } /** @fn void WriteEEprom(void) * @brief Akt. Einstellungen in EEPROM schreiben * @param none * @retval none */ void WriteEEprom(void) { IntDisable(); eeprom_write_byte(&ee_Dummy,0x55); eeprom_write_byte(&ee_WpM, bConfig.WpM); eeprom_write_byte(&ee_KeyerMode, bConfig.KeyerMode); eeprom_write_word(&ee_SidetoneFreq, bConfig.SidetoneFreq); eeprom_write_byte(&ee_Trx1, bConfig.Trx1); eeprom_write_byte(&ee_Trx2, bConfig.Trx2); eeprom_write_byte(&ee_SidetoneEnabled, bConfig.SidetoneEnabled); eeprom_write_byte(&ee_WpMBpM, bConfig.WpMBpM); eeprom_write_byte(&ee_Reverse, bConfig.Reverse); eeprom_write_byte(&ee_MemButtonMode, bConfig.MemButtonMode); eeprom_write_byte(&ee_Weight, bConfig.Weight); eeprom_write_byte(&ee_Ratio, bConfig.Ratio); eeprom_write_byte(&ee_Memory, bConfig.Memory); eeprom_write_byte(&ee_RiseTime, bConfig.RiseTime); eeprom_write_byte(&ee_RiseTimeCounter, bConfig.RiseTimeCounter); eeprom_write_byte(&ee_DebounceTime, bConfig.DebounceTime); IntEnable(); } /** @fn void ReadEEpromWpM(void) * @brief Gespeicherte Einstellung für die Geschwindigkeit aus EEprom lesen * @param none * @retval none */ void ReadEEpromWpM(void) { IntDisable(); bConfig.WpM = eeprom_read_byte(&ee_WpM); IntEnable(); } /** @fn void WriteEEpromWpM(void) * @brief Akt. Einstellung für die Geschwindigkeit in EEprom schreiben * @param none * @retval none */ void WriteEEpromWpM(void) { IntDisable(); eeprom_write_byte(&ee_WpM, bConfig.WpM); IntEnable(); } /** @fn void SetEEprom(void) * @brief Standardeinstellungen (bei neuem Controller) * * Wird ein neuer Controller verwendet, gibt es keine * Einstellungswerte im EEprom. Diese Funktion schreibt * die initialen Werte in das EEprom. Wird sehr selten * benötigt ;-) * * @param none * @retval none */ void SetEEprom(void) { Dummy = 0x55; bConfig.WpM = 15; bConfig.KeyerMode = 2; bConfig.SidetoneFreq = 600; bConfig.Trx1 = 1; bConfig.Trx2 = 0; bConfig.SidetoneEnabled = 1; bConfig.WpMBpM = 1; bConfig.Reverse = 0; bConfig.MemButtonMode = 1; bConfig.Weight = 50; bConfig.Ratio = 30; bConfig.Memory = 0; bConfig.RiseTime = 6; bConfig.RiseTimeCounter = 8; bConfig.DebounceTime = 5; WriteEEprom(); SetStandardMsg(); for(uint8_t i = 1; i < 6; i++) WriteMsgEEprom(i); } /** @fn void ReadEEprom(void) * @brief Einstellungen aus dem EEprom lesen * @param none * @retval none */ void ReadEEprom(void) { IntDisable(); Dummy = eeprom_read_byte(&ee_Dummy); IntEnable(); if(Dummy != 0x55) { SetEEprom(); } IntDisable(); bConfig.WpM = eeprom_read_byte(&ee_WpM); bConfig.KeyerMode = eeprom_read_byte(&ee_KeyerMode); bConfig.SidetoneFreq = eeprom_read_word(&ee_SidetoneFreq); bConfig.Trx1 = eeprom_read_byte(&ee_Trx1); bConfig.Trx2 = eeprom_read_byte(&ee_Trx2); bConfig.SidetoneEnabled = eeprom_read_byte(&ee_SidetoneEnabled); bConfig.WpMBpM = eeprom_read_byte(&ee_WpMBpM); bConfig.Reverse = eeprom_read_byte(&ee_Reverse); bConfig.MemButtonMode = eeprom_read_byte(&ee_MemButtonMode); bConfig.Ratio = eeprom_read_byte(&ee_Ratio); bConfig.Weight = eeprom_read_byte(&ee_Weight); bConfig.Memory = eeprom_read_byte(&ee_Memory); bConfig.RiseTime = eeprom_read_byte(&ee_RiseTime); bConfig.RiseTimeCounter = eeprom_read_byte(&ee_RiseTimeCounter); bConfig.DebounceTime = eeprom_read_byte(&ee_DebounceTime); IntEnable(); } /** @fn void SerialWriteChar(unsigned char data) * @brief Ein Zeichen über serielle Schnittstelle ausgeben * @param data Zeichen, das seriell ausgegeben wird * @retval none */ void SerialWriteChar(unsigned char data) { while(!(UCSR0A & (1< 0) { if(StateButtonPressed == NO_KEY_PRESSED) { StateButtonPressed = KEY_PRESSED_DEBOUNCE; TimerButtonPressed = 0; } if(StateButtonPressed == KEY_PRESSED) { if((bConfig.MemButtonMode) && (ButtonPressed == 5)) { if(TrxButtonPressed == 0) { bConfig.Trx1 = 1; bConfig.Trx2 = 0; } if(TrxButtonPressed == 1) { bConfig.Trx1 = 0; bConfig.Trx2 = 1; } if(TrxButtonPressed == 2) { bConfig.Trx1 = 1; bConfig.Trx2 = 1; } if(TrxButtonPressed == 3) { bConfig.Trx1 = 0; bConfig.Trx2 = 0; } StateButtonPressed = NO_KEY_PRESSED; bMenuCtrl.Update = 1; TrxButtonPressed++; if(TrxButtonPressed > 3) TrxButtonPressed = 0; } else { if(bState.Automatic == 0) { bState.Automatic = 1; StateButtonPressed = NO_KEY_PRESSED; SendMemory(ButtonPressed); } else { StateButtonPressed = NO_KEY_PRESSED; bState.Automatic = 0; } } } } } /** @fn void CheckStraightKey(void) * @brief Fragt die Handtasteneingänge ab und gibt das * entsprechende Symbol aus. Bei der Handtaste * findet über einen Timer eine Entprellung statt * * @param none * @retval none */ void CheckStraightKey(void) { if(PIND & (1<