@@ -802,57 +802,45 @@ static const char _data_FX_MODE_MULTI_STROBE[] PROGMEM = "Strobe Mega@!,!;!,!;!;
802802
803803
804804/*
805- * Android loading circle
805+ * Android loading circle, refactored by @dedehai
806806 */
807807uint16_t mode_android (void ) {
808-
808+ if (!SEGENV.allocateData (sizeof (uint32_t ))) return mode_static ();
809+ uint32_t * counter = reinterpret_cast <uint32_t *>(SEGENV.data );
810+ unsigned size = SEGENV.aux1 >> 1 ; // upper 15 bit
811+ unsigned shrinking = SEGENV.aux1 & 0x01 ; // lowest bit
812+ if (strip.now >= SEGENV.step ) {
813+ SEGENV.step = strip.now + 3 + ((8 * (uint32_t )(255 - SEGMENT.speed )) / SEGLEN);
814+ if (size > (SEGMENT.intensity * SEGLEN) / 255 )
815+ shrinking = 1 ;
816+ else if (size < 2 )
817+ shrinking = 0 ;
818+ if (!shrinking) { // growing
819+ if ((*counter % 3 ) == 1 )
820+ SEGENV.aux0 ++; // advance start position
821+ else
822+ size++;
823+ } else { // shrinking
824+ SEGENV.aux0 ++;
825+ if ((*counter % 3 ) != 1 )
826+ size--;
827+ }
828+ SEGENV.aux1 = size << 1 | shrinking; // save back
829+ (*counter)++;
830+ if (SEGENV.aux0 >= SEGLEN) SEGENV.aux0 = 0 ;
831+ }
832+ uint32_t start = SEGENV.aux0 ;
833+ uint32_t end = (SEGENV.aux0 + size) % SEGLEN;
809834 for (unsigned i = 0 ; i < SEGLEN; i++) {
810- SEGMENT.setPixelColor (i, SEGMENT.color_from_palette (i, true , PALETTE_SOLID_WRAP, 1 ));
811- }
812-
813- if (SEGENV.aux1 > (SEGMENT.intensity *SEGLEN)/255 )
814- {
815- SEGENV.aux0 = 1 ;
816- } else
817- {
818- if (SEGENV.aux1 < 2 ) SEGENV.aux0 = 0 ;
819- }
820-
821- unsigned a = SEGENV.step & 0xFFFFU ;
822-
823- if (SEGENV.aux0 == 0 )
824- {
825- if (SEGENV.call %3 == 1 ) {a++;}
826- else {SEGENV.aux1 ++;}
827- } else
828- {
829- a++;
830- if (SEGENV.call %3 != 1 ) SEGENV.aux1 --;
831- }
832-
833- if (a >= SEGLEN) a = 0 ;
834-
835- if (a + SEGENV.aux1 < SEGLEN)
836- {
837- for (unsigned i = a; i < a+SEGENV.aux1 ; i++) {
838- SEGMENT.setPixelColor (i, SEGCOLOR (0 ));
839- }
840- } else
841- {
842- for (unsigned i = a; i < SEGLEN; i++) {
843- SEGMENT.setPixelColor (i, SEGCOLOR (0 ));
844- }
845- for (unsigned i = 0 ; i < SEGENV.aux1 - (SEGLEN -a); i++) {
835+ if ((start < end && i >= start && i < end) || (start >= end && (i >= start || i < end)))
846836 SEGMENT.setPixelColor (i, SEGCOLOR (0 ));
847- }
837+ else
838+ SEGMENT.setPixelColor (i, SEGMENT.color_from_palette (i, true , PALETTE_SOLID_WRAP, 1 ));
848839 }
849- SEGENV.step = a;
850-
851- return 3 + ((8 * (uint32_t )(255 - SEGMENT.speed )) / SEGLEN);
840+ return FRAMETIME;
852841}
853842static const char _data_FX_MODE_ANDROID[] PROGMEM = " Android@!,Width;!,!;!;;m12=1" ; // vertical
854843
855-
856844/*
857845 * color chase function.
858846 * color1 = background color
0 commit comments