Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ika_shouyu_poppoyaki by
command_utilities.cpp
- Committer:
- okano
- Date:
- 2013-09-13
- Revision:
- 21:e149d0bdbf4a
File content as of revision 21:e149d0bdbf4a:
#include "mbed.h"
#include "command_utilities.h"
#include "ika.h"
Serial pc ( USBTX,USBRX );
#if 0
Serial target( p28, p27 );
#else
#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512
#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 512
#include "MODSERIAL.h"
MODSERIAL target( p28, p27 ); //
#endif
void set_target_baud_rate( int baud_rate )
{
target.baud( baud_rate );
}
void usb_serial_bridge_operation( void )
{
while (1) {
if ( pc.readable() ) {
target.putc( pc.getc() );
}
if ( target.readable() ) {
pc.putc( target.getc() );
}
}
}
void put_string( char *s )
{
char c;
static int i = 0;
while ( c = *s++ ) {
target.putc( c );
set_leds( i++ & 0x1 );
}
}
void put_binary( char *b, int size )
{
for ( int i = 0; i < size; i++ )
target.putc( *b++ );
}
Timeout timeout;
int timeout_flag = 0;
void set_flag()
{
timeout_flag = 1;
}
void get_string( char *s )
{
int i = 0;
char c = 0;
timeout_flag = 0;
timeout.attach( &set_flag, 1 );
do {
do {
if ( target.readable() ) {
c = target.getc();
if ( ( c == '\n') || (c == '\r') )
break;
*s++ = c;
i++;
}
if ( timeout_flag )
return;
} while ( 1 );
} while ( !i );
*s = '\0';
}
int get_binary( char *b, int length )
{
int i;
timeout_flag = 0;
timeout.attach( &set_flag, 1 );
for ( i = 0; i < length; i++ ) {
if ( target.readable() )
*b++ = target.getc();
if ( timeout_flag )
return ( i );
}
return ( i );
}
char read_byte( void )
{
while ( !target.readable() )
;
return ( target.getc() );
}
