Signal Generator
Dependencies: IniManager RA8875 Watchdog mbed-rtos mbed
Fork of speaker_demo_Analog by
Diff: SignalGenDisplay.h
- Revision:
- 1:dd07e1deec6c
- Child:
- 2:8f71b71fce1b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SignalGenDisplay.h Fri Jan 13 12:33:37 2017 +0000 @@ -0,0 +1,218 @@ + +#ifndef SIGNALGENDISPLAY_H +#define SIGNALGENDISPLAY_H + +#include "mbed.h" +#include "RA8875.h" +#include "SignalGenerator.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 + +class SignalGenDisplay { +public: + /// Constructor for the Signal Generator User Interface. + /// + /// @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 + /// @param[in] Manuf is a pointer to a constant string + /// @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, + const char * ProgName, const char * Manuf, const char * Ver, + const char * Build); + + /// Destructor + //// + ~SignalGenDisplay(); + + /// Initialization to present the initial display + /// + /// As part of the display initialization, it also shows + /// program information. + /// + void Init(void); + + /// Set the frequency information + /// + /// This automatically sets the period as 1/frequency + /// + /// @param[in] frequency desired + /// @returns true if the value was accepted + /// + bool SetFrequency(float frequency); + + /// Get the current frequency setting + /// + /// @returns current frequency + /// + float GetFrequency(void) { return frequency; } + + /// Set the period instead of the frequency + /// + /// This automatically sets the frequency as 1/period + /// + /// @param[in] period desired + /// @returns true if the value was accepted + /// + bool SetPeriod(float period); + + /// Get the current period + /// + /// @returns current period + /// + float GetPeriod(void) { return 1/frequency; } + + /// Set the Duty Cycle + /// + /// This adjusts the duty cycle of the waveform + /// + /// @param[in] dutyCycle is a value ranging from 0 to 100. + /// @returns true if the value was accepted + /// + bool SetDutyCycle(float dutyCycle); + + /// Get the current duty cycle + /// + /// @returns the duty cycle + /// + float GetDutyCycle(void) { return dutycycle; } + + /// Set the peak-to-peak voltage of the of the waveform + /// + /// In the range of 0 to 3.3v + /// + /// @param[in] voltage is the peak to peak voltage + /// @returns true if the value was accepted + /// + bool SetVoltagePeakToPeak(float voltage); + + /// Get the Peak to Peak voltage + /// + /// @returns peak to peak voltage + /// + float GetVoltagePeakToPeak(void) { return voltage; } + + /// Set the offset in the range of +/- 1.65v + /// + /// A zero volt offset is biased to VCC/2 (3.3/2) + /// + /// @param[in] voltage is the offset voltage. + /// @returns true if the value was accepted + /// + bool SetVoltageOffset(float voltage); + + /// Get the offset voltage + /// + /// @returns offset voltage + /// + 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. + /// @returns true if the value was accepted + /// + bool SelectWaveformMode(SG_Mode mode); + + /// Operating mode changes + /// + /// Changes in the operating mode are reported by a bitmask value, where + /// 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; + + /// Poll the Signal Generator UI for changes in operation. + /// + /// Call this periodically, in order to determine if there is a user-activated + /// change in the operating mode of the signal generator. + /// + /// @param[in] c is the optional character, emulating the onscreen keypad + /// - 'd' duty cycle entry + /// - 'f' frequency entry + /// - 'p' period entry + /// - 'v' voltage entry + /// - 'o' offset voltage entry + /// - '0'-'9','.' numeric entry + /// - <enter> complete numeric entry + /// - <esc> abandon numeric entry + /// - <nul> do nothing, just poll + /// @returns a bitmask of which non-zero indicates changes in mode. + /// + SG_Changes Poll(char c = 0); + + /// Show the menu of commands on the console interface + /// + void ShowMenu(void); + +private: + RA8875 * lcd; + SignalGenerator * signal; + const char * ProgName; + const char * Manuf; + const char * Ver; + const char * Build; + typedef enum { + VS_MainScreen, + VS_Settings, + } VisualScreen; + VisualScreen vis; + SG_Mode mode; ///< signal mode + float frequency; ///< selected frequency + 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); + void ShowProductInfo(void); + void ShowBrightnessSetting(void); + char GetTouchEvent(void); + void ClearScope(void); + void UpdateScope(void); + void updateDutyCycle(void); + void updateFrequency(void); + void updatePeriod(void); + void updateVoltage(void); + void updateOffset(void); + void updateTextWindow(void); + void resetDataEntry(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); + float rangelimit(float value, float minV, float maxV); +}; + + +#endif // SIGNALGENDISPLAY_H \ No newline at end of file