Skip to content

Commit 2a5d096

Browse files
committed
Atmega 32U4 support
1 parent e5b40f6 commit 2a5d096

File tree

5 files changed

+377
-2
lines changed

5 files changed

+377
-2
lines changed

src/Commander-API.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,48 @@ void Commander::attachDebugChannel( HardwareSerial *resp ){
432432

433433
#endif
434434

435+
#ifdef COMMANDER_USE_ARDUINO_32U4_SERIAL_RESPONSE
436+
437+
void Commander::execute( char *cmd, Serial_ *resp ){
438+
439+
// Arduino Serial execute handler, so the Arduino Serial response will be chosen.
440+
response = &arduino32U4SerialResponse;
441+
442+
// Select the right HardwareSerial object in the response class.
443+
arduino32U4SerialResponse.select( resp );
444+
445+
// Execute the command.
446+
executeCommand( cmd );
447+
448+
}
449+
450+
void Commander::execute( const char *cmd, Serial_ *resp ){
451+
452+
// Arduino Serial execute handler, so the Arduino Serial response will be chosen.
453+
response = &arduino32U4SerialResponse;
454+
455+
// Select the right HardwareSerial object in the response class.
456+
arduino32U4SerialResponse.select( resp );
457+
458+
// Execute the command.
459+
executeCommand( (char*)cmd );
460+
461+
}
462+
463+
void Commander::attachDebugChannel( Serial_ *resp ){
464+
465+
dbgResponse = &arduino32U4SerialResponse;
466+
467+
// Select the right HardwareSerial object in the response class.
468+
arduino32U4SerialResponse.select( resp );
469+
470+
// Enable debug messages.
471+
debugEnabled = true;
472+
473+
}
474+
475+
#endif
476+
435477
#ifdef COMMANDER_USE_WIFI_CLIENT_RESPONSE
436478

437479
void Commander::execute( char *cmd, WiFiClient *resp ){
@@ -578,4 +620,4 @@ void Commander::helpFunction( bool description ){
578620

579621
}
580622

581-
}
623+
}

src/Commander-API.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ class Commander{
214214
void attachDebugChannel( HardwareSerial *resp );
215215
#endif
216216

217+
#ifdef COMMANDER_USE_ARDUINO_32U4_SERIAL_RESPONSE
218+
/// Execution function for Arduino Serial response.
219+
///
220+
/// This function tries to execute a command.
221+
/// It uses the HardwareSerial response channel, so
222+
/// the messages from the command handler
223+
/// will be passed to the selected Serial
224+
/// object.
225+
void execute( char *cmd, Serial_ *resp );
226+
227+
/// Execution function for Arduino Serial response.
228+
///
229+
/// This function tries to execute a command.
230+
/// It uses the HardwareSerial response channel, so
231+
/// the messages from the command handler
232+
/// will be passed to the selected Serial
233+
/// object.
234+
void execute( const char *cmd, Serial_ *resp );
235+
236+
/// Debug channel for Arduino Serial.
237+
///
238+
/// This function attaches a HardwareSerial channel
239+
/// for debug messages. It also enables
240+
/// the debug functionality.
241+
void attachDebugChannel( Serial_ *resp );
242+
#endif
243+
217244
#ifdef COMMANDER_USE_WIFI_CLIENT_RESPONSE
218245
/// Execution function for WiFi Client response.
219246
///
@@ -277,6 +304,11 @@ class Commander{
277304
commandResponseArduinoSerial arduinoSerialResponse;
278305
#endif
279306

307+
#ifdef COMMANDER_USE_ARDUINO_32U4_SERIAL_RESPONSE
308+
/// Serial response handler class.
309+
commandResponseArduino32U4Serial arduino32U4SerialResponse;
310+
#endif
311+
280312
#ifdef COMMANDER_USE_WIFI_CLIENT_RESPONSE
281313
/// WiFi Client response handler class.
282314
commandResponseWiFiClient WiFiClientResponse;

src/Commander-IO.cpp

Lines changed: 240 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,250 @@ size_t commandResponseArduinoSerial::println( double f ){
495495

496496
}
497497

498+
int commandResponseArduinoSerial::printf( const char *fmt, ... ){
498499

500+
char out_buff[ COMMAND_PRINTF_BUFF_LEN ];
499501

502+
va_list args;
500503

504+
va_start( args, fmt );
501505

502-
int commandResponseArduinoSerial::printf( const char *fmt, ... ){
506+
vsnprintf( out_buff, COMMAND_PRINTF_BUFF_LEN, fmt, args );
507+
508+
va_end( args );
509+
510+
if( serialPort ){
511+
512+
return serialPort -> print( out_buff );
513+
514+
}
515+
516+
else{
517+
518+
return -1;
519+
520+
}
521+
522+
}
523+
524+
#endif
525+
526+
#ifdef COMMANDER_USE_ARDUINO_32U4_SERIAL_RESPONSE
527+
528+
//----- Response for Arduino Serial Class -----//
529+
530+
void commandResponseArduino32U4Serial::select( Serial_ *serialPort_p ){
531+
532+
serialPort = serialPort_p;
533+
534+
}
535+
536+
int commandResponseArduino32U4Serial::available(){
537+
538+
if( serialPort ) return serialPort -> available();
539+
return 0;
540+
541+
}
542+
543+
int commandResponseArduino32U4Serial::read(){
544+
545+
if( serialPort ) return serialPort -> read();
546+
return -1;
547+
548+
}
549+
550+
int commandResponseArduino32U4Serial::peek(){
551+
552+
if( serialPort ) return serialPort -> peek();
553+
return -1;
554+
555+
}
556+
557+
size_t commandResponseArduino32U4Serial::readBytes( uint8_t *buff, uint32_t size ){
558+
559+
if( serialPort ) return serialPort -> readBytes( buff, size );
560+
return 0;
561+
562+
}
563+
564+
void commandResponseArduino32U4Serial::flush(){
565+
566+
if( serialPort ) return serialPort -> flush();
567+
568+
}
569+
570+
size_t commandResponseArduino32U4Serial::write( uint8_t b ){
571+
572+
if( serialPort ) return serialPort -> write( b );
573+
return 0;
574+
575+
}
576+
577+
//---- print section ----//
578+
size_t commandResponseArduino32U4Serial::print( char c ){
579+
580+
if( serialPort ) return serialPort -> print( c );
581+
return 0;
582+
583+
}
584+
585+
size_t commandResponseArduino32U4Serial::print( char *str ){
586+
587+
if( serialPort ) return serialPort -> print( str );
588+
return 0;
589+
590+
}
591+
592+
size_t commandResponseArduino32U4Serial::print( const char *str ){
593+
594+
if( serialPort ) return serialPort -> print( str );
595+
return 0;
596+
597+
}
598+
599+
size_t commandResponseArduino32U4Serial::print( int8_t b ){
600+
601+
if( serialPort ) return serialPort -> print( b );
602+
return 0;
603+
604+
}
605+
606+
size_t commandResponseArduino32U4Serial::print( uint8_t b ){
607+
608+
if( serialPort ) return serialPort -> print( b );
609+
return 0;
610+
611+
}
612+
613+
size_t commandResponseArduino32U4Serial::print( int16_t b ){
614+
615+
if( serialPort ) return serialPort -> print( b );
616+
return 0;
617+
618+
}
619+
620+
size_t commandResponseArduino32U4Serial::print( uint16_t b ){
621+
622+
if( serialPort ) return serialPort -> print( b );
623+
return 0;
624+
625+
}
626+
627+
size_t commandResponseArduino32U4Serial::print( int32_t b ){
628+
629+
if( serialPort ) return serialPort -> print( b );
630+
return 0;
631+
632+
}
633+
634+
size_t commandResponseArduino32U4Serial::print( uint32_t b ){
635+
636+
if( serialPort ) return serialPort -> print( b );
637+
return 0;
638+
639+
}
640+
641+
size_t commandResponseArduino32U4Serial::print( float f ){
642+
643+
if( serialPort ) return serialPort -> print( f );
644+
return 0;
645+
646+
}
647+
648+
size_t commandResponseArduino32U4Serial::print( double f ){
649+
650+
if( serialPort ) return serialPort -> print( f );
651+
return 0;
652+
653+
}
654+
655+
//---- println section ----//
656+
657+
size_t commandResponseArduino32U4Serial::println(){
658+
659+
if( serialPort ) return serialPort -> println();
660+
return 0;
661+
662+
}
663+
664+
size_t commandResponseArduino32U4Serial::println( char c ){
665+
666+
if( serialPort ) return serialPort -> println( c );
667+
return 0;
668+
669+
}
670+
671+
size_t commandResponseArduino32U4Serial::println( char *str ){
672+
673+
if( serialPort ) return serialPort -> println( str );
674+
return 0;
675+
676+
}
677+
678+
size_t commandResponseArduino32U4Serial::println( const char *str ){
679+
680+
if( serialPort ) return serialPort -> println( str );
681+
return 0;
682+
683+
}
684+
685+
size_t commandResponseArduino32U4Serial::println( int8_t b ){
686+
687+
if( serialPort ) return serialPort -> println( b );
688+
return 0;
689+
690+
}
691+
692+
size_t commandResponseArduino32U4Serial::println( uint8_t b ){
693+
694+
if( serialPort ) return serialPort -> println( b );
695+
return 0;
696+
697+
}
698+
699+
size_t commandResponseArduino32U4Serial::println( int16_t b ){
700+
701+
if( serialPort ) return serialPort -> println( b );
702+
return 0;
703+
704+
}
705+
706+
size_t commandResponseArduino32U4Serial::println( uint16_t b ){
707+
708+
if( serialPort ) return serialPort -> println( b );
709+
return 0;
710+
711+
}
712+
713+
size_t commandResponseArduino32U4Serial::println( int32_t b ){
714+
715+
if( serialPort ) return serialPort -> println( b );
716+
return 0;
717+
718+
}
719+
720+
size_t commandResponseArduino32U4Serial::println( uint32_t b ){
721+
722+
if( serialPort ) return serialPort -> println( b );
723+
return 0;
724+
725+
}
726+
727+
size_t commandResponseArduino32U4Serial::println( float f ){
728+
729+
if( serialPort ) return serialPort -> println( f );
730+
return 0;
731+
732+
}
733+
734+
size_t commandResponseArduino32U4Serial::println( double f ){
735+
736+
if( serialPort ) return serialPort -> println( f );
737+
return 0;
738+
739+
}
740+
741+
int commandResponseArduino32U4Serial::printf( const char *fmt, ... ){
503742

504743
char out_buff[ COMMAND_PRINTF_BUFF_LEN ];
505744

0 commit comments

Comments
 (0)