#include <aUSBHub3p.reflex>

// Create a reference to the module
aUSBHub3p hub;

// Map scratchpad locations
// pad[offset : length]
pad[0:4] signed int peak;
pad[4:4] signed int duration;

reflex every_1ms() {
    // Current in micro-amps
    signed int current = hub.usb.getPortCurrent(4); 
    
    if (current > peak) {
        peak = current;
    }
    
    // If drawing more than 50mA, increment duration counter
    if (current > 50000) {
        duration++;
    }
}

reflex mapEnable() {
    peak = 0;
    duration = 0;
}