Signal Generator
Dependencies: IniManager RA8875 Watchdog mbed-rtos mbed
Fork of speaker_demo_Analog by
Diff: SignalGenDisplay.h
- Revision:
- 2:8f71b71fce1b
- Parent:
- 1:dd07e1deec6c
- Child:
- 3:d22f3e52d06a
--- a/SignalGenDisplay.h Fri Jan 13 12:33:37 2017 +0000 +++ b/SignalGenDisplay.h Sun Jan 15 03:11:22 2017 +0000 @@ -4,16 +4,21 @@ #include "mbed.h" #include "RA8875.h" -#include "SignalGenerator.h" +#include "SignalGenDAC.h" #define SG_MIN_V 0.0 // Constraint, to match to the hardware #define SG_MAX_V 3.3 // #define SG_AOUT_FS 3.3 // Analog output full scale +#define SAVE_AFTER_IDLE_S 10 // How long after idle should it save + class SignalGenDisplay { public: /// Constructor for the Signal Generator User Interface. /// + /// This will also load the initial settings from the + /// file system. + /// /// @param[in] lcd is a pointer to the Graphics Display /// @param[in] signal is a handle to the signal generator /// @param[in] ProgrName is a pointer to a constant string @@ -21,7 +26,7 @@ /// @param[in] Ver is a pointer to a constant string /// @param[in] Build is a pointer to a constant string /// - SignalGenDisplay(RA8875 * lcd, SignalGenerator * signal, + SignalGenDisplay(RA8875 * lcd, SignalGenDAC * signal, const char * ProgName, const char * Manuf, const char * Ver, const char * Build); @@ -29,12 +34,10 @@ //// ~SignalGenDisplay(); - /// Initialization to present the initial display + /// Refresh the display for the current settings + /// and display mode. /// - /// As part of the display initialization, it also shows - /// program information. - /// - void Init(void); + void Refresh(void); /// Set the frequency information /// @@ -111,29 +114,15 @@ /// float GetVoltageOffset(void) { return offset; } - /// Signal Generator Modes - /// - /// This defines the modes. However, SG_KEYPAD is not an mode, - /// it is a proprietary mechanism used for displaying the keypad, and - /// is not intended to be used by the application. - /// - typedef enum { - SG_SINE, ///< Sine wave - SG_SQUARE, ///< Square wave - SG_TRIANGLE, ///< Triangle wave - SG_SAWTOOTH, ///< Sawtooth - SG_USER, ///< User defined waveform - SG_KEYPAD, ///< This is an internal value, not for applications - } SG_Mode; - /// Select a Waveform Mode /// /// The selection will update the display to reflect the current state /// /// @param[in] mode sets the signal generator mode. + /// @param[in] force as true will force it to set the mode, redrawing the screen /// @returns true if the value was accepted /// - bool SelectWaveformMode(SG_Mode mode); + bool SetWaveformMode(SG_Mode mode, bool force = false); /// Operating mode changes /// @@ -141,14 +130,14 @@ /// zero or more bits are set. /// typedef enum { - SG_NONE = 0, ///< No change in operating mode - SG_MODE = 1, ///< Signal mode changed; Sine, Square, Triangle, Sawtooth, User - SG_FREQ = 2, ///< Change in the frequency - SG_PERI = 4, ///< Change in the period (effectively same as frequency) - SG_DUTY = 8, ///< Change in the duty cycle - SG_VOLT = 16, ///< Change in the peak to peak amplitude - SG_OFFS = 32, ///< Change in the offset voltage - } SG_Changes; + OM_NONE = 0, ///< No change in operating mode + OM_MODE = 1, ///< Signal mode changed; Sine, Square, Triangle, Sawtooth, User + OM_FREQ = 2, ///< Change in the frequency + OM_PERI = 4, ///< Change in the period (effectively same as frequency) + OM_DUTY = 8, ///< Change in the duty cycle + OM_VOLT = 16, ///< Change in the peak to peak amplitude + OM_OFFS = 32, ///< Change in the offset voltage + } OM_Changes; /// Poll the Signal Generator UI for changes in operation. /// @@ -167,7 +156,7 @@ /// - <nul> do nothing, just poll /// @returns a bitmask of which non-zero indicates changes in mode. /// - SG_Changes Poll(char c = 0); + OM_Changes Poll(char c = 0); /// Show the menu of commands on the console interface /// @@ -175,11 +164,12 @@ private: RA8875 * lcd; - SignalGenerator * signal; + SignalGenDAC * signal; const char * ProgName; const char * Manuf; const char * Ver; const char * Build; + bool needsInit; ///< allows defering first init to after the constructor typedef enum { VS_MainScreen, VS_Settings, @@ -190,12 +180,13 @@ float dutycycle; ///< selected duty cycle float voltage; ///< selected voltage float offset; ///< selected offset - SG_Changes EntryMd; ///< indicates if in data entry mode char textBuffer[10]; ///< a place to enter text int textLen; ///< num chars in textBuffer - Timer timer; - - void DrawNavGadget(void); + Timer timer; ///< Keypad repeat timer + OM_Changes EntryMd; ///< indicates if in data entry mode + uint16_t Changes; ///< combined from EntryMd for what to save + Timer timerSave; ///< Save state timer + void ShowProductInfo(void); void ShowBrightnessSetting(void); char GetTouchEvent(void); @@ -207,10 +198,23 @@ void updateVoltage(void); void updateOffset(void); void updateTextWindow(void); - void resetDataEntry(void); + void clearTextWindow(void); + /// Set a flag to request modified settings to be saved. + /// + /// This is also called with OM_NONE as a background task to see if + /// any settings have been changed. In this way, settings changes are not + /// written immediately, which is both slow, and unnecessary if another + /// change is about to be made. + /// + /// @param[in] reportMode indicates what setting, if any, has changed. + /// + void SaveSettings(OM_Changes reportMode = OM_NONE); + void resetDataEntry(OM_Changes mode = OM_NONE, bool save = false); ///< save the current value if exiting entry mode + void DrawNavGadget(void); + void DrawModeButtons(void); void DrawKeypadEnabled(bool enable = false); void DrawButton(rect_t r, bool pressed, SG_Mode mode, bool enable = false, int label=0); - void DrawWaveform(rect_t r, SG_Mode mode, color_t color, float dutycycleOverride = 0.0); + void DrawWaveform(rect_t r, SG_Mode mode, color_t color, bool drawPure = false); // pure ignores, voltage,offset,dutycycle float rangelimit(float value, float minV, float maxV); };