Start weaving the libraries together, but there's quite a ways to go.....

This commit is contained in:
Starbeamrainbowlabs 2019-06-12 20:18:37 +01:00
parent 9dcdad5809
commit 45542edf17
7 changed files with 116 additions and 0 deletions

5
compile_flags.txt Normal file
View File

@ -0,0 +1,5 @@
-include/home/sbrl/Downloads/arduino/hardware/arduino/avr/cores/arduino/Arduino.h
-include/home/sbrl/Arduino/libraries/TinyGPSPlus/src/TinyGPS++.h
-include/home/sbrl/Downloads/arduino/libraries/SD/src/SD.h
-I/home/sbrl/Downloads/arduino/libraries/
-I

6
iot/main/gps.c Normal file
View File

@ -0,0 +1,6 @@
#include "gps.h"
#include "settings.h"
void gps_begin() {
serial_gps.begin(BAUD_GPS);
}

25
iot/main/gps.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <SoftwareSerial.h>
#include <TinyGPS++.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.
*/
void gps_begin();
/**
* Fetches the current location from the GPS device.
* May take a moment, as the GPS device needs time to acquire a satellite fix.
* @return TinyGPSLocation The current location.
*/
TinyGPSLocation get_location();

18
iot/main/main.ino Normal file
View File

@ -0,0 +1,18 @@
#include <Arduino.h>
#include "settings.h"
#include "gps.h"
void setup() {
Serial.begin(BAUD_PC);
gps_begin();
get_location();
}
void loop() {
}

33
iot/main/settings.h Normal file
View File

@ -0,0 +1,33 @@
#pragma once
//////////////////////////////////
////////////// Main //////////////
//////////////////////////////////
// The speed at which we should talk over our main hardware serial connection.
#define BAUD_PC 115200
// Multiple devices can use the same SPI data pin AFAIKT, but some libraries *cough* SD *cough* are too stupid to figure out which pin it is on their own.
#define PIN_SPI_DATA 9
/////////////////////////////////
////////////// GPS //////////////
/////////////////////////////////
// The *TX* gin of the GPS device.
// This is swapped because we receive the GPS device's message on our side on the RX pin, and the GPS device transmits messages on the TX.
#define PIN_GPS_RX 4
// The *RX* pin on the GPS device.
// This is swapped because where the GPs device is receiving, we aresending and vice versa.
// The TX / RX here are according to *our* side, not the GPS device's side.
#define PIN_GPS_TX 3
// The speed at which we should talk to the GPS device. Some GPS devices require a certain speed in order to use certain commands, so it's important that you check the datasheets for the device you're using.
// 9600 is the correct speed for a NEO-6M.
#define BAUD_GPS 9600
//////////////////////////////////
////////// microSD Card //////////
//////////////////////////////////
//
#define PIN_SD_SPI_CHIP_SELECT 3

17
iot/main/storage.c Normal file
View File

@ -0,0 +1,17 @@
#include <Arduino.h>
#include <SD.h>
#include "settings.h"
void store_init() {
pinMode(PIN_SPI_CHIP_SELECT, OUTPUT);
if(!SD.begin(PIN_SPI_DATA)) {
Serial.println("Error: Failed to initialise connection to microSD card");
while(true) { delay(1); } // Pseudo-halt, but uses delay() to ensure we keep passing back control to allow easy re-programming
}
}
void store_reading(uint32_t id, TinyGPSLocation location) {
File handle;
}

12
iot/main/storage.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>
void store_init();
void store_reading(uint32_t id, TinyGPSLocation location);
void store_close();