John Mitchell / lpc4088_displaymodule_GC500_2_5inch

Dependencies:   DMBasicGUI DMSupport

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ServiceInterval.h Source File

ServiceInterval.h

00001 #ifndef SERVICEINTERVAL_H
00002 #define SERVICEINTERVAL_H
00003 
00004 #include "mbed.h"
00005 #include "DMBoard.h"
00006 
00007 #include "USBHostGC.h"
00008 
00009 /*
00010     These classes do what the name implies - handle service intervals. These are measured
00011     either in instrument cycles (i.e. runs), or time - in the latter case, the interval
00012     is always twelve months.
00013     
00014     Each ServiceInterval object deals with one (and only one) service interval, allowing the caller
00015     to specify its description (a text string).
00016     
00017     Note that the caller must 'poll' the ServiceInterval object to find out whether or not 
00018     it has expired - it does not raise an interrupt, or call a callback function,
00019     or do anything unsolicited.
00020 */
00021 
00022 //#define SERVICE_INTERVALS_ACTIVE // #define this to activate the ServiceInterval code in the whole application
00023 
00024 class ServiceInterval {
00025 public:
00026     ServiceInterval(char *intervalDescription, int touchAreaIndex);
00027     ~ServiceInterval();
00028 
00029     int GetDescriptionLength(void);
00030     void GetDescription(char *buffer);
00031     
00032     virtual void Start(void) = 0;
00033     
00034     virtual void InstrumentHasCycled(void) = 0;
00035     
00036     virtual bool HasExpired(void) = 0;
00037     
00038     bool IntervalHasStarted(void) { return intervalHasStarted; }
00039     
00040     virtual void SaveToQSPISettings(void) = 0;
00041     virtual void ReadFromQSPISettings(void) = 0;
00042     
00043     static void SetupAllServiceIntervals(void);
00044     static void StartAllServiceIntervals(void);
00045     static int GetServiceIntervalCount(void) { return SERVICE_INTERVAL_COUNT; }
00046     static ServiceInterval* GetServiceInterval(int serviceIntervalIndex);
00047     static void TellAllServiceIntervalsInstrumentHasCycled(void);
00048     static bool AtLeastOneServiceIntervalHasExpired(void);
00049     static ServiceInterval* GetNextExpiredServiceInterval(ServiceInterval* thisExpiredInterval);
00050     static void SaveAllServiceIntervalsToQSPISettings(void);
00051     static void ReadAllServiceIntervalsFromQSPISettings(void);
00052     static bool IsServicedTouchArea(int touchAreaIndex);
00053     static bool DealWithServicedTouchArea(int touchAreaIndex);
00054     
00055 
00056 private:
00057     char *description;
00058     
00059     enum { SERVICE_INTERVAL_COUNT = 6 };
00060     static ServiceInterval* serviceIntervalArray[SERVICE_INTERVAL_COUNT];
00061     
00062     int servicedTouchArea; // The easyGUI touch area that specifies "this component has now been serviced"
00063                                     
00064 
00065 protected:
00066     bool intervalHasStarted;
00067 };
00068 
00069 class CyclesServiceInterval : public ServiceInterval {
00070 public:
00071     CyclesServiceInterval(char *intervalDescription, int touchAreaIndex);
00072 
00073     void SetDurationInNumberOfInstrumentCycles(int newDurationInNumberOfInstrumentCycles);
00074 
00075     virtual void InstrumentHasCycled(void);
00076     
00077     virtual void Start(void);
00078     
00079     virtual bool HasExpired(void) { return intervalHasExpired; }
00080     
00081     virtual void SaveToQSPISettings(void);
00082     virtual void ReadFromQSPISettings(void);
00083 
00084 private:
00085     int durationInNumberOfInstrumentCycles;
00086     int countOfRemainingCycles;
00087 
00088     bool intervalHasExpired;
00089 };
00090 
00091 class TwelveMonthServiceInterval : public ServiceInterval {
00092 public:
00093     TwelveMonthServiceInterval(char *intervalDescription, int touchAreaIndex);
00094 
00095     virtual void Start(void);
00096     
00097     virtual void InstrumentHasCycled(void);
00098     
00099     virtual bool HasExpired(void);
00100     
00101     virtual void SaveToQSPISettings(void);
00102     virtual void ReadFromQSPISettings(void);
00103 
00104 private:
00105     struct tm startTime;
00106     
00107     static void GetCurrentLocalTime(struct tm *currentLocalTime);
00108 };
00109 
00110 #endif  // SERVICEINTERVAL_H
00111