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