Guest User

Untitled

a guest
Sep 2nd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.16 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Ac6
  5.   * @version V1.0
  6.   * @date    01-December-2013
  7.   * @brief   Default main function.
  8.   * @info   https://community.ugfx.org/topic/430-errors-with-ugfx-and-chibios-on-stm32f7-discovery/#comment-3157
  9.   * @info   https://community.ugfx.org/topic/324-stm32f429-disc/
  10.   * @info
  11.   ******************************************************************************
  12. */
  13.  
  14.  
  15. #include "stm32f4xx.h"
  16. #include "stm32f429i_discovery.h"
  17. #include "gfx.h"
  18. #include "stm32f4xx_hal.h"
  19. #include <stdlib.h>
  20. #include "init.h"
  21. #include "math.h"
  22.  
  23. void mandelbrot(float x1, float y1, float x2, float y2);
  24.  
  25. static GListener gl;
  26. static GHandle   ghButton1, ghButton2, gh, ghContainerPage0;
  27. static GGraphObject g;
  28.  
  29. // A set of data points that will be displayed in the graph
  30. static const point data[5] = {
  31.     { -40, -40 },
  32.     { 70, 40 },
  33.     { 140, 60 },
  34.     { 210, 60 },
  35.     { 280, 200 }
  36. };
  37.  
  38. // A graph styling
  39. static GGraphStyle GraphStyle1 = {
  40.     { GGRAPH_POINT_DOT, 0, Blue },          // Point
  41.     { GGRAPH_LINE_NONE, 2, Gray },          // Line
  42.     { GGRAPH_LINE_SOLID, 0, Black },        // X axis
  43.     { GGRAPH_LINE_SOLID, 0, Black },        // Y axis
  44.     { GGRAPH_LINE_DASH, 5, Gray, 50 },      // X grid
  45.     { GGRAPH_LINE_DOT, 7, Yellow, 50 },     // Y grid
  46.     GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS   // Flags
  47. };
  48.  
  49. // Another graph styling
  50. static const GGraphStyle GraphStyle2 = {
  51.     { GGRAPH_POINT_SQUARE, 5, Red },        // Point
  52.     { GGRAPH_LINE_DOT, 2, Pink },           // Line
  53.     { GGRAPH_LINE_SOLID, 0, Black },        // X axis
  54.     { GGRAPH_LINE_SOLID, 0, Black },        // Y axis
  55.     { GGRAPH_LINE_DASH, 5, Gray, 50 },      // X grid
  56.     { GGRAPH_LINE_DOT, 7, Yellow, 50 },     // Y grid
  57.     GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS   // Flags
  58. };
  59.  
  60. static void createWidgets(void) {
  61.     GWidgetInit wi;
  62.  
  63.     // Apply some default values for GWIN
  64.     gwinWidgetClearInit(&wi);
  65.  
  66.     wi.g.show = FALSE;
  67.     wi.g.x = 0;
  68.     wi.g.y = 0;
  69.     wi.g.width = 240;
  70.     wi.g.height = 320;
  71.     wi.g.parent = 0;
  72.     wi.text = "Container";
  73.     wi.customDraw = 0;
  74.     ghContainerPage0 = gwinContainerCreate(0, &wi, 0);
  75.  
  76.     wi.g.show = TRUE;
  77.  
  78.     // Apply the button parameters
  79.     wi.g.width = 90;
  80.     wi.g.height = 30;
  81.     wi.g.y = 10;
  82.     wi.g.x = 10;
  83.     wi.text = "Toggle LED3";
  84.  
  85.     // Create the actual button
  86.     ghButton1 = gwinButtonCreate(NULL, &wi);
  87.  
  88.     // Apply the button parameters
  89.     wi.g.width = 90;
  90.     wi.g.height = 30;
  91.     wi.g.y = 10;
  92.     wi.g.x = 110;
  93.     wi.text = "Toggle LED4";
  94.  
  95.     // Create the actual button
  96.     ghButton2 = gwinButtonCreate(NULL, &wi);
  97.  
  98.  
  99.  
  100. }
  101.  
  102.  
  103.  
  104. systemticks_t gfxSystemTicks(void)
  105. {
  106.     return HAL_GetTick();
  107. }
  108.  
  109. systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
  110. {
  111.     return ms;
  112. }
  113.  
  114.  
  115. int main(void) {
  116.     GEvent* pe;
  117.     int test;
  118.     test = 42;
  119.     HAL_Init();
  120.     SystemClock_Config();
  121.     BSP_LED_Init(LED3);
  122.     BSP_LED_Init(LED4);
  123.     // Initialize the display
  124.     gfxInit();
  125.  
  126.     // Set the widget defaults
  127.     gwinSetDefaultFont(gdispOpenFont("UI2"));
  128.     gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
  129.     gdispClear(White);
  130.  
  131.     // create the widget
  132.     createWidgets();
  133.  
  134.     GWindowInit wii;
  135.  
  136.     wii.show = TRUE;
  137.     wii.x = 10;
  138.     wii.y = 50;
  139.     wii.width = 150;
  140.     wii.height = 150;
  141.     gh = gwinGraphCreate(&g, &wii);
  142.     gwinGraphSetOrigin(gh, (gwinGetWidth(gh)/2), (gwinGetHeight(gh)/2));
  143.     gwinGraphSetStyle(gh, &GraphStyle1);
  144.     gwinGraphDrawAxis(gh);
  145.  
  146.     gwinGraphDrawPoint(gh, 10, 10);
  147.  
  148.     gwinGraphDrawPoint(gh, 20, 20);
  149.  
  150.     gwinGraphDrawPoint(gh, 30, 30);
  151.  
  152.     // We want to listen for widget events
  153.     geventListenerInit(&gl);
  154.     gwinAttachListener(&gl);
  155.  
  156.  
  157.     while(1) {
  158.         // Get an Event
  159.         pe = geventEventWait(&gl, TIME_INFINITE);
  160.  
  161.         switch(pe->type) {
  162.             case GEVENT_GWIN_BUTTON:
  163.                 if (((GEventGWinButton*)pe)->gwin == ghButton1) {
  164.                     // Our button has been pressed
  165.                     BSP_LED_Toggle(LED3);
  166.                 }
  167.                 if (((GEventGWinButton*)pe)->gwin == ghButton2) {
  168.                     // Our button has been pressed
  169.                     BSP_LED_Toggle(LED4);
  170.                 }
  171.                 break;
  172.             default:
  173.                 break;
  174.         }
  175.     }
  176.  
  177.     return 0;
  178. }
  179.  
  180. /*
  181. int main(void)
  182. {
  183.     float cx, cy;
  184.     float zoom = 1.0f;
  185.  
  186.     HAL_Init();
  187.     SystemClock_Config();
  188.  
  189.     gfxInit();
  190.     // where to zoom in
  191.         cx = -0.086f;
  192.         cy = 0.85f;
  193.  
  194.         while(TRUE) {
  195.             mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy);
  196.  
  197.             zoom *= 0.7f;
  198.             if(zoom <= 0.00001f)
  199.                 zoom = 1.0f;
  200.         }
  201. }
  202.  
  203. void mandelbrot(float x1, float y1, float x2, float y2) {
  204.     unsigned int i,j, width, height;
  205.     uint16_t iter;
  206.     color_t color;
  207.     float fwidth, fheight;
  208.  
  209.     float sy = y2 - y1;
  210.     float sx = x2 - x1;
  211.     const int MAX = 512;
  212.  
  213.     width = (unsigned int)gdispGetWidth();
  214.     height = (unsigned int)gdispGetHeight();
  215.     fwidth = width;
  216.     fheight = height;
  217.  
  218.     for(i = 0; i < width; i++) {
  219.         for(j = 0; j < height; j++) {
  220.             float cy = j * sy / fheight + y1;
  221.             float cx = i * sx / fwidth + x1;
  222.             float x=0.0f, y=0.0f, xx=0.0f, yy=0.0f;
  223.             for(iter=0; iter <= MAX && xx+yy<4.0f; iter++) {
  224.                 xx = x*x;
  225.                 yy = y*y;
  226.                 y = 2.0f*x*y + cy;
  227.                 x = xx - yy + cx;
  228.             }
  229.             //color = ((iter << 8) | (iter&0xFF));
  230.             color = RGB2COLOR(iter<<7, iter<<4, iter);
  231.             gdispDrawPixel(i, j, color);
  232.         }
  233.     }
  234. }
  235. */
Advertisement
Add Comment
Please, Sign In to add comment