Aerocraft/src/Main.java
public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                String inputLine = input.readLine();

                if(before == 0){
                    before = System.currentTimeMillis();
                    BPM = 60;
                    System.out.println("start");
                } else {
                    long now = System.currentTimeMillis();
                    nowTime[count] = (int)(now - before);
                    before = now;
                    count++;
                    if (count == 2) count = 0;

                    int sum = 0;
                    for(int i:nowTime){
//                        System.out.println(i);
                        sum = sum + i;
                    }
                    BPM = 60000 / sum * 2;
                    if(isFirst){
                        BPM = BPM / 2;
                        isFirst=false;
                    }
                    System.out.println(BPM);
                }

            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
        // Ignore all the other eventTypes, but you should consider the other ones.
    }
/**
     * Handle an event on the serial port. Read the data and print it.
     */
Handle an event on the serial port. Read the data and print it.
Handle an event on the serial port . Read the data and print it .
public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                String inputLine = input.readLine();
                if(before == 0){
                    before = System.currentTimeMillis();
                    BPM = 60;
                    System.out.println("start");
                } else {
                    long now = System.currentTimeMillis();
                    nowTime[count] = (int)(now - before);
                    before = now;
                    count++;
                    if (count == 2) count = 0;
                    int sum = 0;
                    for(int i:nowTime){
                        sum = sum + i;
                    }
                    BPM = 60000 / sum * 2;
                    if(isFirst){
                        BPM = BPM / 2;
                        isFirst=false;
                    }
                    System.out.println(BPM);
                }
            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
    }
public synchronized void serialEvent ( SerialPortEvent oEvent ) { if ( oEvent . getEventType ( ) == SerialPortEvent . DATA_AVAILABLE ) { try { String inputLine = input . readLine ( ) ; if ( before == 0 ) { before = System . currentTimeMillis ( ) ; BPM = 60 ; System . out . println ( "start" ) ; } else { long now = System . currentTimeMillis ( ) ; nowTime [ count ] = ( int ) ( now - before ) ; before = now ; count ++ ; if ( count == 2 ) count = 0 ; int sum = 0 ; for ( int i : nowTime ) { sum = sum + i ; } BPM = 60000 / sum * 2 ; if ( isFirst ) { BPM = BPM / 2 ; isFirst = false ; } System . out . println ( BPM ) ; } } catch ( Exception e ) { System . err . println ( e . toString ( ) ) ; } } }
Handle an event on the serial port.
Handle an event on the serial port .
//                        System.out.println(i); // Ignore all the other eventTypes, but you should consider the other ones.