Subversion Repositories DashDisplay

Rev

Go to most recent revision | Details | 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
 */
7
#include "stm32f1xx_hal.h"
8
#include "ap_math.h"
9
#include "font.h"
10
#include "SSD1306.h"
11
 
12
static uint16_t  a1 = 120;
13
static uint8_t  xo=64;
14
static uint8_t  yo=64;
15
static uint8_t siz=32;
16
 
17
 
18
 
19
/* percent is integer from 0 to 100 */
20
void dial_draw_needle(uint16_t percent)
21
{
22
  int ang  = ((percent - 50)* a1) / 50 ;
23
 
24
  int si = ap_sin(ang);
25
  int co = ap_cos(ang);
26
 
27
  /* calculate a shift for a second side of the needle */
28
  int xs = ap_sin(ang-90);
29
  int ys = ap_cos(ang-90);
30
 
31
  int si2 = siz+2;
5 mjames 32
  int si3 = siz/2;
33
 
34
 
2 mjames 35
  drawLine(AP_SCALE(si*si2-xs)+xo,yo-AP_SCALE(co*si2-ys),
5 mjames 36
 
37
                   AP_SCALE(si*si3-xs)+xo,yo-AP_SCALE(co*si3-ys), INVERT);
2 mjames 38
  drawLine(AP_SCALE(si*si2+xs)+xo,yo-AP_SCALE(co*si2+ys),
39
 
5 mjames 40
                   AP_SCALE(si*si3+xs)+xo,yo-AP_SCALE(co*si3+ys), INVERT);
41
 
2 mjames 42
}
43
 
44
 
45
 
46
/* initialise */
47
void dial_size(uint8_t size)
48
{
49
        siz=size;
50
}
51
 
52
void dial_draw_scale(uint8_t low, uint8_t high,uint8_t width, uint8_t num_step)
53
{
54
        int sz;
55
        int ang;
56
        int step = a1*2 / (4 * (high-low));
57
        int t;
58
        ang = -a1;
59
        for(t=low*4; t <= high* 4 ; t++)
60
        {
61
                int si = ap_sin(ang);
62
                int co = ap_cos(ang);
63
 
64
                int len;
65
                switch(t % 4)
66
                {
67
                case 0:
68
                        {
69
                                uint8_t v = t/4;
70
//                              if((v % num_step) ==  0)
71
//                              {
72
//                                 char buff[2];
73
//                                 char * p = buff+1;
74
//                                 int d = 1;
75
//                                 buff[1] = v %10 + '0';
76
//                                 if(v>=10)
77
//                                 {
78
//                                         p = buff;
79
//                                         d= 2;
80
//                                         buff[0] = v/10 + '0';
81
//                                 }
82
//
83
//                                 print_large_string(p,AP_SCALE((siz-width/2-3)*si)+xo - d *4,
84
//                                                 yo - AP_SCALE((siz - width / 2 ) * co), d);
85
//
86
//                              }
87
                        len=2;
88
                        }
89
                        break;
90
                        case 1:
91
                        case 3:
92
                                len = width/4;
93
                                break;
94
                        case 2:
95
                                len = width/2;
96
                                break;
97
                        }
98
 
99
 
100
                        drawLine(AP_SCALE((siz)*si) + xo, yo - AP_SCALE((siz)*co),
101
                                         AP_SCALE((siz-len)*si) +xo, yo - AP_SCALE((siz-len)*co), 1);
102
                        ang += step;
103
                }
104
 
105
 
106
        }
107
 
108
 
109
 
110
void dial_origin(uint8_t x, uint8_t y)
111
{
112
        xo=x; yo=y;
113
}