-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatorRTC.ts
398 lines (368 loc) · 9.47 KB
/
gatorRTC.ts
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/**
* Andy England @ SparkFun Electronics
* September 6, 2018
* Development environment specifics:
* Written in Microsoft Makecode
* Tested with a SparkFun gatorlog sensor and micro:bit
*
* This code is released under the [MIT License](http://opensource.org/licenses/MIT).
* Please review the LICENSE.md file included with this example. If you have any questions
* or concerns with licensing, please contact [email protected].
* Distributed as-is; no warranty is given.
*/
/**
* Functions to operate the gatorrtc sensor
*/
enum TimeType{
Seconds=1,
Minutes=2,
Hours=3,
Date=4,
Month=5,
Year=6,
Weekday=7
}
enum dayNames{
Monday=0,
Tuesday=1,
Wednesday=2,
Thursday=3,
Friday=4,
Saturday=5,
Sunday=6
}
enum TimeStampType{
Seconds=1,
Minutes=2,
Hours=3,
Date=4,
Month=5,
Year=6
}
enum Months{
January=1,
February=2,
March=3,
April=4,
May=5,
June=6,
July=7,
August=8,
September=9,
October=10,
November=11,
December=12,
}
enum TimeMode{
Military=0,
Standard=1
}
enum Afternoon{
AM=0,
PM=1
}
/**
* Functions for working with the gator:RTC
*/
//% color=#f44242
//% icon="\uf017"
namespace gatorRTC {
/**
* Set RTC time in HH:MM:SS in 12 hour format format
*/
//% weight=49
//% blockId="gatorRTC_set12Time"
//% block="set time to %hours :%minutes :%seconds -%amPm"
//% hours.min=0 hours.max=12
//% minutes.min=0 minutes.max=60
//% seconds.min=0 seconds.max=60
//% shim=gatorRTC::set12Time
export function set12Time(hours: number, minutes: number, seconds: number, amPm: Afternoon){
return
}
/**
* Set RTC time in HH:MM:SS in 24 hour format
*/
//% weight=48
//% blockId="gatorRTC_set24Time"
//% block="set time to %hours | : %minutes | : %seconds in 24 hour mode"
//% hours.min=0 hours.max=24
//% minutes.min=0 minutes.max=60
//% seconds.min=0 seconds.max=60
//% shim=gatorRTC::set24Time
//% advanced=true
export function set24Time(hours: number, minutes: number, seconds: number){
return
}
/**
* Set RTC Date in MM-DD-YYYY format
*/
//% weight=47
//% blockId="gatorRTC_setDate"
//% block="set date to %weekday|,%month|-%day|-20%year"
//% day.min=1 day.max=31
//% year.min=0 year.max=99
//% shim=gatorRTC::setDate
export function setDate(weekday:dayNames, month: Months, day: number, year: number){
return
}
/**
* Sets one component of the time on the RTC. Select which component you would like to set from the drop down.
*/
//% weight=46
//% blockId="gatorRTC_setTimeComponent"
//% block="set %timeComponent | to %value"
//% shim=gatorRTC::setTimeComponent
export function setTimeComponent(timeComponent: TimeType, value: number){
return
}
/**
* Gets one component of the time on the RTC. Select which component you would like to get from the drop down.
*/
//% weight=45
//% blockId="gatorRTC_timeComponent"
//% block="value of %timeComponent"
//% shim=gatorRTC::timeComponent
export function timeComponent(timeComponent: TimeType): number{
return 0
}
/**
* Gets one component of the time on the RTC. Select which component you would like to get from the drop down.
*/
//% weight=44
//% blockId="gatorRTC_weekdayName"
//% block="text of weekday"
export function weekdayName(): string{
let dayString: string
switch (timeComponent(TimeType.Weekday))
{
case 0:
dayString = "Monday"
break;
case 1:
dayString = "Tuesday"
break;
case 2:
dayString = "Wednesday"
break;
case 3:
dayString = "Thursday"
break;
case 4:
dayString = "Friday"
break;
case 5:
dayString = "Saturday"
break;
case 6:
dayString = "Sunday"
break;
}
return dayString
}
/**
* Get RTC time in HH:MM:SS format
*/
//% weight=43
//% blockId="gatorRTC_time"
//% block="time in HH:MM:SS"
export function time(): string{
let minutes = timeComponent(TimeType.Minutes)
let seconds = timeComponent(TimeType.Seconds)
let minuteDelimiterString: string = ":"
let secondDelimiterString: string = ":"
let ampmString: string = ""
if (minutes < 10)
{
minuteDelimiterString = ":0"
}
if (seconds < 10)
{
secondDelimiterString = ":0"
}
if (is12HourMode())
{
ampmString = " AM"
if (isAfternoon())
{
ampmString = " PM"
}
}
let timeString: string = timeComponent(TimeType.Hours) + minuteDelimiterString + minutes + secondDelimiterString + seconds + ampmString
return timeString
}
/**
* Get RTC Time in yyyy-mm-ddThh:mm:ss format. This is the ISO8601 standard timestamp format.
*/
//% weight=42
//% blockId="gatorRTC_get8601Time"
//% block="time in yyyy-mm-ddThh:mm:ss"
//% advanced=true
export function get8601Time(): string{
let minutes = timeComponent(TimeType.Minutes)
let seconds = timeComponent(TimeType.Seconds)
let minuteDelimiterString: string = ":"
let secondDelimiterString: string = ":"
if (minutes < 10)
{
minuteDelimiterString = ":0"
}
if (seconds < 10)
{
secondDelimiterString = ":0"
}
let timeString: string = "20" + timeComponent(TimeType.Year) + "-" + timeComponent(TimeType.Month) + "-" + timeComponent(TimeType.Date) + "T" + timeComponent(TimeType.Hours) + minuteDelimiterString + minutes + secondDelimiterString + seconds
return timeString
}
/**
* Get RTC date in mm-dd-yyyy
*/
//% weight=41
//% blockId="gatorRTC_dateUSA"
//% block="date in mm-dd-yyyy"
export function dateUSA(): string{
let timeString: string = timeComponent(TimeType.Month) + "-" + timeComponent(TimeType.Date) + "-" + "20" + timeComponent(TimeType.Year)
return timeString
}
/**
* Get RTC date in dd-mm-yyyy
*/
//% weight=40
//% blockId="gatorRTC_dateWorld"
//% block="date in dd-mm-yyyy"
//% advanced=true
export function dateWorld(): string{
let timeString: string = timeComponent(TimeType.Date) + "-" + timeComponent(TimeType.Month) + "-" + "20" + timeComponent(TimeType.Year)
return timeString
}
/**
* Get RTC timestamp from button press in HH:MM:SS format
*/
//% weight=39
//% blockId="gatorRTC_timestamp"
//% block="button timestamp in HH:MM:SS"
export function timestamp(): string{
let hours = timestampComponent(TimeStampType.Hours)
let minutes = timestampComponent(TimeStampType.Minutes)
let seconds = timestampComponent(TimeStampType.Seconds)
let minuteDelimiterString: string = ":"
let secondDelimiterString: string = ":"
let ampmString: string = ""
if (minutes < 10)
{
minuteDelimiterString = ":0"
}
if (seconds < 10)
{
secondDelimiterString = ":0"
}
if (is12HourMode())
{
ampmString = " AM"
if (isAfternoon())
{
ampmString = " PM"
}
}
let timeStringfirst = hours + minuteDelimiterString + minutes;
let timeString: string = hours + minuteDelimiterString + minutes + secondDelimiterString + seconds + ampmString
return timeString
}
/**
* Get RTC button timestamp in yyyy-mm-ddThh:mm:ss format. This is the ISO8601 standard timestamp format.
*/
//% weight=38
//% blockId="gatorRTC_get8601Timestamp"
//% block="button timestamp in yyyy-mm-ddThh:mm:ss"
//% advanced=true
export function get8601Timestamp(): string{
let minutes = timestampComponent(TimeStampType.Minutes)
let seconds = timestampComponent(TimeStampType.Seconds)
let minuteDelimiterString: string = ":"
let secondDelimiterString: string = ":"
if (minutes < 10)
{
minuteDelimiterString = ":0"
}
if (seconds < 10)
{
secondDelimiterString = ":0"
}
let timeString: string = "20" + timestampComponent(TimeStampType.Year) + "-" + timestampComponent(TimeStampType.Month) + "-" + timestampComponent(TimeStampType.Date) + "T" + timestampComponent(TimeStampType.Hours) + minuteDelimiterString + minutes + secondDelimiterString + seconds
return timeString
}
/**
* Get RTC button timestamp date in mm-dd-yyyy
*/
//% weight=37
//% blockId="gatorRTC_dateUSATimestamp"
//% block="button timestamp date in mm-dd-yyyy"
export function dateUSATimestamp(): string{
let timeString: string = timestampComponent(TimeStampType.Month) + "-" + timestampComponent(TimeStampType.Date) + "-" + "20" + timestampComponent(TimeStampType.Year)
return timeString
}
/**
* Get RTC button timestamp date in dd-mm-yyyy
*/
//% weight=36
//% blockId="gatorRTC_dateWorldTimestamp"
//% block="button timestamp date in dd-mm-yyyy"
//% advanced=true
export function dateWorldTimestamp(): string{
let timeString: string = timestampComponent(TimeStampType.Date) + "-" + timestampComponent(TimeStampType.Month) + "-" + "20" + timestampComponent(TimeStampType.Year)
return timeString
}
/**
* Get one component of the most recent button timestamp on the RTC. Select which component you would like to get from the drop down.
*/
//% weight=35
//% blockId="gatorRTC_timestampComponent"
//% block="value of button timestamp %timeComponent"
//% shim=gatorRTC::timestampComponent
//% advanced=true
export function timestampComponent(timeComponent: TimeStampType): number{
return 0
}
/**
* Switch between standard (12 hour) and military (24 hour) time formats
*/
//% weight=34
//% blockId="gatorRTC_set1224Mode"
//% block="set to %timeType| time"
//% advanced=true
export function set1224Mode(timeType: TimeMode){
if(timeType)
{
set12HourMode()
}
else
{
set24HourMode()
}
}
//% shim=gatorRTC::set12HourMode
function set12HourMode()
{
return
}
//% shim=gatorRTC::set24HourMode
function set24HourMode()
{
return
}
//% shim=gatorRTC::is12HourMode
function is12HourMode(): boolean
{
return false
}
//% shim=gatorRTC::isAfternoon
function isAfternoon(): boolean
{
return true
}
//% shim=gatorRTC::initializeTimestamp
function initializeTimestamp()
{
return false
}
}