xoseperez / sonoffsc

Itead Studio SonoffSC custom firmware with MQTT and Domoticz support
GNU General Public License v3.0
104 stars 35 forks source link

Dismiss RGB notifications with double clap #6

Open Justblair opened 7 years ago

Justblair commented 7 years ago

Thought I would leave this as a feature request...


void clapDecode() {

    // at least 2 claps
    if (clapPointer > 0) {

        byte code = 2;
        if (clapPointer > 1) {
            int length = clapTimings[0] * CLAP_TOLERANCE;
            for(byte i=1; i<clapPointer; i++) {
                code <<= 1;
                if (clapTimings[i] > length) code += 1;
            }
        }

        link.send_P(at_code, code);
        if (code == 2) {
            rgbExec = true;         // Set the Exec flag to on
            colorR = colorB = colorG = 0;
            rgbEffect = RGB_WIPE;   // Set the Animation type
        }

    }

    // reset
    clapPointer = 0;

}`

I have tested it and it works just fine, wanted opinions on it before making a pull request.

The idea is that from OpenHab I can send (via mqtt) a color change to the rgb light ring, either timed (working on the code for that just now) or not.  The user can acknowledge the "alert" with a double clap or by double tapping the case of the Sonoff SC.  

This then switches the lights off.  It would also be nice if the Sonoff then sends a mqtt message to be used as an acknowledgement.