1010
Check-in [968cc45924]
Not logged in
Public Repositories
mwm's Repositories

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix button handling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:968cc45924893f998812fc73e11c4fa8aae6ce48
User & Date: mwm 2016-11-04 08:26:18
Context
2016-11-04
10:05
Replace delays with spins on button state. check-in: 10b72045d3 user: mwm tags: trunk
08:26
Fix button handling check-in: 968cc45924 user: mwm tags: trunk
07:45
Fix title for chiselapp check-in: 7d7aaa0995 user: mwm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tiny-1010.ino.

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
...
450
451
452
453
454
455
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470
471
472
473
474

475
void
loop(void) {
     const shape *const s = &shapes[game.waiting[selected]];
     const byte can_place = draw_game();

     arduboy.pollButtons();

     if (arduboy.pressed(B_BUTTON)) {
          state = PAUSED;
          selected = 0;
          return;
     }

     switch (state) {
     case SELECTING:
          if (arduboy.pressed(UP_BUTTON))
               do {
                    if (selected)
                         selected -= 1;
                    else
                         selected = WAIT_LEN - 1;
               } while (game.waiting[selected] < 0);
          else if (arduboy.pressed(DOWN_BUTTON))
               do
                    selected = (selected + 1) % WAIT_LEN;
               while (game.waiting[selected] < 0);
          else if (arduboy.pressed(A_BUTTON)) {
               game.x = game.y = 0;
               state = MOVING;
          } else if (arduboy.pressed(RIGHT_BUTTON)) {
               arduboy.digitalWriteRGB(RGB_ON, RGB_OFF, RGB_OFF);
               if (find_clear(s))
                    state = MOVING;
          }
          break;
     case MOVING:
          if (arduboy.pressed(A_BUTTON) && can_place)
               make_move();
          else if (arduboy.pressed(UP_BUTTON) && (game.y > 0))
               game.y -= 1;
          else if (arduboy.pressed(DOWN_BUTTON)
                   && (game.y < BOARD_SIZE - s->height))
               game.y += 1;
          else if (arduboy.pressed(RIGHT_BUTTON)
................................................................................
               if (game.x > 0)
                    game.x -= 1;
               else
                    state = SELECTING;
          }
          break;
     case PAUSED:
          if (arduboy.pressed(A_BUTTON)) {
               if (selected)
                    reset_game();
               state = SELECTING;
               select_next();
          } else if (!arduboy.notPressed(LEFT_BUTTON | RIGHT_BUTTON))

               selected = !selected;
          break;
     case DONE:
          for (byte i = 0; i < WAIT_LEN; i += 1)
               game.waiting[i] = -1;
          EEPROM.put(saved_game, game);
          if (arduboy.pressed(A_BUTTON))
               reset_game();
          break;
     }
     EEPROM.put(saved_game, game);
     delay(game.delay);

}







|







|






|



|


|






|







 







|




|
>






|



|
|
>

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
...
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
void
loop(void) {
     const shape *const s = &shapes[game.waiting[selected]];
     const byte can_place = draw_game();

     arduboy.pollButtons();

     if (arduboy.justPressed(B_BUTTON)) {
          state = PAUSED;
          selected = 0;
          return;
     }

     switch (state) {
     case SELECTING:
          if (arduboy.justPressed(UP_BUTTON))
               do {
                    if (selected)
                         selected -= 1;
                    else
                         selected = WAIT_LEN - 1;
               } while (game.waiting[selected] < 0);
          else if (arduboy.justPressed(DOWN_BUTTON))
               do
                    selected = (selected + 1) % WAIT_LEN;
               while (game.waiting[selected] < 0);
          else if (arduboy.justPressed(A_BUTTON)) {
               game.x = game.y = 0;
               state = MOVING;
          } else if (arduboy.justPressed(RIGHT_BUTTON)) {
               arduboy.digitalWriteRGB(RGB_ON, RGB_OFF, RGB_OFF);
               if (find_clear(s))
                    state = MOVING;
          }
          break;
     case MOVING:
          if (arduboy.justPressed(A_BUTTON) && can_place)
               make_move();
          else if (arduboy.pressed(UP_BUTTON) && (game.y > 0))
               game.y -= 1;
          else if (arduboy.pressed(DOWN_BUTTON)
                   && (game.y < BOARD_SIZE - s->height))
               game.y += 1;
          else if (arduboy.pressed(RIGHT_BUTTON)
................................................................................
               if (game.x > 0)
                    game.x -= 1;
               else
                    state = SELECTING;
          }
          break;
     case PAUSED:
          if (arduboy.justPressed(A_BUTTON)) {
               if (selected)
                    reset_game();
               state = SELECTING;
               select_next();
          } else if (arduboy.justPressed(LEFT_BUTTON)
                  || arduboy.justPressed(RIGHT_BUTTON))
               selected = !selected;
          break;
     case DONE:
          for (byte i = 0; i < WAIT_LEN; i += 1)
               game.waiting[i] = -1;
          EEPROM.put(saved_game, game);
          if (arduboy.justPressed(A_BUTTON))
               reset_game();
          break;
     }
     if (state == MOVING)
          delay(game.delay);
     EEPROM.put(saved_game, game);
}