forked from cgwood/ArdustationMega
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asm.h
81 lines (64 loc) · 2.11 KB
/
asm.h
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
// ASM Parameters
// Created 2012 By Colin G http://www.diydrones.com/profile/ColinG
static float load;
#define BATTSAMPLES 30 // Too high and the averaging code has to change
struct ArduStation {
// Properties
uint32_t time; ///< GPS time (milliseconds from epoch)
uint32_t date; ///< GPS date (FORMAT TBD)
int32_t altitude; ///< altitude in cm
int16_t hdop; ///< horizontal dilution of precision in cm
uint8_t num_sats; ///< Number of visible satelites
uint8_t gps_status; ///< GPS fix status
float lat;
float lon;
float alt;
int encoderval;
int batt_sum;
int batt_sample[BATTSAMPLES]; // Average over last BATTSAMPLES readings
uint8_t batt_i; // Which index of batt did we last write to
float batt_min; // For scaling on the front page
float batt_max; // For scaling on the front page
uint8_t SDok; // Whether the SD card initialised ok
unsigned long last_hb; // Timestamp of last heartbeat
unsigned long hb_period; // Moving average of the heartbeat period
int rssi_sum;
int rssi_sample[BATTSAMPLES]; // Average over last BATTSAMPLES readings
uint8_t rssi_i; // Which index of rssi did we last write to
};
ArduStation ASM;
// Initialize default values (this will later be in the construction section of the class)
void
init_batt() {
int initval = analogRead(A8);
ASM.batt_i=0;
for (uint8_t i=0;i<BATTSAMPLES;i++)
ASM.batt_sample[i] = initval;
ASM.batt_sum = initval*BATTSAMPLES;
}
void
sample_batt() {
// Get the new reading for the moving average
ASM.batt_sum -= ASM.batt_sample[ASM.batt_i];
ASM.batt_sample[ASM.batt_i] = analogRead(A7);
ASM.batt_sum += ASM.batt_sample[ASM.batt_i];
// Move the index along
ASM.batt_i++;
if (ASM.batt_i > BATTSAMPLES-1)
ASM.batt_i = 0;
}
float
get_batt() {
float v = ASM.batt_sum;
v /= 30.0;//BATTSAMPLES;
// v *= 0.0048828125;
v *= 0.01731;
return v;
}
int get_rssi() {
int rssi;
rssi = analogRead(A15);
// Scale as working on 3.3v logic
rssi*=1.5;
return constrain(rssi,0,1023);
}