Skip to content

Commit cf6a73e

Browse files
committed
Merge pull request #17 from carledwards/add_delay_with_loop_polling
Serial output is affected while sampling temperature Blink time parameter was not being passed into the blinkColor method Added a delay method on Scout to allow the system to continue performing background system tasks
2 parents 1d666c9 + 192c3c0 commit cf6a73e

File tree

10 files changed

+45
-45
lines changed

10 files changed

+45
-45
lines changed

Scout.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void PinoccioScout::loop() {
7878
}
7979
}
8080

81+
void PinoccioScout::delay(unsigned long ms) {
82+
unsigned long target = millis() + ms;
83+
while ((long)(millis() - target) < 0) {
84+
loop();
85+
}
86+
}
87+
8188
bool PinoccioScout::isBatteryCharging() {
8289
return isBattCharging;
8390
}

Scout.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PinoccioScout : public PinoccioClass {
2424

2525
void setup(bool isForcedLeadScout=false);
2626
void loop();
27+
void delay(unsigned long ms);
2728

2829
bool isBatteryCharging();
2930
int getBatteryPercentage();

examples/Peripherals/BlinkRGB/BlinkRGB.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ void setup() {
99
void loop() {
1010
Scout.loop();
1111

12-
RgbLed.blinkRed();
13-
delay(1000);
12+
// blink once for 250ms
13+
RgbLed.blinkRed(250);
14+
Scout.delay(1000);
15+
16+
// blink once using the default (500ms)
1417
RgbLed.blinkGreen();
15-
delay(1000);
16-
RgbLed.blinkBlue();
17-
delay(1000);
18+
Scout.delay(1000);
19+
20+
// blink once using 750ms
21+
RgbLed.blinkBlue(750);
22+
Scout.delay(1000);
1823
}

examples/Peripherals/Temperature/Temperature.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ void loop() {
1212
Serial.print("Temperature: ");
1313
Serial.println(Scout.getTemperature());
1414

15-
delay(1000);
15+
Scout.delay(1000);
1616
}

examples/Peripherals/TrueRandomNumber/TrueRandomNumber.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ void loop() {
1212
Serial.print("Random Number: ");
1313
Serial.println(Scout.getRandomNumber());
1414

15-
delay(1000);
15+
Scout.delay(1000);
1616
}

examples/Power/BackpackPower/BackpackPower.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ void loop() {
1111

1212
Scout.enableBackpackVcc();
1313
Serial.println("Backpack VCC is on.");
14-
delay(3000);
14+
Scout.delay(3000);
1515

1616
Scout.disableBackpackVcc();
1717
Serial.println("Backpack VCC is off.");
18-
delay(3000);
18+
Scout.delay(3000);
1919
}

examples/Power/BatteryStatus/BatteryStatus.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ void loop() {
2323
}
2424

2525
Serial.println("");
26-
delay(3000);
26+
Scout.delay(3000);
2727
}

utility/halRgbLed.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,46 +96,46 @@ void HalRgbLed::white() {
9696
}
9797

9898
void HalRgbLed::blinkRed(unsigned int ms) {
99-
blinkColor(255, 0, 0);
99+
blinkColor(255, 0, 0, ms);
100100
}
101101

102102
void HalRgbLed::blinkGreen(unsigned int ms) {
103-
blinkColor(0, 255, 0);
103+
blinkColor(0, 255, 0, ms);
104104
}
105105

106106
void HalRgbLed::blinkBlue(unsigned int ms) {
107-
blinkColor(0, 0, 255);
107+
blinkColor(0, 0, 255, ms);
108108
}
109109

110110
void HalRgbLed::blinkCyan(unsigned int ms) {
111-
blinkColor(0, 255, 255);
111+
blinkColor(0, 255, 255, ms);
112112
}
113113

114114
void HalRgbLed::blinkPurple(unsigned int ms) {
115-
blinkColor(50, 0, 255);
115+
blinkColor(50, 0, 255, ms);
116116
}
117117

118118
void HalRgbLed::blinkMagenta(unsigned int ms) {
119-
blinkColor(255, 0, 255);
119+
blinkColor(255, 0, 255, ms);
120120
}
121121

122122
void HalRgbLed::blinkYellow(unsigned int ms) {
123-
blinkColor(255, 255, 0);
123+
blinkColor(255, 255, 0, ms);
124124
}
125125

126126
void HalRgbLed::blinkOrange(unsigned int ms) {
127-
blinkColor(255, 127, 0);
127+
blinkColor(255, 127, 0, ms);
128128
}
129129

130130
void HalRgbLed::blinkWhite(unsigned int ms) {
131-
blinkColor(255, 255, 255);
131+
blinkColor(255, 255, 255, ms);
132132
}
133133

134134
void HalRgbLed::blinkTorch(unsigned int ms) {
135135
blinkColor(torchRedValue, torchGreenValue, torchBlueValue, ms);
136136
}
137137

138-
void HalRgbLed::blinkColor(short red, short green, short blue, int ms) {
138+
void HalRgbLed::blinkColor(short red, short green, short blue, unsigned int ms) {
139139
if (!isEnabled()) {
140140
return;
141141
}

utility/halRgbLed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class HalRgbLed {
4343
void blinkOrange(unsigned int ms=500);
4444
void blinkWhite(unsigned int ms=500);
4545
void blinkTorch(unsigned int ms=500);
46-
void blinkColor(short red, short green, short blue, int ms=500);
46+
void blinkColor(short red, short green, short blue, unsigned int ms=500);
4747

4848
void setRedValue(int value);
4949
void setGreenValue(int value);

utility/halTemperature.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,31 @@
1515

1616
/*****************************************************************************
1717
*****************************************************************************/
18-
static volatile uint8_t halAdcFinished;
1918
static int8_t halAdcOffset;
2019

20+
static inline void sleep (void)
21+
{
22+
asm volatile("sleep");
23+
}
24+
2125
/*****************************************************************************
2226
*****************************************************************************/
2327
static inline int16_t HAL_AdcMeasure(void) {
24-
set_sleep_mode(SLEEP_MODE_ADC);
2528
/* dummy cycle */
26-
halAdcFinished = false;
2729
do
2830
{
29-
sleep_mode();
30-
/* sleep, wake up by ADC IRQ */
31-
/* check here for ADC IRQ because sleep mode could wake up from * another source too */
31+
sleep();
3232
}
33-
while (false == halAdcFinished);
34-
//while (ADCSRA & (1 << ADSC));
35-
/* set by ISR */
33+
while (ADCSRA & (1 << ADSC));
34+
35+
/* set by ISR */
3636
return ADC;
3737
}
3838

3939
/*****************************************************************************
4040
*****************************************************************************/
4141
int8_t HAL_MeasureTemperature(void) {
4242
int32_t val;
43-
uint8_t adcsrc = ADCSRC;
44-
uint8_t adcsrb = ADCSRB;
45-
uint8_t adcsra = ADCSRA;
46-
uint8_t admux = ADMUX;
4743

4844
ADCSRC = 10 << ADSUT0;
4945
ADCSRB = (1 << MUX5);
@@ -55,20 +51,11 @@ int8_t HAL_MeasureTemperature(void) {
5551
ADCSRA |= (1 << ADIF); /* clear flag */
5652
ADCSRA |= (1 << ADIE);
5753

58-
/* dummy cycle after REF change (suggested by datasheet) */
54+
// dummy cycle after REF change (suggested by datasheet)
5955
HAL_AdcMeasure();
6056

6157
val = HAL_AdcMeasure();
6258

63-
ADCSRA = adcsra;
64-
ADCSRB = adcsrb;
65-
ADCSRC = adcsrc;
66-
ADMUX = admux;
59+
ADCSRA = 0;
6760
return (int)((1.13 * val - 272.8)) + HAL_TEMPERATURE_CALIBRATION_OFFSET - 3;
6861
}
69-
70-
/*****************************************************************************
71-
*****************************************************************************/
72-
ISR(ADC_vect, ISR_BLOCK) {
73-
halAdcFinished = true;
74-
}

0 commit comments

Comments
 (0)