Fix a bunch of bugs, but ti's still not linking

This commit is contained in:
Starbeamrainbowlabs 2019-06-13 14:33:08 +01:00
parent 0cdd8f5539
commit 9b76570be8
7 changed files with 59 additions and 13 deletions

View File

@ -24,7 +24,7 @@
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
// This routine sets up the watch dog timer with interrupt handler to maintain a // This routine sets up the watch dog timer with interrupt handler to maintain a
// pool of real entropy for use in sketches. This mechanism is relatively slow // pool of real entropy for use in sketches. This mechanism is relatively slow
// since it will only produce a little less than two 32-bit random values per // since it will only produce a little less than two 32-bit random values per

View File

@ -1,22 +1,40 @@
#include "gps.h" #include "gps.h"
#include "settings.h" #include "settings.h"
// The GPS message decoder
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial serial_gps(PIN_GPS_RX, PIN_GPS_TX);
void gps_begin() { void gps_begin() {
// Initialise the software-based serial connection to the GPS device
serial_gps.begin(BAUD_GPS); serial_gps.begin(BAUD_GPS);
} }
TinyGPSLocation gps_location() { TinyGPSLocation gps_location() {
Serial.print("[gps] Getting location: "); Serial.print("[gps] Getting location: ");
while(serial_gps.available() > 0) { // We WILL discover our location - if it's the last thing we do!
while(true) {
// Make sure there's something to read
if(serial_gps.available() <= 0) {
Serial.print("!");
delay(100);
continue;
}
// If it failed, go around again
if(!gps.encode(serial_gps.read())) if(!gps.encode(serial_gps.read()))
continue; continue;
if(!gps.location.isValid() || gis.location.isUpdated()) { // If we haven't acquired a lock yet, go around again
// Also go around again if the location is the same hasn't yet been updated (GPS devices are strange)
if(!gps.location.isValid() || gps.location.isUpdated()) {
Serial.print("."); Serial.print(".");
delay(100); delay(100);
continue; continue;
} }
// Hooray!
Serial.println("ok"); Serial.println("ok");
return gps.location; return gps.location;
} }

View File

@ -6,12 +6,6 @@
#include "settings.h" #include "settings.h"
// The GPS message decoder
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial serial_gps(PIN_GPS_RX, PIN_GPS_TX);
/** /**
* Initialises the connection to the GPS device. * Initialises the connection to the GPS device.
*/ */

View File

@ -2,18 +2,26 @@
#include <TinyGPS++.h> #include <TinyGPS++.h>
#include "settings.h" #include "settings.h"
#include "random.h"
#include "gps.h" #include "gps.h"
void setup() { void setup() {
Serial.begin(BAUD_PC); Serial.begin(BAUD_PC);
random_begin();
gps_begin(); gps_begin();
TinyGPSLocation loc = get_location(); TinyGPSLocation loc = gps_location();
gps_end(); gps_end();
Serial.print("[main] Location: ("); Serial.print(loc.longitude()); Serial.print(", "); Serial.print(loc.latitude()); Serial.println(); Serial.print("[main] Location: ("); Serial.print(loc.lat()); Serial.print(", "); Serial.print(loc.lng()); Serial.println();
uint32_t id = random_get();
Serial.print("[main] id: ");
Serial.println(id);
} }

10
iot/main/random.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <Entropy.h>
inline void random_begin() {
// Initialise the system to start gathering entropy ready to generate random numbers later
Entropy.initialize();
}
inline uint32_t random_get() {
return Entropy.random();
}

View File

@ -1 +1,16 @@
#pragma once #pragma once
/**
* Initialises the random number generation system.
* It's important to do this as early as possible, as it takes a while to
* gather the necessary entropy in order to actually generate a random number.
*/
void random_begin();
// FUTURE: Swap this out for LoRa untuned wideband radio static?
/**
* Gets an unsigned 32-bit random number.
* @return {uint32_t} A random number.
*/
uint32_t random_get();

View File

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <SD.h> #include <SD.h>
#include <TinyGPS++.h>
#include "settings.h" #include "settings.h"
@ -19,10 +20,10 @@ void store_reading(uint32_t id, TinyGPSLocation location) {
handle.print(id); handle.print(id);
handle.print("\t"); handle.print("\t");
handle.print(location.longitude()); handle.print(location.lat());
handle.print("\t"); handle.print("\t");
handle.print(location.latitude()); handle.print(location.lng());
handle.println(); handle.println();
handle.close(); handle.close();