77#include "I2CConsole.h"
88#include "SerialDebug.h"
99#include "PgmStorage.h"
10- #include "Timer.h"
11- #include "I2C.h"
1210#include "Millis.h"
1311
1412#include <stdio.h>
1513#include <util/delay.h>
1614
17-
18- const char PROGMEM helpaddr1 [] = "Hint address: LCD 0x28, compass 0x19" ;
1915const char PROGMEM help1 [] = "Sample command \t\t - explanation (command case insensitive)" ;
2016const char PROGMEM help2 [] = "ADDR 28 \t\t - set i2c 7-bit address as 0x28" ;
2117const char PROGMEM help3 [] = "TX 2 00 03 \t\t - send 2 bytes 0x00 and 0x03" ;
2218const char PROGMEM help0 [] = "TX \"hello world\" \t - send string \"hello world\"" ;
2319const char PROGMEM help4 [] = "RX 6 2 ab 03 \t\t - send 2 bytes 0xab and 0x03, receive 6 bytes back to rx" ;
2420const char PROGMEM help41 [] = "SLOW 0 \t\t\t - set slow sending off" ;
21+ const char PROGMEM help42 [] = "PING 23 \t\t - check if address 0x23 is alive" ;
2522const char PROGMEM helploop1 [] = "LOOP 2 TX 2 00 03 \t - loop the command 'TX 2 00 03' for 2 seconds" ;
2623const char PROGMEM helploop2 [] = "LOOP 5 RX 6 1 ab \t - loop the command 'RX 6 1 ab' for 5 seconds" ;
2724const char PROGMEM help5 [] = "---------------" ;
@@ -38,9 +35,6 @@ void showHelp()
3835{
3936 char msg [PGM_SIZE ];
4037
41- PgmStorageGet (msg , helpaddr1 );
42- SerialDebugPrint (msg );
43-
4438 PgmStorageGet (msg , help1 );
4539 SerialDebugPrint (msg );
4640
@@ -59,6 +53,9 @@ void showHelp()
5953 PgmStorageGet (msg , help41 );
6054 SerialDebugPrint (msg );
6155
56+ PgmStorageGet (msg , help42 );
57+ SerialDebugPrint (msg );
58+
6259 PgmStorageGet (msg , helploop1 );
6360 SerialDebugPrint (msg );
6461
@@ -187,15 +184,38 @@ void showHistory()
187184void runScan ()
188185{
189186 uint8_t device_addr ;
187+ I2CConsoleMessage msg ;
188+ char foundDevice = 0 ;
190189
191190 SerialDebugPrint ("Scanning for devices ..." );
192191 for (device_addr = 0 ; device_addr < 128 ; ++ device_addr )
193192 {
194- if (!I2CCheckAlive (device_addr ))
193+ char buff [20 ];
194+ snprintf (buff , 20 , "ping %x" , device_addr );
195+
196+ if (!I2CConsoleParser (buff , & msg ))
195197 {
196- SerialDebugPrint ("Found device 0x%x" , device_addr );
198+ uint8_t sendResult = I2CConsoleSendCommand (& msg );
199+ if (!sendResult )
200+ {
201+ SerialDebugPrint ("Found device 0x%x" , device_addr );
202+ foundDevice = 1 ;
203+ }
204+ else
205+ {
206+ LOG ("Error code %d for %s" , sendResult , buff );
207+ }
208+ }
209+ else
210+ {
211+ LOG ("Error parsing %s" , buff );
197212 }
198213 }
214+
215+ if (!foundDevice )
216+ {
217+ SerialDebugPrint ("No I2C device found" );
218+ }
199219}
200220
201221void parseNRunMessage (const char * message )
@@ -220,14 +240,14 @@ void parseNRunMessage(const char * message)
220240 uint8_t sendResult = I2CConsoleSendCommand (& cmd );
221241 if (sendResult == 0 )
222242 {
223- SerialDebugPrint ("sent %s " , message );
243+ SerialDebugPrint ("OK - '%s' " , message );
224244
225245 if (cmd .command == SENDNRECV )
226246 {
227247 SerialDebugPrint ("RX result:" );
228248 for (i = 0 ; i < cmd .rx_len ; ++ i )
229249 {
230- SerialDebugPrint (" rx[%d] = 0x%x = %d = '%c'" , i , cmd .rx [i ],
250+ SerialDebugPrint (" rx[%d] = 0x%x \t = %d \t = '%c'" , i , cmd .rx [i ],
231251 cmd .rx [i ], cmd .rx [i ]);
232252 }
233253 }
0 commit comments