Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LED service and themes for system signaling #1205

Merged
merged 19 commits into from Dec 17, 2016

Conversation

@sergeuz
Copy link
Member

commented Dec 16, 2016

This PR fixes #569, #976 and #1111 by implementing centralized LED service and theme "engine" for system LED signaling.

TODO:

  • Reference documentation;
  • Use user-defined LED signaling in bootloader (at least colors);
  • Improve unit test coverage.

Test application to play with:

#include "application.h"

SYSTEM_MODE(MANUAL);

namespace {

Serial1LogHandler logHandler(115200, LOG_LEVEL_WARN, {
    { "app", LOG_LEVEL_ALL }
});

uint32_t t = 0;
int step = 0;

} // namespace

void setup() {
    // Set custom theme for system LED signaling
    LEDSystemTheme theme;
    theme.setSignal(LED_SIGNAL_NETWORK_OFF, RGB_COLOR_GRAY);            // WHITE
    theme.setSignal(LED_SIGNAL_NETWORK_ON, RGB_COLOR_YELLOW);           // BLUE
    theme.setSignal(LED_SIGNAL_NETWORK_CONNECTING, RGB_COLOR_MAGENTA);  // GREEN
    theme.setSignal(LED_SIGNAL_NETWORK_DHCP, RGB_COLOR_MAGENTA);        // GREEN
    theme.setSignal(LED_SIGNAL_NETWORK_CONNECTED, RGB_COLOR_MAGENTA);   // GREEN
    theme.setSignal(LED_SIGNAL_CLOUD_CONNECTING, RGB_COLOR_ORANGE);     // CYAN
    theme.setSignal(LED_SIGNAL_CLOUD_HANDSHAKE, RGB_COLOR_ORANGE);      // CYAN
    theme.setSignal(LED_SIGNAL_CLOUD_CONNECTED, RGB_COLOR_ORANGE);      // CYAN
    theme.setSignal(LED_SIGNAL_SAFE_MODE, RGB_COLOR_BLUE);              // YELLOW
    theme.setSignal(LED_SIGNAL_LISTENING_MODE, RGB_COLOR_YELLOW);       // BLUE
    theme.setSignal(LED_SIGNAL_DFU_MODE, RGB_COLOR_YELLOW);             // BOOTLOADER NOT IMPLEMENTED YET
    theme.setSignal(LED_SIGNAL_FIRMWARE_UPDATE, RGB_COLOR_MAGENTA);     // BOOTLOADER NOT IMPLEMENTED YET
    theme.setSignal(LED_SIGNAL_POWER_OFF, RGB_COLOR_GREEN);             // GRAY

    // Comment out this line to load above theme from flash on reboot
    theme.apply(true /* save */);

    // Uncomment this line to restore factory default theme
    // LEDSystemTheme::restoreDefault();
}

void loop() {
    if (step && millis() - t < 5000) {
        return;
    }
    switch (++step) {
    case 1:
    case 9: {
        // Keep network off for a while
        break;
    }
    case 10:
    case 2: {
        Log.info("-> WiFi.on()");
        WiFi.on();
        break;
    }
    case 11:
    case 3: {
        Log.info("-> WiFi.connect()");
        WiFi.connect();
        break;
    }
    case 12:
    case 4: {
        Log.info("-> Particle.connect()");
        Particle.connect();
        break;
    }
    case 13:
    case 5: {
        Log.info("-> Particle.disconnect()");
        Particle.disconnect();
        break;
    }
    case 14:
    case 6: {
        Log.info("-> WiFi.disconnect()");
        WiFi.disconnect(); // Seems to cause automatic reconnection
        break;
    }
    case 15:
    case 7: {
        Log.info("-> WiFi.off()");
        WiFi.off();
        break;
    }
    case 8: {
        // restore factory default theme, and repeat
        LEDSystemTheme::restoreDefault();
        break;
    }
    default:
        break;
    }
    t = millis();
}

Doneness:

  • Contributor has signed CLA
  • Problem and Solution clearly stated
  • Code peer reviewed
  • API tests compiled
  • Run unit/integration/application tests on device
  • Add documentation
  • Add to CHANGELOG.md after merging (add links to docs and issues)

Features

@sergeuz sergeuz added this to the 0.6.1 milestone Dec 16, 2016

sergeuz and others added 2 commits Dec 16, 2016
Merge branch 'develop' into feature/led_service
  Conflicts:
	platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/dct.h
	services/inc/services_dynalib.h
	services/src/rgbled.c
@technobly
Copy link
Member

left a comment

🔴 🍊 💛 🍏 🔵 💜 💡 All Your Colors Are Belong To Us!

@technobly technobly merged commit b4dd5e4 into develop Dec 17, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@technobly technobly deleted the feature/led_service branch Dec 17, 2016

@sergeuz sergeuz referenced this pull request Jan 15, 2017
@technobly technobly referenced this pull request Feb 13, 2017
2 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.