kopia lustrzana https://github.com/helium/longfi-arduino
fixes
rodzic
c4c3f1eab0
commit
09b9968f4b
|
@ -35,10 +35,9 @@
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
|
|
||||||
|
#include <CayenneLPP.h>
|
||||||
#include <MicroNMEA.h>
|
#include <MicroNMEA.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <CayenneLPP.h>
|
|
||||||
|
|
||||||
// I2C communication parameters
|
// I2C communication parameters
|
||||||
#define DEFAULT_DEVICE_ADDRESS 0x3A
|
#define DEFAULT_DEVICE_ADDRESS 0x3A
|
||||||
|
@ -137,13 +136,9 @@ const lmic_pinmap lmic_pins = *Arduino_LMIC::GetPinmap_Disco_L072cz_Lrwan1();
|
||||||
#error "Unknown target"
|
#error "Unknown target"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ppsHandler(void)
|
void ppsHandler(void) { ppsTriggered = true; }
|
||||||
{
|
|
||||||
ppsTriggered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gpsHardwareReset()
|
void gpsHardwareReset() {
|
||||||
{
|
|
||||||
// reset the device
|
// reset the device
|
||||||
digitalWrite(RESET_PIN, LOW);
|
digitalWrite(RESET_PIN, LOW);
|
||||||
delay(50);
|
delay(50);
|
||||||
|
@ -154,23 +149,20 @@ void gpsHardwareReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read 32 bytes from I2C
|
// Read 32 bytes from I2C
|
||||||
void readI2C(char *inBuff)
|
void readI2C(char *inBuff) {
|
||||||
{
|
|
||||||
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
||||||
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
||||||
gps.endTransmission(false);
|
gps.endTransmission(false);
|
||||||
gps.requestFrom((uint8_t)DEFAULT_DEVICE_ADDRESS, (uint8_t)32);
|
gps.requestFrom((uint8_t)DEFAULT_DEVICE_ADDRESS, (uint8_t)32);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (gps.available())
|
while (gps.available()) {
|
||||||
{
|
|
||||||
inBuff[i] = gps.read();
|
inBuff[i] = gps.read();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a NMEA command via I2C
|
// Send a NMEA command via I2C
|
||||||
void sendCommand(char *cmd)
|
void sendCommand(char *cmd) {
|
||||||
{
|
|
||||||
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
gps.beginTransmission(DEFAULT_DEVICE_ADDRESS);
|
||||||
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
gps.write((uint8_t)DEFAULT_DEVICE_PORT);
|
||||||
MicroNMEA::sendSentence(gps, cmd);
|
MicroNMEA::sendSentence(gps, cmd);
|
||||||
|
@ -295,8 +287,7 @@ void onEvent(ev_t ev) {
|
||||||
|
|
||||||
void readGPS() {
|
void readGPS() {
|
||||||
// If a message is recieved print all the informations
|
// If a message is recieved print all the informations
|
||||||
if (ppsTriggered)
|
if (ppsTriggered) {
|
||||||
{
|
|
||||||
ppsTriggered = false;
|
ppsTriggered = false;
|
||||||
ledState = !ledState;
|
ledState = !ledState;
|
||||||
digitalWrite(LED_BUILTIN, ledState);
|
digitalWrite(LED_BUILTIN, ledState);
|
||||||
|
@ -348,6 +339,7 @@ void readGPS() {
|
||||||
else
|
else
|
||||||
Serial.println("not available");
|
Serial.println("not available");
|
||||||
|
|
||||||
|
// Pack CayenneLPP Payload
|
||||||
lpp.addGPS(1, latitude_mdeg, longitude_mdeg, alt);
|
lpp.addGPS(1, latitude_mdeg, longitude_mdeg, alt);
|
||||||
|
|
||||||
Serial.print("Speed: ");
|
Serial.print("Speed: ");
|
||||||
|
@ -356,13 +348,11 @@ void readGPS() {
|
||||||
Serial.println(nmea.getCourse() / 1000., 3);
|
Serial.println(nmea.getCourse() / 1000., 3);
|
||||||
Serial.println("-----------------------");
|
Serial.println("-----------------------");
|
||||||
nmea.clear();
|
nmea.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
while (!ppsTriggered) {
|
||||||
char c;
|
char c;
|
||||||
if (idx == 0)
|
if (idx == 0) {
|
||||||
{
|
|
||||||
readI2C(buff);
|
readI2C(buff);
|
||||||
delay(I2C_DELAY);
|
delay(I2C_DELAY);
|
||||||
}
|
}
|
||||||
|
@ -371,8 +361,7 @@ void readGPS() {
|
||||||
idx++;
|
idx++;
|
||||||
idx %= 32;
|
idx %= 32;
|
||||||
// If we have a valid character pass it to the library
|
// If we have a valid character pass it to the library
|
||||||
if ((uint8_t) c != 0xFF)
|
if ((uint8_t)c != 0xFF) {
|
||||||
{
|
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
nmea.process(c);
|
nmea.process(c);
|
||||||
}
|
}
|
||||||
|
@ -427,18 +416,15 @@ void setup() {
|
||||||
char c;
|
char c;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
memset(buff, 0, 32);
|
memset(buff, 0, 32);
|
||||||
do
|
do {
|
||||||
{
|
if (idx == 0) {
|
||||||
if (idx == 0)
|
|
||||||
{
|
|
||||||
readI2C(buff);
|
readI2C(buff);
|
||||||
delay(I2C_DELAY);
|
delay(I2C_DELAY);
|
||||||
}
|
}
|
||||||
c = buff[idx];
|
c = buff[idx];
|
||||||
idx++;
|
idx++;
|
||||||
idx %= 32;
|
idx %= 32;
|
||||||
}
|
} while ((uint8_t)c != 0xFF);
|
||||||
while ((uint8_t) c != 0xFF);
|
|
||||||
|
|
||||||
pinMode(2, INPUT);
|
pinMode(2, INPUT);
|
||||||
attachInterrupt(digitalPinToInterrupt(2), ppsHandler, RISING);
|
attachInterrupt(digitalPinToInterrupt(2), ppsHandler, RISING);
|
||||||
|
|
Ładowanie…
Reference in New Issue