Fabio Fumi
/
send_to_sharp
Renamed
main.cpp@5:062962db7a48, 2022-03-29 (annotated)
- Committer:
- ffxx68
- Date:
- Tue Mar 29 10:06:20 2022 +0000
- Revision:
- 5:062962db7a48
- Parent:
- 3:6237f9e5e798
Receiving the file through serial port
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ffxx68 | 5:062962db7a48 | 1 | /******************************************** |
ffxx68 | 5:062962db7a48 | 2 | Send File to Sharp PC-1403(H) |
ffxx68 | 5:062962db7a48 | 3 | ========================================== |
ffxx68 | 5:062962db7a48 | 4 | |
ffxx68 | 5:062962db7a48 | 5 | Author: Fabio Fumi |
ffxx68 | 5:062962db7a48 | 6 | Date: 04.03.2022 |
ffxx68 | 5:062962db7a48 | 7 | |
ffxx68 | 5:062962db7a48 | 8 | This software comes with the GNU public licence (GPL). |
ffxx68 | 5:062962db7a48 | 9 | |
ffxx68 | 5:062962db7a48 | 10 | It is an adaptation to the Mbed OS of the |
ffxx68 | 5:062962db7a48 | 11 | img2wav from the "Pocket Tools" suite |
ffxx68 | 5:062962db7a48 | 12 | https://www.peil-partner.de/ifhe.de/sharp/ |
ffxx68 | 5:062962db7a48 | 13 | *********************************************/ |
ffxx68 | 0:07819bc70660 | 14 | #include "mbed.h" |
ffxx68 | 0:07819bc70660 | 15 | #include "send_pc1403.h" |
ffxx68 | 5:062962db7a48 | 16 | //#ifdef FILE_BUF_SIZE |
ffxx68 | 5:062962db7a48 | 17 | //volatile char debugOut[1024]; |
ffxx68 | 5:062962db7a48 | 18 | //#endif |
ffxx68 | 5:062962db7a48 | 19 | RawSerial pc(USBTX,USBRX); // better than Serial, when using interrupts |
ffxx68 | 5:062962db7a48 | 20 | DigitalOut my_led(LED1); |
ffxx68 | 5:062962db7a48 | 21 | DigitalIn my_button(USER_BUTTON); |
ffxx68 | 5:062962db7a48 | 22 | InterruptIn btn(USER_BUTTON); |
ffxx68 | 5:062962db7a48 | 23 | Timer total_time; |
ffxx68 | 5:062962db7a48 | 24 | Ticker blink; |
ffxx68 | 5:062962db7a48 | 25 | |
ffxx68 | 5:062962db7a48 | 26 | // bin-to-wav conversion information (from Pocket Tools code) |
ffxx68 | 5:062962db7a48 | 27 | int send_err; |
ffxx68 | 5:062962db7a48 | 28 | |
ffxx68 | 5:062962db7a48 | 29 | void ledBlink () { |
ffxx68 | 5:062962db7a48 | 30 | my_led = !my_led; |
ffxx68 | 5:062962db7a48 | 31 | } |
ffxx68 | 0:07819bc70660 | 32 | |
ffxx68 | 5:062962db7a48 | 33 | #ifdef FILE_BUF_SIZE |
ffxx68 | 5:062962db7a48 | 34 | void printInfo() |
ffxx68 | 5:062962db7a48 | 35 | { |
ffxx68 | 5:062962db7a48 | 36 | int i ; |
ffxx68 | 5:062962db7a48 | 37 | // printout info |
ffxx68 | 5:062962db7a48 | 38 | pc.printf("totBytesReceived %d\n\r", totBytesReceived); |
ffxx68 | 5:062962db7a48 | 39 | pc.printf("fileBufReceivePtr %d\n\r", fileBufReceivePtr); |
ffxx68 | 5:062962db7a48 | 40 | for ( i=0; i<10; i++ ) |
ffxx68 | 5:062962db7a48 | 41 | pc.printf("0x%.2X ", fileOverSerialBuffer[i] ); |
ffxx68 | 5:062962db7a48 | 42 | pc.printf("...\n\r"); |
ffxx68 | 5:062962db7a48 | 43 | pc.printf("fileBufSendPtr %d\n\r", fileBufSendPtr); |
ffxx68 | 5:062962db7a48 | 44 | //pc.printf("<%s>\n\r", debugOut); |
ffxx68 | 5:062962db7a48 | 45 | pc.printf("fileReceiveComplete %d\n\r", fileReceiveComplete); |
ffxx68 | 5:062962db7a48 | 46 | pc.printf("fileError %d\n\r", fileError); |
ffxx68 | 5:062962db7a48 | 47 | pc.printf("fileInfo.total %d\n\r", fileInfo.total); |
ffxx68 | 5:062962db7a48 | 48 | pc.printf("time (ms): %d [send_err %d]\n\r", total_time.read_us()/1000, send_err); |
ffxx68 | 5:062962db7a48 | 49 | |
ffxx68 | 5:062962db7a48 | 50 | } |
ffxx68 | 1:9289febf4ae9 | 51 | |
ffxx68 | 5:062962db7a48 | 52 | // invoked at each character received over serial |
ffxx68 | 5:062962db7a48 | 53 | void serial_rx() { |
ffxx68 | 5:062962db7a48 | 54 | |
ffxx68 | 5:062962db7a48 | 55 | // getting data from serial |
ffxx68 | 5:062962db7a48 | 56 | if ( totBytesReceived == 0 ) { |
ffxx68 | 5:062962db7a48 | 57 | timeout.start(); // new file: enable a watchdog |
ffxx68 | 5:062962db7a48 | 58 | timeout.reset(); |
ffxx68 | 5:062962db7a48 | 59 | blink.attach( &ledBlink, 0.05 ); // fast blink: receiving |
ffxx68 | 5:062962db7a48 | 60 | } |
ffxx68 | 5:062962db7a48 | 61 | // push character on the circular buffer |
ffxx68 | 5:062962db7a48 | 62 | filePushData ( pc.getc() ); |
ffxx68 | 5:062962db7a48 | 63 | totBytesReceived++; |
ffxx68 | 5:062962db7a48 | 64 | timeout.reset(); |
ffxx68 | 3:6237f9e5e798 | 65 | |
ffxx68 | 5:062962db7a48 | 66 | } |
ffxx68 | 5:062962db7a48 | 67 | #endif |
ffxx68 | 3:6237f9e5e798 | 68 | |
ffxx68 | 5:062962db7a48 | 69 | |
ffxx68 | 0:07819bc70660 | 70 | int main() |
ffxx68 | 0:07819bc70660 | 71 | { |
ffxx68 | 5:062962db7a48 | 72 | |
ffxx68 | 5:062962db7a48 | 73 | my_led = 0; |
ffxx68 | 5:062962db7a48 | 74 | pc.baud(600); // file-over-serial can't go faster (sending to Sharp is about 500baud) |
ffxx68 | 0:07819bc70660 | 75 | fflush(stdout); |
ffxx68 | 5:062962db7a48 | 76 | #ifdef FILE_BUF_SIZE |
ffxx68 | 5:062962db7a48 | 77 | btn.rise(&printInfo); |
ffxx68 | 5:062962db7a48 | 78 | pc.attach(&serial_rx, Serial::RxIrq); |
ffxx68 | 5:062962db7a48 | 79 | fileReceiveInit( ); |
ffxx68 | 5:062962db7a48 | 80 | #endif |
ffxx68 | 0:07819bc70660 | 81 | // main loop |
ffxx68 | 0:07819bc70660 | 82 | while(true) { |
ffxx68 | 5:062962db7a48 | 83 | |
ffxx68 | 5:062962db7a48 | 84 | blink.attach( &ledBlink, 1.0 ); // slow blink - waiting for file |
ffxx68 | 5:062962db7a48 | 85 | |
ffxx68 | 5:062962db7a48 | 86 | #ifdef FILE_BUF_SIZE |
ffxx68 | 5:062962db7a48 | 87 | // File-over-serial |
ffxx68 | 5:062962db7a48 | 88 | // serial interrupt - pushing to buffer |
ffxx68 | 5:062962db7a48 | 89 | // main thread - pulling from buffer |
ffxx68 | 5:062962db7a48 | 90 | fileInfo.debug = 0x1000; // disable verbose printf while using serial |
ffxx68 | 5:062962db7a48 | 91 | fileReceiveInit( ); |
ffxx68 | 5:062962db7a48 | 92 | // wait for data available, before starting to send |
ffxx68 | 5:062962db7a48 | 93 | while ( !totBytesReceived ) |
ffxx68 | 5:062962db7a48 | 94 | wait (.1); |
ffxx68 | 5:062962db7a48 | 95 | #else |
ffxx68 | 5:062962db7a48 | 96 | // hardcoded BIN file |
ffxx68 | 5:062962db7a48 | 97 | pc.printf("Push user button to start sending \n\r"); |
ffxx68 | 5:062962db7a48 | 98 | // wait for button pressed, only for the hardcoded BIN file |
ffxx68 | 1:9289febf4ae9 | 99 | while ( my_button == 1 ) |
ffxx68 | 1:9289febf4ae9 | 100 | wait ( .1 ); |
ffxx68 | 5:062962db7a48 | 101 | #endif |
ffxx68 | 0:07819bc70660 | 102 | |
ffxx68 | 5:062962db7a48 | 103 | // start sending new file to Sharp |
ffxx68 | 5:062962db7a48 | 104 | fileInfo.ident = IDENT_NEW_BAS; |
ffxx68 | 5:062962db7a48 | 105 | fileInfo.debug = 0x0040; // 0x0000 disable printf; 0x0040 DEBUG |
ffxx68 | 5:062962db7a48 | 106 | bitHandlerInit(); // new bit stream being sent |
ffxx68 | 0:07819bc70660 | 107 | total_time.reset(); |
ffxx68 | 0:07819bc70660 | 108 | total_time.start(); |
ffxx68 | 5:062962db7a48 | 109 | send_err = FileSend ( ) ; // removed for debug ! |
ffxx68 | 5:062962db7a48 | 110 | bitHandlerStop(); // stop bit consumer, after last bit |
ffxx68 | 5:062962db7a48 | 111 | while( bitHandlerRunning() ) // time for bit handler to complete |
ffxx68 | 0:07819bc70660 | 112 | wait (.1); |
ffxx68 | 0:07819bc70660 | 113 | total_time.stop(); |
ffxx68 | 5:062962db7a48 | 114 | #ifdef FILE_BUF_SIZE |
ffxx68 | 5:062962db7a48 | 115 | printInfo() ; |
ffxx68 | 5:062962db7a48 | 116 | #endif |
ffxx68 | 5:062962db7a48 | 117 | pc.printf("DONE - time (ms): %d [send_err %d]\n\r", total_time.read_us()/1000, send_err); |
ffxx68 | 1:9289febf4ae9 | 118 | |
ffxx68 | 1:9289febf4ae9 | 119 | // doing nothing... |
ffxx68 | 5:062962db7a48 | 120 | wait(.1); |
ffxx68 | 5:062962db7a48 | 121 | |
ffxx68 | 0:07819bc70660 | 122 | } |
ffxx68 | 0:07819bc70660 | 123 | } |