Subversion Repositories DashDisplay

Rev

Rev 28 | Rev 46 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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