From 38e707c3c5a4600daac694284d0ebdbd96820956 Mon Sep 17 00:00:00 2001 From: Roy van de Water Date: Tue, 8 Apr 2014 14:12:26 -0700 Subject: [PATCH] Add a cop and an progress indicator --- spec/char_queue_test.h | 1 - src/TestStatus.ino | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/spec/char_queue_test.h b/spec/char_queue_test.h index 4d34402..beac47d 100644 --- a/spec/char_queue_test.h +++ b/spec/char_queue_test.h @@ -16,7 +16,6 @@ class CharQueueTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST( test_size_with_two_items ); CPPUNIT_TEST( test_size_after_a_push_and_a_pop ); CPPUNIT_TEST( test_size_after_two_pushes_and_a_pop ); - CPPUNIT_TEST( test_size_after_a_pop ); CPPUNIT_TEST( test_tripple_pop_after_double_push ); CPPUNIT_TEST( test_clear_with_nothing ); CPPUNIT_TEST( test_clear_after_two_pushes ); diff --git a/src/TestStatus.ino b/src/TestStatus.ino index d5212c8..49b0e86 100644 --- a/src/TestStatus.ino +++ b/src/TestStatus.ino @@ -13,6 +13,8 @@ struct CRGB leds[LED_COUNT]; int mPulseInterval; char mColor; int mBrightness; +int mCommandStartTime; +char mLastColor; void setup() { @@ -49,7 +51,55 @@ void color() { case 'x': rainbow(); return; + case 'c': + cop(); + return; + case 'i': + indefinite_progress(); + return; + } +} + +void cop() { + int now = millis() / 100; + int phase = now % 5; + + switch(phase) { + case 0: + case 1: + set_rgb(254, 0, 0); + return; + case 2: + case 3: + set_rgb(0, 0, 254); + return; + case 4: + set_rgb(254, 254, 254); + return; + } +} + +void indefinite_progress() { + int time_elapsed = millis() - mCommandStartTime; + + if(time_elapsed > 5000) { + return set_color(mLastColor); } + + int leds_to_show = time_elapsed / (5000 / LED_COUNT); + + for (uint8_t i = 0; i < LED_COUNT; i++) { + if(i <= leds_to_show) { + leds[i].r = 254; + leds[i].g = 0; + leds[i].b = 254; + } else { + leds[i].r = 0; + leds[i].g = 0; + leds[i].b = 0; + } + } + LEDS.show(); } bool is_color(char character) { @@ -99,6 +149,10 @@ void set_color(char character) { case 'w': case 't': case 'x': + case 'c': + case 'i': + mCommandStartTime = millis(); + mLastColor = mColor; mColor = character; return; }