summaryrefslogtreecommitdiff
path: root/support/dktools/DkClockData.cpp
blob: 53d10c12d3166318518dee52e8e689c81583984b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
Copyright (C) 2017-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: DkClockData.cpt
*/

/**	@file DkClockData.cpp The DkClockData module.
*/


#line 88 "DkClockData.cpt"

#include "dk3conf.h"
#include "wxdkclock.h"




#line 94 "DkClockData.cpt"


DkClockData::DkClockData()
{
  

#line 99 "DkClockData.cpt"
  clvd.h = 0;
  clvd.m = 0;
  clvd.s = 0;
  clvd.a = 0;
  iAlertHour = 0;
  iAlertMinute = 0;
  iAlertEnabled = 0;
  iAlertState = 0;
  tmCurrent.Y = 0;
  tmCurrent.M = 0;
  tmCurrent.D = 0;
  tmCurrent.h = 0;
  tmCurrent.m = 0;
  tmCurrent.s = 0;
  

#line 114 "DkClockData.cpt"
}



void
DkClockData::getData(clockview_data_t *dptr)
{
  

#line 122 "DkClockData.cpt"
  if(dptr) {
    wxMutexLocker	lock(mxProtectData);
    dk3mem_cpy((void *)dptr, (void *)(&clvd), sizeof(clockview_data_t));
  }
  

#line 127 "DkClockData.cpt"
}



int
DkClockData::setTime(dk3_time_t *ct)
{
  dk3_tm_t	lct;
  int		back		= 0;
  

#line 137 "DkClockData.cpt"
  if(dk3sf_localtime_app(&lct, ct, NULL)) {
    wxMutexLocker		lock(mxProtectData);
    /*
    	Check date change.
    */
    if(2 == iAlertState) {
      if(lct.Y != tmCurrent.Y) {
        iAlertState = 0;
      } else {
        if(lct.M != tmCurrent.M) {
	  iAlertState = 0;
	} else {
	  if(lct.D != tmCurrent.D) {
	    iAlertState = 0;
	  }
	}
      }
    }
    /*
    	Check alert state change.
    */
    if((0 != iAlertEnabled) && (0 == iAlertState)) {
      if(lct.h > iAlertHour) {
        iAlertState = 1; back = 1;
      } else {
        if(lct.h == iAlertHour) {
	  if(lct.m >= iAlertMinute) {
	    iAlertState = 1; back = 1;
	  }
	}
      }
    }
    /*
    	Copy current time.
    */
    dk3mem_cpy((void *)(&tmCurrent), (void *)(&lct), sizeof(dk3_tm_t));
    /*
    	Copy to output structure.
    */
    clvd.h = lct.h;
    clvd.m = lct.m;
    clvd.s = lct.s;
    clvd.a = ((1 == iAlertState) ? 1 : 0);
  } 

#line 181 "DkClockData.cpt"
  return back;
}



void
DkClockData::setAlert(bool flag, int hour, int min)
{
  

#line 190 "DkClockData.cpt"
  iAlertState = 0;
  {
    wxMutexLocker         lock(mxProtectData);
    if(flag) {				

#line 194 "DkClockData.cpt"
      if((0 <= hour) && (23 >= hour) && (0 <= min) && (59 >= min)) {
        iAlertEnabled = 1;		

#line 196 "DkClockData.cpt"
        iAlertHour = hour;
        iAlertMinute = min;
        if(tmCurrent.h > hour) {
          iAlertState = 2;
        } else {
          if(tmCurrent.h == hour) {
	    if(tmCurrent.m >= min) {
	      iAlertState = 2;
	    }
	  }
        }
      } else {				

#line 208 "DkClockData.cpt"
        iAlertEnabled = 0;
        iAlertHour = 0;
        iAlertMinute = 0;
      }
    } else {				

#line 213 "DkClockData.cpt"
      iAlertEnabled = 0;
      iAlertHour = 0;
      iAlertMinute = 0;
    }
  } 

#line 218 "DkClockData.cpt"
}



void
DkClockData::endAlert(void)
{
  

#line 226 "DkClockData.cpt"
  {
    wxMutexLocker		lock(mxProtectData);
    if(1 == iAlertState) {
      iAlertState = 2;
    }
  }

#line 232 "DkClockData.cpt"
}



void
DkClockData::getAlertData(int *en, int *h, int *m)
{
  

#line 240 "DkClockData.cpt"
  if((en) && (h) && (m)) {
    wxMutexLocker		lock(mxProtectData);
    *en = iAlertEnabled;	

#line 243 "DkClockData.cpt"
    *h  = iAlertHour;		

#line 244 "DkClockData.cpt"
    *m  = iAlertMinute;		

#line 245 "DkClockData.cpt"
  } 

#line 246 "DkClockData.cpt"
}