Advertisement
Guest User

RB PLUGIN EX

a guest
Apr 15th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.21 KB | None | 0 0
  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id$
  9.  *
  10.  * Copyright (C) 2022
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License
  14.  * as published by the Free Software Foundation; either version 2
  15.  * of the License, or (at your option) any later version.
  16.  *
  17.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  18.  * KIND, either express or implied.
  19.  *
  20.  ****************************************************************************/
  21.  
  22. #include "plugin.h"
  23. #include "lib/pluginlib_actions.h"
  24.  
  25. const struct button_mapping* plugin_contexts[]= {
  26.     pla_main_ctx,
  27. #if defined(HAVE_REMOTE_LCD)
  28.     pla_remote_ctx,
  29. #endif
  30. };
  31.  
  32. const int NOT_GUESSED = 0;
  33. const int GUESSED_RIGHT_WRONG_POSITION = 1;
  34. const int GUESSED_RIGHT = 2;
  35.  
  36. int cubeSize = 24;
  37. int cubeSpacing = 4;
  38.  
  39.  
  40. #ifdef HAVE_SCROLLWHEEL
  41. #define ACT_UP          PLA_SCROLL_FWD
  42. #define ACT_UP_REPEAT   PLA_SCROLL_FWD_REPEAT
  43. #define ACT_DOWN        PLA_SCROLL_BACK:
  44. #define ACT_DOWN_REPEAT PLA_SCROLL_BACK_REPEAT:
  45. #else
  46. #define ACT_UP          PLA_UP
  47. #define ACT_UP_REPEAT   PLA_UP_REPEAT
  48. #define ACT_DOWN        PLA_DOWN:
  49. #define ACT_DOWN_REPEAT PLA_DOWN_REPEAT:
  50. #endif
  51.  
  52. struct candidate
  53. {
  54.     char character;
  55.     int guess;
  56. };
  57.  
  58. struct candidate candidates[26];
  59.  
  60. static void cleanup(void *parameter)
  61. {
  62.     (void)parameter;
  63. }
  64. void make_background(void)
  65. {
  66.     rb->lcd_set_background(LCD_WHITE);
  67.     rb->lcd_set_foreground(LCD_BLACK);
  68.     rb->lcd_clear_display();
  69. }
  70.  
  71. void draw_square(int x, int y)
  72. {
  73.     rb->lcd_fillrect(x,y,cubeSize,cubeSize);
  74. }
  75.  
  76.  
  77. enum plugin_status plugin_start(const void* parameter)
  78. {
  79.     (void)parameter;
  80.     bool quit = false;
  81.     int action = ACTION_NONE;
  82.  
  83.     for (int i = 0; i < 26; i++)
  84.     {
  85.         candidates[i].character = 65 + i;
  86.     }
  87.    
  88.     int xStart = (LCD_WIDTH - (5 * cubeSize) - (4 * cubeSpacing)) / 2;
  89.     int yStart = 32;
  90.  
  91.     while(!quit)
  92.     {
  93.         make_background();
  94.        
  95.         int xPosTest = 0;
  96.         rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
  97.         for (int i = 0; i < 26; i++)
  98.         {
  99.             char tempCharacter[2];
  100.             rb->snprintf(tempCharacter, sizeof(tempCharacter), "%c", candidates[i].character);
  101.             rb->lcd_putsxy(0,xPosTest, tempCharacter);
  102.             xPosTest += 15;
  103.         }
  104.         rb->lcd_set_drawmode(DRMODE_SOLID);
  105.  
  106.         int xPos = xStart;
  107.         int yPos = yStart;
  108.  
  109.         for (int i = 0; i < 5; i++)
  110.         {
  111.             for (int j = 0; j < 5; j++)
  112.             {
  113.                 draw_square(xPos, yPos);
  114.                 xPos += cubeSize + cubeSpacing;
  115.             }
  116.             yPos += cubeSize + cubeSpacing;
  117.             xPos = xStart;
  118.         }
  119.  
  120.         //rb->lcd_set_drawmode(DRMODE_BG);
  121.         //rb->lcd_fillrect(0,0,LCD_WIDTH,LCD_HEIGHT);
  122.  
  123.         //rb->lcd_set_drawmode(DRMODE_SOLID);
  124.  
  125.         rb->lcd_update();
  126.  
  127.         action = pluginlib_getaction(0, plugin_contexts, ARRAYLEN(plugin_contexts));
  128.    
  129.         switch (action)
  130.         {
  131.             case PLA_EXIT:
  132.             /* FALL-Through */
  133.             case PLA_CANCEL:
  134.                 quit = true;
  135.                 cleanup(NULL);
  136.                 return PLUGIN_OK;
  137.             case PLA_LEFT:
  138.                 break;
  139.             case PLA_RIGHT:
  140.                 break;
  141.             case ACT_UP:
  142.             /* FALL-Through */
  143.             case ACT_UP_REPEAT:
  144.                 break;
  145.             case ACT_DOWN:
  146.             /* FALL-Through */
  147.             case ACT_DOWN_REPEAT:
  148.                 break;
  149.  
  150.             default:
  151.                 if (rb->default_event_handler_ex(action, cleanup, NULL)
  152.                     == SYS_USB_CONNECTED)
  153.                     return PLUGIN_USB_CONNECTED;
  154.         }
  155.  
  156.     }
  157.     return PLUGIN_OK;
  158. }
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement