2024-04-27 15:24:41 -04:00
/*
* Copyright ( C ) 2015 Jared Boone , ShareBrained Technology , Inc .
* Copyright ( C ) 2017 Furrtek
* Copyleft ( ɔ ) 2024 zxkmm with the GPL license
* Copyright ( C ) 2024 HTotoo
*
* This file is part of PortaPack .
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 , or ( at your option )
* any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; see the file COPYING . If not , write to
* the Free Software Foundation , Inc . , 51 Franklin Street ,
* Boston , MA 02110 - 1301 , USA .
*/
# include "usb_serial_asyncmsg.hpp"
2024-09-29 04:19:29 -04:00
# include "usb_serial.hpp"
2024-04-27 15:24:41 -04:00
/// value
// to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here
// usage: UsbSerialAsyncmsg::asyncmsg(num);
template < >
void UsbSerialAsyncmsg : : asyncmsg < int64_t > ( const int64_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < int32_t > ( const int32_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < int16_t > ( const int16_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < int8_t > ( const int8_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < uint8_t > ( const uint8_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < uint16_t > ( const uint16_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < uint32_t > ( const uint32_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < uint64_t > ( const uint64_t & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_dec_int ( data ) . c_str ( ) ) ;
}
template < >
void UsbSerialAsyncmsg : : asyncmsg < float > ( const float & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , to_string_decimal ( data , 7 ) . c_str ( ) ) ;
}
/// fs things
template < >
// usage: UsbSerialAsyncmsg::asyncmsg(path);
void UsbSerialAsyncmsg : : asyncmsg < std : : filesystem : : path > ( const std : : filesystem : : path & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
std : : string path_str = data . string ( ) ;
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , path_str . c_str ( ) ) ;
}
2024-05-21 06:08:47 -04:00
template < >
void UsbSerialAsyncmsg : : asyncmsg < std : : filesystem : : path : : string_type > ( const std : : filesystem : : path : : string_type & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-05-21 06:08:47 -04:00
return ;
}
std : : string str_data ( data . begin ( ) , data . end ( ) ) ;
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , str_data . c_str ( ) ) ;
}
2024-04-27 15:24:41 -04:00
/// string
// string obj
template < >
// usage: UsbSerialAsyncmsg::asyncmsg(str);
void UsbSerialAsyncmsg : : asyncmsg < std : : string > ( const std : : string & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , data . c_str ( ) ) ;
}
// string literal AKA char[]
// usage: UsbSerialAsyncmsg::asyncmsg("abc");
void UsbSerialAsyncmsg : : asyncmsg ( const char * data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-04-27 15:24:41 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , data ) ;
}
2024-05-08 02:23:47 -04:00
/// bool
template < >
// usage: UsbSerialAsyncmsg::asyncmsg(true);
void UsbSerialAsyncmsg : : asyncmsg < bool > ( const bool & data ) {
2024-09-29 04:19:29 -04:00
if ( ! portapack : : async_tx_enabled | | ! portapack : : usb_serial . serial_connected ( ) ) {
2024-05-08 02:23:47 -04:00
return ;
}
chprintf ( ( BaseSequentialStream * ) & SUSBD1 , " %s \r \n " , data ? " true " : " false " ) ;
2024-09-29 04:19:29 -04:00
}