Global change

This commit is contained in:
Dmitry Borisenko
2020-06-19 22:14:50 +02:00
parent 446809355b
commit 817a3e5898
90 changed files with 3370 additions and 2709 deletions

View File

@@ -0,0 +1,2 @@
0.01 2019-01-14
- initial version

View File

@@ -0,0 +1,15 @@
all: README examples/UpTime_tick/README examples/UpTime_synopsis/README
clean:
rm -f README README.bak \
examples/UpTime_tick/README examples/UpTime_tick/README.bak \
examples/UpTime_synopsis/README examples/UpTime_synopsis/README.bak
README: UpTime.h
pod2readme $< $@ && rm -f $@.bak
examples/UpTime_tick/README: examples/UpTime_tick/UpTime_tick.ino
pod2readme $< $@ && rm -f $@.bak
examples/UpTime_synopsis/README: examples/UpTime_synopsis/UpTime_synopsis.ino
pod2readme $< $@ && rm -f $@.bak

99
lib/Arduino-UpTime/README Normal file
View File

@@ -0,0 +1,99 @@
NAME
UpTime.h - Arduino uptime and events in seconds
SYNOPSIS
#include <Arduino.h>
#include <UpTime.h> // https://github.com/jozef/Arduino-UpTime
uptime_interval fire2(2);
uptime_interval fire5(5,UPTIME_RIGHT_AWAY);
void setup () {
Serial.begin(9600);
}
void loop () {
Serial.println("uptime: "+uptime_as_string()+" or "+uptime()+"s");
if (fire2.check()) Serial.println("2s elapsed");
if (fire5.check()) Serial.println("5s elapsed");
delay(1400);
}
will output:
uptime: 00:00:00 or 0s
5s elapsed
uptime: 00:00:01 or 1s
uptime: 00:00:02 or 2s
2s elapsed
uptime: 00:00:04 or 4s
2s elapsed
uptime: 00:00:05 or 5s
5s elapsed
uptime: 00:00:07 or 7s
2s elapsed
uptime: 00:00:08 or 8s
2s elapsed
uptime: 00:00:09 or 9s
uptime: 00:00:11 or 11s
2s elapsed
5s elapsed
uptime: 04:41:23 or 16883s
uptime: 04:41:25 or 16885s
2s elapsed
5s elapsed
uptime: 04:41:26 or 16886s
2s elapsed
uptime: 04:41:28 or 16888s
2s elapsed
uptime: 04:41:29 or 16889s
uptime: 04:41:30 or 16890s
2s elapsed
5s elapsed
DESCRIPTION
Uptime class is made to to track uptime of Arduino in seconds. The
uptime() or check() functions has to be called at least once for 0xFFFF
seconds (once in 18h) to work. Seconds will be counted even after
Arduinos millis() overrun and the seconds of unsigned long are enough
to not overrun sooner then in 136+ years. Once 0xFFFF0000 seconds is
elapsed, will trigger reset so that Arduino program clearly starts all
over again.
METHODS
bool check()
Returns true/false if the interval elapset.
void reset(bool postpone = true)
Will reset the time to count from current moment in until interval. If
postpone is set to false, check() will return true with next call.
INSTALL
git clone https://github.com/jozef/Arduino-UpTime sketchbook/libraries/UpTime
EXAMPLES
examples/UpTime_tick/UpTime_synopsis.ino
synopsis section example
examples/UpTime_tick/UpTime_tick.ino
print formatted and raw uptime in seconds und 4x interval
LICENSE
This is free software, licensed under the MIT License.
AUTHOR
Jozef Kutej

View File

@@ -0,0 +1,65 @@
/* see UpTime.h */
#include <Arduino.h>
#include <UpTime.h>
unsigned long _uptime_seconds = 0;
void (*time_to_die)(void) = 0; // reset Arduino after 136+ years
unsigned long uptime() {
unsigned int cur_second = millis() / 1000;
unsigned int _uptime_seconds_uint = _uptime_seconds;
while (_uptime_seconds_uint != cur_second) {
_uptime_seconds++;
_uptime_seconds_uint++;
if (_uptime_seconds > 0xFFFF0000) time_to_die();
}
return _uptime_seconds;
}
uptime_interval::uptime_interval(unsigned int inte, bool postpone) : interval(inte) {
reset(postpone);
}
bool uptime_interval::check() {
if (next <= uptime()) {
next += interval;
return true;
}
return false;
}
void uptime_interval::reset(bool postpone) {
next = (postpone ? _uptime_seconds + interval : _uptime_seconds);
}
String _uptime_two_dig(uint8_t x) {
if (x > 9) {
return String(x);
}
else {
return "0"+String(x);
}
}
String uptime_as_string() {
unsigned long tmp_uptime = uptime();
unsigned long seconds;
unsigned long minutes;
unsigned long hours;
unsigned long days;
seconds = tmp_uptime % 60;
tmp_uptime = tmp_uptime / 60;
minutes = tmp_uptime % 60;
tmp_uptime = tmp_uptime / 60;
hours = tmp_uptime % 24;
days = tmp_uptime / 24;
return (days ? String(days)+'d'+' ' : "")
+ _uptime_two_dig(hours)
+ ':' + _uptime_two_dig(minutes)
+ ':' + _uptime_two_dig(seconds);
}

124
lib/Arduino-UpTime/UpTime.h Normal file
View File

@@ -0,0 +1,124 @@
/* VERSION 0.01; 14.1.2019; see below for description and documentation */
#ifndef UpTime_h
#define UpTime_h
#define UPTIME_RIGHT_AWAY false
unsigned long uptime();
String uptime_as_string();
class uptime_interval {
private:
unsigned long next;
unsigned int interval;
public:
uptime_interval(unsigned int inte, bool postpone = true);
bool check();
void reset(bool postpone = true);
};
#endif
/*
=head1 NAME
UpTime.h - Arduino uptime and events in seconds
=head1 SYNOPSIS
#include <Arduino.h>
#include <UpTime.h> // https://github.com/jozef/Arduino-UpTime
uptime_interval fire2(2);
uptime_interval fire5(5,UPTIME_RIGHT_AWAY);
void setup () {
Serial.begin(9600);
}
void loop () {
Serial.println("uptime: "+uptime_as_string()+" or "+uptime()+"s");
if (fire2.check()) Serial.println("2s elapsed");
if (fire5.check()) Serial.println("5s elapsed");
delay(1400);
}
will output:
uptime: 00:00:00 or 0s
5s elapsed
uptime: 00:00:01 or 1s
uptime: 00:00:02 or 2s
2s elapsed
uptime: 00:00:04 or 4s
2s elapsed
uptime: 00:00:05 or 5s
5s elapsed
uptime: 00:00:07 or 7s
2s elapsed
uptime: 00:00:08 or 8s
2s elapsed
uptime: 00:00:09 or 9s
uptime: 00:00:11 or 11s
2s elapsed
5s elapsed
uptime: 04:41:23 or 16883s
uptime: 04:41:25 or 16885s
2s elapsed
5s elapsed
uptime: 04:41:26 or 16886s
2s elapsed
uptime: 04:41:28 or 16888s
2s elapsed
uptime: 04:41:29 or 16889s
uptime: 04:41:30 or 16890s
2s elapsed
5s elapsed
=head1 DESCRIPTION
Uptime class is made to to track uptime of Arduino in seconds. The uptime()
or check() functions has to be called at least once for 0xFFFF seconds
(once in 18h) to work. Seconds will be counted even after Arduinos
millis() overrun and the seconds of unsigned long are enough to not overrun
sooner then in 136+ years. Once 0xFFFF0000 seconds is elapsed, will trigger
reset so that Arduino program clearly starts all over again.
=head1 METHODS
=head2 bool check()
Returns true/false if the interval elapset.
=head2 void reset(bool postpone = true)
Will reset the time to count from current moment in until interval. If
C<postpone> is set to false, check() will return true with next call.
=head1 INSTALL
git clone https://github.com/jozef/Arduino-UpTime sketchbook/libraries/UpTime
=head1 EXAMPLES
=head2 examples/UpTime_tick/UpTime_synopsis.ino
synopsis section example
=head2 examples/UpTime_tick/UpTime_tick.ino
print formatted and raw uptime in seconds und 4x interval
=head1 LICENSE
This is free software, licensed under the MIT License.
=head1 AUTHOR
Jozef Kutej
=cut
*/

View File

@@ -0,0 +1,4 @@
DESCRIPTION
synopsis section example from UpTime.h

View File

@@ -0,0 +1,24 @@
/*
=head1 DESCRIPTION
synopsis section example from UpTime.h
=cut
*/
#include <Arduino.h>
#include <UpTime.h> // https://github.com/jozef/Arduino-UpTime
uptime_interval fire2(2);
uptime_interval fire5(5,UPTIME_RIGHT_AWAY);
void setup () {
Serial.begin(9600);
}
void loop () {
Serial.println("uptime: "+uptime_as_string()+" or "+uptime()+"s");
if (fire2.check()) Serial.println("2s elapsed");
if (fire5.check()) Serial.println("5s elapsed");
delay(1400);
}

View File

@@ -0,0 +1,11 @@
NAME
UpTime_tick.ino - print formatted and raw uptime in seconds und 4x
interval
DESCRIPTION
On serial port will print current uptime in seconds with 4 interval
checks. Each loop has random 0-5s delay. Intervals will be printed once
elapsed.

View File

@@ -0,0 +1,52 @@
/*
=head1 NAME
UpTime_tick.ino - print formatted and raw uptime in seconds und 4x interval
=head1 DESCRIPTION
On serial port will print current uptime in seconds with 4 interval checks.
Each loop has random 0-5s delay. Intervals will be printed once elapsed.
=cut
*/
#include <Arduino.h>
#include <UpTime.h> // https://github.com/jozef/Arduino-UpTime
uptime_interval fire2(2);
uptime_interval fire5(5);
uptime_interval fire10(10, UPTIME_RIGHT_AWAY);
uptime_interval fire60(60, UPTIME_RIGHT_AWAY);
void setup () {
Serial.begin(9600);
while (Serial.available()) { Serial.read(); }
randomSeed(analogRead(0));
}
void loop () {
Serial.print("uptime: ");
Serial.println(uptime_as_string());
if (fire2.check()) {
Serial.println("fire 2s");
}
if (fire5.check()) {
Serial.println("fire 5s");
}
if (fire10.check()) {
Serial.println("fire 10s");
}
if (fire60.check()) {
Serial.println("fire 60s");
}
int rand_delay = random(5000);
Serial.print("delay(");
Serial.print(rand_delay);
Serial.println(")");
delay(rand_delay);
}