Skip to content

Commit 39e82b8

Browse files
committed
Merge branch 'devel'
Conflicts: ReleaseNote.txt common/utils/AVRString.h common/utils/SoftSerial.h
2 parents efbbca8 + 2ac6757 commit 39e82b8

File tree

16 files changed

+391
-224
lines changed

16 files changed

+391
-224
lines changed

ReleaseNote.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
RelNote -*- mode : org -*-
2+
13
# Release Note
24
* DONE v1.0.0 - all-C projects
35
** I2C console via serial port: make I2C debugging easier
@@ -11,14 +13,24 @@
1113
** DONE Support Arduino IDE framework (Arduino Makefile)
1214
** DONE skeleton.mk is one-stop .mk for all projects, include it at the end of project's makefile
1315
** DONE create libutils.a
14-
** INPROGRESS v2.0.1 - migrate SerialDebugPrint api to non-macro, restructure i2c-console parser
15-
*** TODO change SerialDebugPrint* api & test src
16-
*** WAIT move i2c-console parser to module & callback management
17-
*** WAIT GPS breakout board to output to softserial
16+
** DONE v2.0.1 - migrate SerialDebugPrint api to non-macro, restructure i2c-console parser
17+
- State "DONE" from "INPROGRESS" [2017-06-11 Sun 23:01]
18+
*** DONE change SerialDebugPrint* api & test src
19+
SCHEDULED: <2017-06-10 Sat>
20+
- State "DONE" from "INPROGRESS" [2017-06-10 Sat 17:10]
21+
*** DONE move i2c-console parser to module & callback management
22+
- State "DONE" from "INPROGRESS" [2017-06-10 Sat 21:02]
23+
*** DONE GPS breakout board to output to softserial
24+
- State "DONE" from "INPROGRESS" [2017-06-11 Sun 22:54]
1825

1926
* WAIT v2.1.0 - Google test support & C sensor library support
2027
** add common/makefiles/gtest.mk
2128
*** add simple gtest project
29+
** full range adc & pin change interrupt C support
2230
** motion sensor test code
2331
** hand clap sound detector
24-
** full range adc & pin change interrupt C support
32+
* WAIT v2.2.0 - more integrated module in i2c-console
33+
** LSM303DLHC support: compass & accelerator in test/
34+
*** accelerometer support
35+
*** compass support
36+
*** i2c-console support

c-project/without-os/GPS-breakout-board/GPS-test.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "NMEAParser.h"
99
#include "SerialDebug.h"
10+
#include "SoftSerial.h"
1011
#include "LCD.h"
1112

1213
#include <util/delay.h>
@@ -16,6 +17,7 @@ int main(void)
1617
{
1718
LCDInit();
1819
SerialDebugInitWithBaudRate(9600);
20+
SoftSerialInit();
1921
double distance = 0.0f;
2022
NMEAData initLocation, prevData;
2123
initLocation.isValid = 0;
@@ -32,7 +34,7 @@ int main(void)
3234

3335
if (!initLocation.isValid)
3436
{
35-
SerialDebugPrint("Failed initial parsed message: %s", gps_msg);
37+
SoftSerialPrintLn("Failed initial parsed message: %s", gps_msg);
3638
}
3739
}
3840

@@ -50,22 +52,22 @@ int main(void)
5052

5153
if (gpsData.isValid && parseResult == 0)
5254
{
53-
SerialDebugPrint("Parse succeeds, message %s", gps_msg);
54-
SerialDebugPrint("lat %d %lf", gpsData.location.lat_deg,
55+
SoftSerialPrintLn("Parse succeeds, message %s", gps_msg);
56+
SoftSerialPrintLn("lat %d %lf", gpsData.location.lat_deg,
5557
gpsData.location.lat_min);
56-
SerialDebugPrint("lon %d %lf", gpsData.location.lon_deg,
58+
SoftSerialPrintLn("lon %d %lf", gpsData.location.lon_deg,
5759
gpsData.location.lon_min);
5860

5961
distance += NMEAGetDistance(&prevData.location, &gpsData.location);
60-
SerialDebugPrint("traveled distance %.2lf m", distance);
62+
SoftSerialPrintLn("traveled distance %.2lf m", distance);
6163

6264
double angle = NMEAGetAngle(&initLocation.location, &gpsData.location);
63-
SerialDebugPrint("angle from initial location %.2lf degrees", angle);
65+
SoftSerialPrintLn("angle from initial location %.2lf degrees", angle);
6466

6567
double distanceToInitPlace = NMEAGetDistance(&initLocation.location, &gpsData.location);
66-
SerialDebugPrint(" %4.0lf m to initial place", distanceToInitPlace);
68+
SoftSerialPrintLn(" %4.0lf m to initial place", distanceToInitPlace);
6769

68-
SerialDebugPrint(" ");
70+
SoftSerialPrintLn(" ");
6971

7072
LCDSetCursor(1,0);
7173
LCDPrint("traveled %.2lf m", distance);

c-project/without-os/GPS-breakout-board/NMEAParser.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ double NMEAGetAngle(const NMEALocation * a, const NMEALocation * b)
418418
double latb = toRadian(b->lat_deg, b->lat_min);
419419
double lonb = toRadian(b->lon_deg, b->lon_min);
420420

421-
double dlat = (latb - lata);
422421
double dlon = (lonb - lona);
423422

424423
double y = sin(dlon) * cos(latb);

c-project/without-os/i2c-console/I2CConsole.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ typedef enum _i2ccommand
1717
SEND = 0,
1818
SENDNRECV,
1919
SET_ADDRESS,
20-
SET_SLOW
20+
SET_SLOW,
21+
PING
2122
} I2CConsoleCommand;
2223

2324
typedef struct _i2cMessage
@@ -44,6 +45,7 @@ typedef struct _i2cMessage
4445
* LOOP 3 TX "hello world" - loop in 3 seconds for sending TX "hello world"
4546
* LOOP 5 RX 6 2 ab 03 - loop in 5 seconds for sending RX 6 2 ab 03
4647
* SLOW 0 - set slow sending off
48+
* PING 23 - check if address 0x23 is alive
4749
*
4850
* @param inputmessage
4951
* @param result
@@ -62,6 +64,7 @@ uint8_t I2CConsoleParser(const char * message, I2CConsoleMessage * result);
6264
* - 1 on failed sending/recv
6365
* - 2 on invalid message
6466
* - 3 on invalid address
67+
* - 4 on timeout of ping
6568
*/
6669
uint8_t I2CConsoleSendCommand(I2CConsoleMessage * command);
6770

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* I2CConsole.c
3+
*
4+
* Created on: May 29, 2017
5+
* Author: dat
6+
*/
7+
8+
#include "I2CConsole.h"
9+
10+
#include <util/delay.h>
11+
#include <stdio.h>
12+
#include <string.h>
13+
14+
#include "SerialDebug.h"
15+
#include "I2C.h"
16+
17+
static uint8_t _i2c_address;
18+
static uint8_t _i2c_slowTx;
19+
20+
static void consoleInit()
21+
{
22+
static uint8_t isInited = 0;
23+
if (!isInited)
24+
{
25+
I2CInit();
26+
isInited = 1;
27+
}
28+
}
29+
30+
uint8_t I2CConsoleSendCommand(I2CConsoleMessage * command)
31+
{
32+
consoleInit();
33+
34+
uint8_t retVal = (command->isValid) ? 0 : 2;
35+
36+
if (!retVal)
37+
{
38+
uint8_t data[I2CMESSAGE_MAXLEN]; // for converting to uint8_t array
39+
40+
if (command->command == SET_ADDRESS)
41+
{
42+
_i2c_address = (uint8_t) command->address;
43+
}
44+
else if (command->command == PING)
45+
{
46+
// don't change command address if it's PING
47+
;
48+
}
49+
else
50+
{
51+
command->address = _i2c_address;
52+
int i;
53+
54+
if (command->tx_len)
55+
{
56+
for (i = 0; i < command->tx_len; ++i)
57+
{
58+
data[i] = command->tx[i];
59+
}
60+
}
61+
else if (command->message)
62+
{
63+
for (i = 0; i < (int) strlen(command->message); ++i)
64+
{
65+
data[i] = command->message[i];
66+
}
67+
}
68+
}
69+
70+
if (command->command == SET_SLOW)
71+
{
72+
_i2c_slowTx = (command->isDelayBetweenBytes) ? 1 : 0;
73+
}
74+
else
75+
{
76+
command->isDelayBetweenBytes = _i2c_slowTx;
77+
}
78+
79+
if (command->address != 0x00)
80+
{
81+
if (command->command == SEND)
82+
{
83+
if (command->tx_len)
84+
{
85+
retVal += I2CSendData(_i2c_address, data, command->tx_len,
86+
_i2c_slowTx);
87+
}
88+
89+
else if (command->message)
90+
{
91+
retVal += I2CSendData(_i2c_address, data,
92+
strlen(command->message), _i2c_slowTx);
93+
}
94+
}
95+
else if (command->command == SENDNRECV)
96+
{
97+
98+
if (command->tx_len)
99+
{
100+
retVal += I2CSendnRecvData(_i2c_address, data,
101+
command->tx_len, command->rx, command->rx_len,
102+
_i2c_slowTx);
103+
}
104+
105+
else if (command->message)
106+
{
107+
retVal += I2CSendnRecvData(_i2c_address, data,
108+
strlen(command->message), command->rx,
109+
command->rx_len, _i2c_slowTx);
110+
}
111+
}
112+
else if (command->command == PING)
113+
{
114+
retVal = (I2CCheckAlive(command->address) == 0) ? retVal : 4;
115+
TRACE_INT(retVal);
116+
LOG("address %x", command->address);
117+
}
118+
}
119+
else
120+
{
121+
retVal = 3;
122+
}
123+
}
124+
125+
if (!retVal)
126+
_delay_ms(150);
127+
128+
return retVal;
129+
}
130+
131+
uint8_t I2CConsoleGetCurrentAddress()
132+
{
133+
consoleInit();
134+
return _i2c_address;
135+
}
136+
137+
uint8_t I2CConsoleGetSlowSendingStatus()
138+
{
139+
consoleInit();
140+
return _i2c_slowTx;
141+
}

0 commit comments

Comments
 (0)