Subversion Repositories DashDisplay

Rev

Rev 13 | Rev 28 | 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 dial_draw_scale (int16_t low, int16_t high, uint8_t width, uint8_t num_step,int16_t scale)
  57. {
  58.   int sz;
  59.   int ang;
  60.   int sc_low  = low/scale;
  61.   int sc_high = high/scale;
  62.   int step = 256 * a1 * 2 / (4 * (sc_high - sc_low));
  63.   int t;
  64.   ang = -a1 * 256;
  65.   for (t = sc_low * 4; t <= sc_high * 4; t++)
  66.     {
  67.       int si = ap_sin (ang / 256);
  68.       int co = ap_cos (ang / 256);
  69.  
  70.       int len;
  71.       switch (t % 4)
  72.         {
  73.         case 0:
  74.           len = width;
  75.           break;
  76.         case 1:
  77.         case 3:
  78.         case -1:
  79.         case -3:
  80.           len = width / 4;
  81.           break;
  82.         case 2:
  83.         case -2:
  84.           len = width / 2;
  85.           break;
  86.         }
  87.  
  88.       drawLine (AP_SCALE((siz)*si) + xo, yo - AP_SCALE((siz) * co),
  89.       AP_SCALE((siz-len)*si) + xo,
  90.                 yo - AP_SCALE((siz - len) * co), 1);
  91.       ang += step;
  92.     }
  93.  
  94.   font_sig_digits (0,7,0,10,low);
  95.   font_sig_digits(20,7,1,10,high);
  96. }
  97.  
  98. void
  99. dial_origin (uint8_t x, uint8_t y)
  100. {
  101.   xo = x;
  102.   yo = y;
  103. }
  104.