You are reading a single comment by @duncs and its replies. Click here to read the full conversation.
  • then "rewrite the above using Java"

    Here's an equivalent program written in Java that collects heart rate data from a chest strap at maximum sampling rate using the Garmin SDK:

    import com.garmin.fit.*;
    
    // Connect to the Garmin device
    Device device = GarminDevice.getDevice();
    
    // Start the heart rate monitor
    device.hrmStart();
    
    // Get the maximum sampling rate
    int samplingRate = device.hrmGetSamplingRate();
    
    // Collect the heart rate data
    List<Integer> heartRateData = new ArrayList<>();
    while (true) {
        int heartRate = device.hrmGetHeartRate();
        heartRateData.add(heartRate);
        try {
            Thread.sleep(1000 / samplingRate);
        } catch (InterruptedException e) {
            break;
        }
    }
    
    // Stop the heart rate monitor
    device.hrmStop();
    
    // Save the collected data to a file
    try (BufferedWriter writer = new BufferedWriter(new FileWriter("heart_rate_data.txt"))) {
        for (int data : heartRateData) {
            writer.write(Integer.toString(data));
            writer.newLine();
        }
    } catch (IOException e) {
        System.err.println("Error saving data to file: " + e.getMessage());
    }
    
About

Avatar for duncs @duncs started