Permalink
Browse files

Add clang auto-formatter config file

  • Loading branch information...
monkbroc committed Mar 21, 2016
1 parent bf464cf commit 9c527710af59f56be0c6b7a061e05306d71fe41c
Showing with 192 additions and 231 deletions.
  1. +57 −0 .clang-format
  2. +61 −68 firmware/TinyGPS++.cpp
  3. +54 −144 firmware/TinyGPS++.h
  4. +17 −17 firmware/carloop.cpp
  5. +3 −2 firmware/carloop.h
@@ -0,0 +1,57 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Allman
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: Never
DisableFormat: false
...
129 firmware/TinyGPS++.cpp 100755 → 100644
@@ -1,6 +1,7 @@
/*
TinyGPS++ - a small GPS library for Arduino providing universal NMEA parsing
Based on work by and "distanceBetween" and "courseTo" courtesy of Maarten Lamers.
Based on work by and "distanceBetween" and "courseTo" courtesy of Maarten
Lamers.
Suggestion to add satellites, courseTo(), and cardinal() by Matt Monson.
Location precision improvements suggested by Wayne Holder.
Copyright (C) 2008-2013 Mikal Hart
@@ -28,31 +29,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <ctype.h>
#include <stdlib.h>
#define _GPRMCterm "GPRMC"
#define _GPGGAterm "GPGGA"
#define _GPRMCterm "GPRMC"
#define _GPGGAterm "GPGGA"
// Converts degrees to radians.
#define radians(angleDegrees) ((angleDegrees) * M_PI / 180.0)
#define radians(angleDegrees) ((angleDegrees)*M_PI / 180.0)
// Converts radians to degrees.
#define degrees(angleRadians) ((angleRadians) * 180.0 / M_PI)
#define degrees(angleRadians) ((angleRadians)*180.0 / M_PI)
#define TWO_PI 6.283185307179586476925286766559
#define sq(x) ((x)*(x))
#define sq(x) ((x) * (x))
TinyGPSPlus::TinyGPSPlus()
: parity(0)
, isChecksumTerm(false)
, curSentenceType(GPS_SENTENCE_OTHER)
, curTermNumber(0)
, curTermOffset(0)
, sentenceHasFix(false)
, customElts(0)
, customCandidates(0)
, encodedCharCount(0)
, sentencesWithFixCount(0)
, failedChecksumCount(0)
, passedChecksumCount(0)
: parity(0), isChecksumTerm(false), curSentenceType(GPS_SENTENCE_OTHER), curTermNumber(0),
curTermOffset(0), sentenceHasFix(false), customElts(0), customCandidates(0),
encodedCharCount(0), sentencesWithFixCount(0), failedChecksumCount(0), passedChecksumCount(0)
{
term[0] = '\0';
}
@@ -74,7 +66,7 @@ bool TinyGPSPlus::encode(char c)
case '*':
{
bool isValidSentence = false;
if (curTermOffset < sizeof(term))
if(curTermOffset < sizeof(term))
{
term[curTermOffset] = 0;
isValidSentence = endOfTermHandler();
@@ -95,9 +87,9 @@ bool TinyGPSPlus::encode(char c)
return false;
default: // ordinary characters
if (curTermOffset < sizeof(term) - 1)
if(curTermOffset < sizeof(term) - 1)
term[curTermOffset++] = c;
if (!isChecksumTerm)
if(!isChecksumTerm)
parity ^= c;
return false;
}
@@ -110,9 +102,9 @@ bool TinyGPSPlus::encode(char c)
//
int TinyGPSPlus::fromHex(char a)
{
if (a >= 'A' && a <= 'F')
if(a >= 'A' && a <= 'F')
return a - 'A' + 10;
else if (a >= 'a' && a <= 'f')
else if(a >= 'a' && a <= 'f')
return a - 'a' + 10;
else
return a - '0';
@@ -123,13 +115,15 @@ int TinyGPSPlus::fromHex(char a)
int32_t TinyGPSPlus::parseDecimal(const char *term)
{
bool negative = *term == '-';
if (negative) ++term;
if(negative)
++term;
int32_t ret = 100 * (int32_t)atol(term);
while (isdigit(*term)) ++term;
if (*term == '.' && isdigit(term[1]))
while(isdigit(*term))
++term;
if(*term == '.' && isdigit(term[1]))
{
ret += 10 * (term[1] - '0');
if (isdigit(term[2]))
if(isdigit(term[2]))
ret += term[2] - '0';
}
return negative ? -ret : ret;
@@ -146,11 +140,11 @@ void TinyGPSPlus::parseDegrees(const char *term, RawDegrees &deg)
deg.deg = (int16_t)(leftOfDecimal / 100);
while (isdigit(*term))
while(isdigit(*term))
++term;
if (*term == '.')
while (isdigit(*++term))
if(*term == '.')
while(isdigit(*++term))
{
multiplier /= 10;
tenMillionthsOfMinutes += (*term - '0') * multiplier;
@@ -167,21 +161,21 @@ void TinyGPSPlus::parseDegrees(const char *term, RawDegrees &deg)
bool TinyGPSPlus::endOfTermHandler()
{
// If it's the checksum term, and the checksum checks out, commit
if (isChecksumTerm)
if(isChecksumTerm)
{
byte checksum = 16 * fromHex(term[0]) + fromHex(term[1]);
if (checksum == parity)
if(checksum == parity)
{
passedChecksumCount++;
if (sentenceHasFix)
if(sentenceHasFix)
++sentencesWithFixCount;
switch(curSentenceType)
{
case GPS_SENTENCE_GPRMC:
date.commit();
time.commit();
if (sentenceHasFix)
if(sentenceHasFix)
{
location.commit();
speed.commit();
@@ -190,7 +184,7 @@ bool TinyGPSPlus::endOfTermHandler()
break;
case GPS_SENTENCE_GPGGA:
time.commit();
if (sentenceHasFix)
if(sentenceHasFix)
{
location.commit();
altitude.commit();
@@ -201,7 +195,9 @@ bool TinyGPSPlus::endOfTermHandler()
}
// Commit all custom listeners of this sentence type
for (TinyGPSCustom *p = customCandidates; p != NULL && strcmp(p->sentenceName, customCandidates->sentenceName) == 0; p = p->next)
for(TinyGPSCustom *p = customCandidates;
p != NULL && strcmp(p->sentenceName, customCandidates->sentenceName) == 0;
p = p->next)
p->commit();
return true;
}
@@ -215,24 +211,27 @@ bool TinyGPSPlus::endOfTermHandler()
}
// the first term determines the sentence type
if (curTermNumber == 0)
if(curTermNumber == 0)
{
if (!strcmp(term, _GPRMCterm))
if(!strcmp(term, _GPRMCterm))
curSentenceType = GPS_SENTENCE_GPRMC;
else if (!strcmp(term, _GPGGAterm))
else if(!strcmp(term, _GPGGAterm))
curSentenceType = GPS_SENTENCE_GPGGA;
else
curSentenceType = GPS_SENTENCE_OTHER;
// Any custom candidates of this sentence type?
for (customCandidates = customElts; customCandidates != NULL && strcmp(customCandidates->sentenceName, term) < 0; customCandidates = customCandidates->next);
if (customCandidates != NULL && strcmp(customCandidates->sentenceName, term) > 0)
for(customCandidates = customElts;
customCandidates != NULL && strcmp(customCandidates->sentenceName, term) < 0;
customCandidates = customCandidates->next)
;
if(customCandidates != NULL && strcmp(customCandidates->sentenceName, term) > 0)
customCandidates = NULL;
return false;
}
if (curSentenceType != GPS_SENTENCE_OTHER && term[0])
if(curSentenceType != GPS_SENTENCE_OTHER && term[0])
switch(COMBINE(curSentenceType, curTermNumber))
{
case COMBINE(GPS_SENTENCE_GPRMC, 1): // Time in both sentences
@@ -282,8 +281,11 @@ bool TinyGPSPlus::endOfTermHandler()
}
// Set custom values as needed
for (TinyGPSCustom *p = customCandidates; p != NULL && strcmp(p->sentenceName, customCandidates->sentenceName) == 0 && p->termNumber <= curTermNumber; p = p->next)
if (p->termNumber == curTermNumber)
for(TinyGPSCustom *p = customCandidates;
p != NULL && strcmp(p->sentenceName, customCandidates->sentenceName) == 0 &&
p->termNumber <= curTermNumber;
p = p->next)
if(p->termNumber == curTermNumber)
p->set(term);
return false;
@@ -297,7 +299,7 @@ double TinyGPSPlus::distanceBetween(double lat1, double long1, double lat2, doub
// distance computation for hypothetical sphere of radius 6372795 meters.
// Because Earth is no exact sphere, rounding errors may be up to 0.5%.
// Courtesy of Maarten Lamers
double delta = radians(long1-long2);
double delta = radians(long1 - long2);
double sdlong = sin(delta);
double cdlong = cos(delta);
lat1 = radians(lat1);
@@ -317,18 +319,20 @@ double TinyGPSPlus::distanceBetween(double lat1, double long1, double lat2, doub
double TinyGPSPlus::courseTo(double lat1, double long1, double lat2, double long2)
{
// returns course in degrees (North=0, West=270) from position 1 to position 2,
// returns course in degrees (North=0, West=270) from position 1 to position
// 2,
// both specified as signed decimal-degrees latitude and longitude.
// Because Earth is no exact sphere, calculated course may be off by a tiny fraction.
// Because Earth is no exact sphere, calculated course may be off by a tiny
// fraction.
// Courtesy of Maarten Lamers
double dlon = radians(long2-long1);
double dlon = radians(long2 - long1);
lat1 = radians(lat1);
lat2 = radians(lat2);
double a1 = sin(dlon) * cos(lat2);
double a2 = sin(lat1) * cos(lat2) * cos(dlon);
a2 = cos(lat1) * sin(lat2) - a2;
a2 = atan2(a1, a2);
if (a2 < 0.0)
if(a2 < 0.0)
{
a2 += TWO_PI;
}
@@ -337,7 +341,8 @@ double TinyGPSPlus::courseTo(double lat1, double long1, double lat2, double long
const char *TinyGPSPlus::cardinal(double course)
{
static const char* directions[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};
static const char *directions[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"};
int direction = (int)((course + 11.25f) / 22.5f);
return directions[direction % 16];
}
@@ -388,15 +393,9 @@ void TinyGPSTime::commit()
valid = updated = true;
}
void TinyGPSTime::setTime(const char *term)
{
newTime = (uint32_t)TinyGPSPlus::parseDecimal(term);
}
void TinyGPSTime::setTime(const char *term) { newTime = (uint32_t)TinyGPSPlus::parseDecimal(term); }
void TinyGPSDate::setDate(const char *term)
{
newDate = atol(term);
}
void TinyGPSDate::setDate(const char *term) { newDate = atol(term); }
uint16_t TinyGPSDate::year()
{
@@ -448,10 +447,7 @@ void TinyGPSDecimal::commit()
valid = updated = true;
}
void TinyGPSDecimal::set(const char *term)
{
newval = TinyGPSPlus::parseDecimal(term);
}
void TinyGPSDecimal::set(const char *term) { newval = TinyGPSPlus::parseDecimal(term); }
void TinyGPSInteger::commit()
{
@@ -460,10 +456,7 @@ void TinyGPSInteger::commit()
valid = updated = true;
}
void TinyGPSInteger::set(const char *term)
{
newval = atol(term);
}
void TinyGPSInteger::set(const char *term) { newval = atol(term); }
TinyGPSCustom::TinyGPSCustom(TinyGPSPlus &gps, const char *_sentenceName, int _termNumber)
{
@@ -499,10 +492,10 @@ void TinyGPSPlus::insertCustom(TinyGPSCustom *pElt, const char *sentenceName, in
{
TinyGPSCustom **ppelt;
for (ppelt = &this->customElts; *ppelt != NULL; ppelt = &(*ppelt)->next)
for(ppelt = &this->customElts; *ppelt != NULL; ppelt = &(*ppelt)->next)
{
int cmp = strcmp(sentenceName, (*ppelt)->sentenceName);
if (cmp < 0 || (cmp == 0 && termNumber < (*ppelt)->termNumber))
if(cmp < 0 || (cmp == 0 && termNumber < (*ppelt)->termNumber))
break;
}
Oops, something went wrong.

0 comments on commit 9c52771

Please sign in to comment.