Subversion Repositories DashDisplay

Rev

Rev 7 | Rev 13 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * dials.c
  3.  *
  4.  *  Created on: 22 Jan 2016
  5.  *      Author: Mike
  6.  */
  7. #include "stm32f1xx_hal.h"
  8. #include "ap_math.h"
  9. #include "font.h"
  10. #include "SSD1306.h"
  11.  
  12. static uint16_t a1 = 90;
  13. static uint8_t xo = 64;
  14. static uint8_t yo = 64;
  15. static uint8_t siz = 32;
  16.  
  17. /* percent is integer from 0 to 100 */
  18. void
  19. dial_draw_needle (uint16_t percent)
  20. {
  21.   int ang = ((percent - 50) * a1) / 50;
  22.  
  23.   int si = ap_sin (ang);
  24.   int co = ap_cos (ang);
  25.  
  26.   /* calculate a shift for a second side of the needle */
  27.   int xl = ap_sin (ang - 90);
  28.   int yl = ap_cos (ang - 90);
  29.  
  30.   int si2 = siz + 2;
  31.   int si3 = 2 * siz / 3;
  32.  
  33.   int xs,ys;
  34.   // three parallel lines
  35.   xs = -xl;
  36.   ys = -yl;
  37.   int step;
  38.   for(step =0; step < 3; step++)
  39.     {
  40.     drawLine (AP_SCALE(si*si2-xs) + xo, yo - AP_SCALE(co * si2 - ys),
  41.  
  42.   AP_SCALE(si*si3-xs) + xo,
  43.             yo - AP_SCALE(co * si3 - ys), INVERT);
  44.     xs+=xl;
  45.     ys+=yl;
  46.     }
  47.  }
  48.  
  49. /* initialise */
  50. void
  51. dial_size (uint8_t size)
  52. {
  53.   siz = size;
  54. }
  55.  
  56. void
  57. dial_draw_scale (uint8_t low, uint8_t high, uint8_t width, uint8_t num_step)
  58. {
  59.   int sz;
  60.   int ang;
  61.   int step = 256 * a1 * 2 / (4 * (high - low));
  62.   int t;
  63.   ang = -a1 * 256;
  64.   for (t = low * 4; t <= high * 4; t++)
  65.     {
  66.       int si = ap_sin (ang / 256);
  67.       int co = ap_cos (ang / 256);
  68.  
  69.       int len;
  70.       switch (t % 4)
  71.         {
  72.         case 0:
  73.           len = width;
  74.           break;
  75.         case 1:
  76.         case 3:
  77.           len = width / 4;
  78.           break;
  79.         case 2:
  80.           len = width / 2;
  81.           break;
  82.         }
  83.  
  84.       drawLine (AP_SCALE((siz)*si) + xo, yo - AP_SCALE((siz) * co),
  85.       AP_SCALE((siz-len)*si) + xo,
  86.                 yo - AP_SCALE((siz - len) * co), 1);
  87.       ang += step;
  88.     }
  89.  
  90.   font_gotoxy (0, 7);
  91.   font_digits(2,10,low);
  92.   font_gotoxy (19, 7);
  93.   font_digits(2,10,high);
  94. }
  95.  
  96. void
  97. dial_origin (uint8_t x, uint8_t y)
  98. {
  99.   xo = x;
  100.   yo = y;
  101. }
  102.