Skip to content

Commit a2d8c6a

Browse files
committed
move time functions to godmode
1 parent 709b697 commit a2d8c6a

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

cpp/arduino/Arduino.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
11
#include "Arduino.h"
22
#include "Godmode.h"
33

4-
unsigned long millis() {
5-
GodmodeState* godmode = GODMODE();
6-
return godmode->micros / 1000;
7-
}
8-
9-
unsigned long micros() {
10-
GodmodeState* godmode = GODMODE();
11-
return godmode->micros;
12-
}
13-
14-
void delay(unsigned long millis) {
15-
GodmodeState* godmode = GODMODE();
16-
godmode->micros += millis * 1000;
17-
}
18-
19-
void delayMicroseconds(unsigned long micros) {
20-
GodmodeState* godmode = GODMODE();
21-
godmode->micros += micros;
22-
}
23-
24-
25-
void randomSeed(unsigned long seed)
26-
{
27-
GodmodeState* godmode = GODMODE();
28-
godmode->seed = seed;
29-
}
30-
31-
long random(long vmax)
32-
{
33-
GodmodeState* godmode = GODMODE();
34-
godmode->seed += 4294967291; // it's a prime that fits in 32 bits
35-
return godmode->seed % vmax;
36-
}
37-
38-
long random(long vmin, long vmax)
39-
{
40-
return vmin < vmax ? (random(vmax - vmin) + vmin) : vmin;
41-
}
424

435
void digitalWrite(unsigned char pin, unsigned char val) {
446
GodmodeState* godmode = GODMODE();

cpp/arduino/Godmode.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,42 @@ GodmodeState godmode = GodmodeState();
55
GodmodeState* GODMODE() {
66
return &godmode;
77
}
8+
9+
unsigned long millis() {
10+
GodmodeState* godmode = GODMODE();
11+
return godmode->micros / 1000;
12+
}
13+
14+
unsigned long micros() {
15+
GodmodeState* godmode = GODMODE();
16+
return godmode->micros;
17+
}
18+
19+
void delay(unsigned long millis) {
20+
GodmodeState* godmode = GODMODE();
21+
godmode->micros += millis * 1000;
22+
}
23+
24+
void delayMicroseconds(unsigned long micros) {
25+
GodmodeState* godmode = GODMODE();
26+
godmode->micros += micros;
27+
}
28+
29+
30+
void randomSeed(unsigned long seed)
31+
{
32+
GodmodeState* godmode = GODMODE();
33+
godmode->seed = seed;
34+
}
35+
36+
long random(long vmax)
37+
{
38+
GodmodeState* godmode = GODMODE();
39+
godmode->seed += 4294967291; // it's a prime that fits in 32 bits
40+
return godmode->seed % vmax;
41+
}
42+
43+
long random(long vmin, long vmax)
44+
{
45+
return vmin < vmax ? (random(vmax - vmin) + vmin) : vmin;
46+
}

cpp/arduino/Godmode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ class GodmodeState {
3636

3737
GodmodeState* GODMODE();
3838

39+
// random
40+
void randomSeed(unsigned long seed);
41+
long random(long vmax);
42+
long random(long vmin, long vmax);
43+
44+
45+
// Time
46+
void delay(unsigned long millis);
47+
void delayMicroseconds(unsigned long micros);
48+
unsigned long millis();
49+
unsigned long micros();
50+

cpp/arduino/Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "Godmode.h"
23
#include "WString.h"
34
#include "Print.h"
45

0 commit comments

Comments
 (0)