-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeRadiate-ThermoSense.ino
901 lines (743 loc) · 25.8 KB
/
WeRadiate-ThermoSense.ino
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
/*
Module: WeRadiate-ThermoSense.ino
Function:
Code for the WeRadiate ThermoSense sensor based on Catena 4612
Copyright notice:
See LICENSE file accompanying this project
Author:
Ezra Undag, WeRadiate September 2018
Terry Moore, MCCI Corporation September 2018
Dhinesh Kumar Pitchai, MCCI Corporation November 2020
*/
#include <Catena.h>
#include <Catena_Led.h>
#include <Catena_TxBuffer.h>
#include <Catena_Mx25v8035f.h>
#include <Adafruit_BME280.h>
#include <Catena_Si1133.h>
#include <mcciadk_baselib.h>
#include <MCCI_Sigfox.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/****************************************************************************\
|
| Manifest constants & typedefs.
|
\****************************************************************************/
using namespace McciCatena;
/* parameters for controlling the uplink timing */
enum {
// set this to interval between transmissions, in seconds
// Actual time will be a little longer because have to
// add measurement and broadcast time, but we attempt
// to compensate for the gross effects below.
CATCFG_T_CYCLE = 8 * 60 * 60, // 3 times a day(every 480 minutes)
// uplink cycle time after bootup
CATCFG_T_CYCLE_TEST = 30, // every 30 seconds
CATCFG_T_CYCLE_INITIAL = 30, // every 30 seconds initially
// number of uplinks at initial rate before resetting
CATCFG_INTERVAL_COUNT_INITIAL = 30, // repeat for 15 minutes
};
/* additional timing parameters; ususually you don't change these. */
enum {
// the warm-up time, in seconds
CATCFG_T_WARMUP = 1,
// the settling time uplink, in seconds
CATCFG_T_SETTLE = 5,
// the amount of overhead, total, in seconds.
CATCFG_T_OVERHEAD = (CATCFG_T_WARMUP + CATCFG_T_SETTLE + 2),
// the minimum cycle time
CATCFG_T_MIN = CATCFG_T_OVERHEAD,
// length of day in seconds
CATCFG_T_ONE_DAY = 24 * 60 * 60,
// maximum programmable cycle time
CATCFG_T_MAX = CATCFG_T_ONE_DAY, // normally one hour max.
// default uplink interval, in seconds
CATCFG_INTERVAL_COUNT_DEFAULT = 30,
};
// given a cycle time in seconds, how long should we sleep?
constexpr uint32_t CATCFG_GetInterval(uint32_t tCycle)
{
return (tCycle < CATCFG_T_OVERHEAD + 1)
? 1
: tCycle - CATCFG_T_OVERHEAD
;
}
enum {
// how long to sleep, in seconds.
CATCFG_T_INTERVAL = CATCFG_GetInterval(CATCFG_T_CYCLE),
};
enum {
PIN_ONE_WIRE = A2, // XSDA1 == A2
};
// forwards
bool checkCompostSensorPresent(void);
void fillBuffer(void);
void deepSleepPrepare(void);
void deepSleepRecovery(void);
void settleDone(void);
void setTxCycleTime(unsigned txCycle, unsigned txCount);
void sleepDone(void);
void txFailedDone(void);
bool isManufacturingMode(void);
float updateUsbPower(void);
/****************************************************************************\
|
| Read-only data.
|
\****************************************************************************/
const char sVersion[] = "1.1.0";
//
// set this to the branch you're using, if this is a branch.
const char sBranch[] = "";
// keep by itself, more or less, for easy git rebasing.
//
/****************************************************************************\
|
| Variables.
|
\****************************************************************************/
// the Catena instance
Catena gCatena;
//
// the LED
//
StatusLed gLed (Catena::PIN_STATUS_LED);
// The external temperature sensor
OneWire oneWire(PIN_ONE_WIRE);
DallasTemperature sensor_CompostTemp(&oneWire);
bool fHasCompostTemp;
// The temperature/humidity sensor
Adafruit_BME280 gBme; // The default initalizer creates an I2C connection
bool fBme;
// The LUX sensor
Catena_Si1133 gSi1133;
bool fLux;
// the Flash driver requires a SPI instance for the underlying transport.
SPIClass gSPI2(
Catena::PIN_SPI2_MOSI,
Catena::PIN_SPI2_MISO,
Catena::PIN_SPI2_SCK
);
MCCI_Sigfox Sigfox( "<4-byte_DevID>", "8-byte_PAC", "<16-byte_Key>", REGION_RC2, 0x8080008, false);
// The flash
Catena_Mx25v8035f gFlash;
bool fFlash;
// USB power
bool fUsbPower;
// have we printed the sleep info?
bool g_fPrintedSleeping = false;
// the cycle time to use
unsigned gTxCycle;
// remaining before we reset to default
unsigned gTxCycleCount;
/*
Name: setup()
Function:
Arduino setup function.
Definition:
void setup(
void
);
Description:
This function is called by the Arduino framework after
basic framework has been initialized. We initialize the sensors
that are present on the platform, set up the Sigfox connection,
and (ultimately) return to the framework, which then calls loop()
forever.
Returns:
No explicit result.
*/
void setup(void)
{
Serial.begin(115200);
gCatena.begin();
setup_platform();
setup_built_in_sensors();
setup_external_temp_sensor();
gCatena.SafePrintf("End of setup\n");
/* trigger a join by sending the first packet */
if (! isManufacturingMode())
{
{
/* send the first packet */
startSendingUplink();
}
}
}
/*
Name: setup_platform()
Function:
Setup everything related to the Catena framework. (Not app specific.)
Definition:
void setup_platform(
void
);
Description:
This function only exists to make clear what has to be done for
the framework (as opposed to the actual application). It can be argued
that all this should be part of the gCatena.begin() function.
Returns:
No explicit result.
*/
void setup_platform(void)
{
#ifdef USBCON
// if running unattended, don't wait for USB connect.
if (!(gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fUnattended)))
{
while (!Serial)
/* wait for USB attach */
yield();
}
gCatena.SafePrintf("USB enabled\n");
#else
gCatena.SafePrintf("USB disabled\n");
#endif
gCatena.SafePrintf("\n");
gCatena.SafePrintf("-------------------------------------------------------------------------------\n");
gCatena.SafePrintf("This is the WeRadiate-ThermoSense program V%s%s.\n", sVersion, sBranch);
gCatena.SafePrintf("Current board: %s\n", gCatena.CatenaName());
gCatena.SafePrintf("Enter 'help' for a list of commands.\n");
gCatena.SafePrintf("(remember to select 'Line Ending: Newline' at the bottom of the monitor window.)\n");
gCatena.SafePrintf("--------------------------------------------------------------------------------\n");
gCatena.SafePrintf("\n");
// set up the LED
gLed.begin();
gCatena.registerObject(&gLed);
gLed.Set(LedPattern::FastFlash);
// This function allows to ensure the library initialization has been
// correctly executed.
if ( Sigfox.isReady() ) {
// When using the simple initilization, you can associate in a second step a logger
// The library will print information only if the logs are enable in the config.h file.
// Sigfox.setLogger(&Serial);
// Now let's print some of the information we can get from the library
Serial.println("Sigfox library is ready");
Serial.print(" RC : "); Serial.println(Sigfox.getCurrentRC());
Serial.print(" DevId: 0x"); Serial.println(Sigfox.getDeviceId(),16);
Serial.print(" InitialPac: ");
uint8_t lpac[8];
Sigfox.getInitialPac(lpac);
for (int i = 0 ; i < 8 ; i++) {
Serial.print(lpac[i],16);
}
Serial.println();
Serial.print(" Last Reception Rssi: ");
Serial.print(Sigfox.getLastRssi());
Serial.println("dBm");
Serial.print(" Current Tx Power: ");
Serial.print(Sigfox.getTxPower());
Serial.println("dBm");
Serial.print(" Last Sequence number used: ");
Serial.println(Sigfox.getLastSeqId());
Serial.print(" Sigfox version: ");
Sigfox.printSigfoxVersion();
}
else {
Serial.println("Failed to init Sigfox Library");
while(true);
}
// set up the uplink cycle time.
setTxCycleTime(CATCFG_T_CYCLE_INITIAL, CATCFG_INTERVAL_COUNT_INITIAL);
// display the CPU unique ID
Catena::UniqueID_string_t CpuIDstring;
gCatena.SafePrintf("CPU Unique ID: %s\n",
gCatena.GetUniqueIDstring(&CpuIDstring)
);
/* find the platform */
const Catena::EUI64_buffer_t *pSysEUI = gCatena.GetSysEUI();
uint32_t flags;
const CATENA_PLATFORM * const pPlatform = gCatena.GetPlatform();
if (pPlatform)
{
gCatena.SafePrintf("EUI64: ");
for (unsigned i = 0; i < sizeof(pSysEUI->b); ++i)
{
gCatena.SafePrintf("%s%02x", i == 0 ? "" : "-", pSysEUI->b[i]);
}
gCatena.SafePrintf("\n");
flags = gCatena.GetPlatformFlags();
gCatena.SafePrintf(
"Platform Flags: %#010x\n",
flags
);
gCatena.SafePrintf(
"Operating Flags: %#010x\n",
gCatena.GetOperatingFlags()
);
}
else
{
gCatena.SafePrintf("**** no platform, check provisioning ****\n");
flags = 0;
}
/* initialize the FLASH */
if (gFlash.begin(&gSPI2, Catena::PIN_SPI2_FLASH_SS))
{
fFlash = true;
gFlash.powerDown();
gCatena.SafePrintf("FLASH found, put power down\n");
}
else
{
fFlash = false;
gFlash.end();
gSPI2.end();
gCatena.SafePrintf("No FLASH found: check board\n");
}
/* is it modded? */
uint32_t modnumber = gCatena.PlatformFlags_GetModNumber(flags);
/* modnumber is 102 for WeRadiate app */
if (modnumber != 0)
{
gCatena.SafePrintf("Catena 4612-M%u\n", modnumber);
if (modnumber == 102)
{
fHasCompostTemp = flags & CatenaBase::fHasWaterOneWire;
}
else
{
gCatena.SafePrintf("unknown mod number %d\n", modnumber);
}
}
else
{
gCatena.SafePrintf("No mods detected\n");
}
}
/*
Name: setup_sensors()
Function:
Set up the sensors we intend to use (app specific).
Definition:
void setup_sensors(
void
);
Description:
This function only exists to make clear what has to be done for
the actual application. This is the code that cannot be part of
the generic gCatena.begin() function.
Returns:
No explicit result.
*/
void setup_external_temp_sensor(void)
{
bool fCompostTemp = checkCompostSensorPresent();
if(!fCompostTemp)
{
gCatena.SafePrintf("No one-wire temperature sensor detected\n");
}
else
{
gCatena.SafePrintf("One-wire temperature sensor detected\n");
}
}
// return true if the compost sensor is attached.
bool checkCompostSensorPresent(void)
{
/* set D11 high so V_OUT2 is going to be high for onewire sensor */
pinMode(D11, OUTPUT);
digitalWrite(D11, HIGH);
sensor_CompostTemp.begin();
return sensor_CompostTemp.getDeviceCount() != 0;
}
// setup all the on-board sensors
void setup_built_in_sensors(void)
{
uint32_t flags;
flags = gCatena.GetPlatformFlags();
/* initialize the lux sensor */
if (flags & CatenaStm32::fHasLuxSi1113)
{
if (gSi1133.begin())
{
fLux = true;
gSi1133.configure(0, CATENA_SI1133_MODE_SmallIR);
gSi1133.configure(1, CATENA_SI1133_MODE_White);
gSi1133.configure(2, CATENA_SI1133_MODE_UV);
gSi1133.start();
}
else
{
fLux = false;
gCatena.SafePrintf("No Si1133 found: check platform selection\n");
}
}
else
{
gCatena.SafePrintf("No Si1133 wiring\n");
fLux = false;
}
/* initialize the BME280 */
if (flags & CatenaStm32::fHasBme280)
{
if (gBme.begin(BME280_ADDRESS, Adafruit_BME280::OPERATING_MODE::Sleep))
{
fBme = true;
gCatena.SafePrintf("BME280 found\n");
Adafruit_BME280::Measurements m = gBme.readTemperaturePressureHumidity();
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
// pressure is 2 bytes, hPa * 10.
// humidity is one byte, where 0 == 0/256 and 0xFF == 255/256.
gCatena.SafePrintf(
"BME280: T: %d P: %d RH: %d\n",
(int) m.Temperature,
(int) m.Pressure,
(int) m.Humidity
);
}
else
{
fBme = false;
gCatena.SafePrintf("No BME280 found: check platfom setting\n");
}
}
else
{
fBme = false;
gCatena.SafePrintf("No BME280 found: check wiring. Just nothing. \n");
}
}
/*
Name: loop()
Function:
Arduino loop function.
Definition:
void loop(
void
);
Description:
This function is called repeatedly by the Arduino framework after
setup() has been called.
This version calls gCatena.poll() to drive all the event loops and
timers. For manufacturing test mode, it continuously reads the sensor values,
which will produce serial output.
Returns:
No explicit result.
*/
void loop(void)
{
// put your main code here, to run repeatedly:
gCatena.poll();
/* for mfg test, don't tx, just fill */
if (isManufacturingMode())
{
TxBuffer_t b;
fillBuffer(b);
delay(1000);
}
}
/*
Name: fillBuffer()
Function:
Make measurements and fill a TxBuffer
Definition:
void fillBuffer(
TxBuffer_t &b
);
Description:
This function initializes the buffer with a series of
measurements taken from the sensors. If a serial port
is attached, it also displays data; so it's useful
for manufacturing test, even if you don't want to
send the data.
Returns:
No explicit result.
*/
void fillBuffer(TxBuffer_t &b)
{
b.begin();
b.put(0x00);
float vBat = gCatena.ReadVbat();
gCatena.SafePrintf("vBat: %d mV\n", (int) (vBat * 1000.0f));
b.putV(vBat);
// vBus is sent as 5000 * v
float const vBus = updateUsbPower();
gCatena.SafePrintf("vBus: %d mV\n", (int) (vBus * 1000.0f));
uint32_t bootCount;
gCatena.getBootCount(bootCount);
b.putBootCountLsb(bootCount);
/*
|| Measure and transmit the compost temperature (OneWire)
|| tranducer value. This is complicated because we want
|| to support plug/unplug and the sw interface is not
|| really hot-pluggable.
*/
/* set D11 high so V_OUT2 is going to be high for onewire sensor */
pinMode(D11, OUTPUT);
digitalWrite(D11, HIGH);
bool fCompostTemp = checkCompostSensorPresent();
if (fCompostTemp)
{
sensor_CompostTemp.requestTemperatures();
float compostTempC = sensor_CompostTemp.getTempCByIndex(0);
Serial.print("Compost temperature: "); Serial.print(compostTempC); Serial.println(" C");
// transmit the measurement
b.putT(compostTempC);
}
else if (fHasCompostTemp)
{
gCatena.SafePrintf("No compost temperature\n");
}
/* else
{
gCatena.SafePrintf("Both flag check failed for compost temperature\n");
} */
/* set D11 low to turn off after measuring */
pinMode(D11, INPUT);
}
/*
Name: startSendingUplink()
Function:
Start sending a message to the cloud
Definition:
void startSendingUplink(
void
);
Description:
This function takes a set of measurements, and forwards
them to the cloud. It also has the side-effect of
starting the cyclical finite state machine; at the end
of a transmisison cycle, the system sleeps until the
next cycle and then meausures and sends again.
Returns:
No explicit result.
*/
void startSendingUplink(void)
{
TxBuffer_t b;
bool fStatus;
LedPattern savedLed = gLed.Set(LedPattern::Measuring);
fillBuffer(b);
// gCatena.SafePrintf("Measurement done\n");
if (savedLed != LedPattern::Joining)
{
gLed.Set(LedPattern::Sending);
}
else
{
gLed.Set(LedPattern::Joining);
}
delay(1000);
if ( Sigfox.sendFrame(b.getbase(), b.getn()) == MCCSIG_SUCCESS ) {
fStatus = true;
gCatena.SafePrintf("Send frame success\n");
}
else {
fStatus = false;
// gCatena.SafePrintf("Send frame failed\n");
}
sendBufferDone(fStatus);
}
void
sendBufferDone(
bool fStatus
)
{
gLed.Set(LedPattern::Settling);
if (! fStatus)
{
gCatena.SafePrintf("send buffer failed\n");
txFailedDone();
}
else
{
gCatena.SafePrintf("tx complete\n");
settleDone();
}
}
void txFailedDone(void)
{
gCatena.SafePrintf("check configuration, idling\n");
gLed.Set(LedPattern::NotProvisioned);
}
void settleDone(void)
{
const bool fDeepSleep = checkDeepSleep();
if (! g_fPrintedSleeping)
doSleepAlert(fDeepSleep);
/* count what we're up to */
updateSleepCounters();
if (fDeepSleep)
doDeepSleep();
else
doLightSleep();
}
bool checkDeepSleep(void)
{
bool const fDeepSleepTest = gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
bool fDeepSleep;
if (fDeepSleepTest)
{
fDeepSleep = true;
}
#ifdef USBCON
else if (Serial.dtr())
{
fDeepSleep = false;
}
#endif
else if (gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDisableDeepSleep))
{
fDeepSleep = false;
}
else if ((gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fUnattended)) != 0)
{
fDeepSleep = true;
}
else
{
fDeepSleep = false;
}
return fDeepSleep;
}
void doSleepAlert(const bool fDeepSleep)
{
g_fPrintedSleeping = true;
if (fDeepSleep)
{
bool const fDeepSleepTest = gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
const uint32_t deepSleepDelay = fDeepSleepTest ? 10 : 30;
gCatena.SafePrintf("using deep sleep in %u secs"
#ifdef USBCON
" (USB will disconnect while asleep)"
#endif
": ",
deepSleepDelay
);
// sleep and print
gLed.Set(LedPattern::TwoShort);
for (auto n = deepSleepDelay; n > 0; --n)
{
uint32_t tNow = millis();
while (uint32_t(millis() - tNow) < 1000)
{
gCatena.poll();
yield();
}
gCatena.SafePrintf(".");
}
gCatena.SafePrintf("\nStarting deep sleep.\n");
uint32_t tNow = millis();
while (uint32_t(millis() - tNow) < 100)
{
gCatena.poll();
yield();
}
}
else
gCatena.SafePrintf("using light sleep\n");
}
void updateSleepCounters(void)
{
// update the sleep parameters
if (gTxCycleCount > 1)
{
// values greater than one are decremented and ultimately reset to default.
--gTxCycleCount;
}
else if (gTxCycleCount == 1)
{
// it's now one (otherwise we couldn't be here.)
gCatena.SafePrintf("resetting tx cycle to default: %u\n", CATCFG_T_CYCLE);
gTxCycleCount = 0;
gTxCycle = CATCFG_T_CYCLE;
}
else
{
// it's zero. Leave it alone.
}
}
void doDeepSleep(void)
{
bool const fDeepSleepTest = gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fDeepSleepTest);
uint32_t const sleepInterval = CATCFG_GetInterval(
fDeepSleepTest ? CATCFG_T_CYCLE_TEST : gTxCycle
);
/* ok... now it's time for a deep sleep */
gLed.Set(LedPattern::Off);
deepSleepPrepare();
/* sleep */
gCatena.Sleep(sleepInterval);
/* recover from sleep */
deepSleepRecovery();
/* and now... we're awake again. trigger another measurement */
sleepDone();
}
void deepSleepPrepare(void)
{
Serial.end();
Wire.end();
SPI.end();
if (fFlash)
gSPI2.end();
}
void deepSleepRecovery(void)
{
Serial.begin();
Wire.begin();
SPI.begin();
if (fFlash)
gSPI2.begin();
}
void doLightSleep(void)
{
uint32_t interval = CATCFG_GetInterval(gTxCycle);
gLed.Set(LedPattern::Sleeping);
if (gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fQuickLightSleep))
{
interval = 1;
}
gLed.Set(LedPattern::Sleeping);
delay(interval);
sleepDone();
}
void sleepDone(void)
{
gLed.Set(LedPattern::WarmingUp);
warmupDone();
}
static void warmupDone(void)
{
startSendingUplink();
}
// read and return USB power, and update the global fUsbPower flag.
float updateUsbPower(void)
{
float vBus = gCatena.ReadVbus();
fUsbPower = (vBus > 4.0) ? true : false;
return vBus;
}
// set the transmit cycle time
void setTxCycleTime(
unsigned txCycle,
unsigned txCount
)
{
if (txCount > 0)
gCatena.SafePrintf(
"message cycle time %u seconds for %u messages\n",
txCycle, txCount
);
else
gCatena.SafePrintf(
"message cycle time %u seconds indefinitely\n",
txCycle
);
gTxCycle = txCycle;
gTxCycleCount = txCount;
}
// is device in manufacturing mode?
bool isManufacturingMode(void)
{
return (gCatena.GetOperatingFlags() &
static_cast<uint32_t>(gCatena.OPERATING_FLAGS::fManufacturingTest)) != 0;
}