Rev 4 | Rev 7 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | mjames | 1 | /* |
2 | * dials.c |
||
3 | * |
||
4 | * Created on: 22 Jan 2016 |
||
5 | * Author: Mike |
||
6 | */ |
||
7 | |||
8 | #include "libOLED/ap_math.H" |
||
9 | #include "libOLED/displayclass.H" |
||
10 | #include "libOLED/fontclass.H" |
||
11 | #include "libOLED/displayDial.H" |
||
12 | |||
13 | |||
14 | static ap_math math; |
||
15 | // this is the number of degrees between top centre of scale and |
||
16 | // left or right hand end of scale : 90 degrees produces a semicircle. |
||
17 | |||
18 | |||
5 | mjames | 19 | displayDial_t::displayDial_t(display_t & display,uint8_t x, uint8_t y, uint8_t siz,uint16_t angle_) :m_display(display), m_xo(x),m_yo(y),m_siz(siz),m_a1(angle_) |
4 | mjames | 20 | { |
21 | |||
22 | } |
||
23 | |||
24 | /* position is integer from 0 to SINE_STEPS */ |
||
25 | void |
||
5 | mjames | 26 | displayDial_t::draw_needle (int16_t position) |
4 | mjames | 27 | { |
28 | int ang = math.SINE_SCALING * ((position - (math.SINE_STEPS/2)) * m_a1) / (math.SINE_STEPS/2); |
||
29 | |||
30 | int si = math.ap_sin (ang); |
||
31 | int co = math.ap_cos (ang); |
||
32 | |||
33 | /* calculate a shift for a second side of the needle */ |
||
34 | int xl = math.ap_sin (ang - math.SINE_STEPS); |
||
35 | int yl = math.ap_cos (ang - math.SINE_STEPS); |
||
36 | |||
37 | int si2 = m_siz + 2; |
||
38 | int si3 = 2 * m_siz / 3; |
||
39 | |||
40 | int xs,ys; |
||
41 | // three parallel lines |
||
42 | xs = -xl; |
||
43 | ys = -yl; |
||
44 | int step; |
||
45 | for(step =0; step < 3; step++) |
||
46 | { |
||
5 | mjames | 47 | m_display.drawLine (math.AP_SCALE(si*si2-xs) + m_xo, m_yo - math.AP_SCALE(co * si2 - ys), |
4 | mjames | 48 | |
49 | math.AP_SCALE(si*si3-xs) + m_xo,m_yo - math.AP_SCALE(co * si3 - ys), INVERT); |
||
50 | xs+=xl; |
||
51 | ys+=yl; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | |||
5 | mjames | 56 | void displayDial_t::draw_scale ( int16_t low, int16_t high, uint8_t width, uint8_t num_step,int16_t scale) |
4 | mjames | 57 | { |
5 | mjames | 58 | |
4 | mjames | 59 | int ang; |
60 | int sc_low = low/scale; |
||
61 | int sc_high = high/scale; |
||
62 | int step = 256 * m_a1 * 2 / (4 * (sc_high - sc_low)); |
||
63 | int t; |
||
64 | ang = -m_a1 * 256; |
||
65 | for (t = sc_low * 4; t <= sc_high * 4; t++) |
||
66 | { |
||
67 | int si = math.ap_sin ((ang*math.SINE_SCALING) / 256); |
||
68 | int co = math.ap_cos ((ang*math.SINE_SCALING) / 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 | |||
5 | mjames | 88 | m_display.drawLine (math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz) * co), |
4 | mjames | 89 | math.AP_SCALE((m_siz-len)*si) + m_xo, |
90 | m_yo - math.AP_SCALE((m_siz - len) * co), WHITE); |
||
91 | ang += step; |
||
92 | } |
||
93 | |||
94 | // font_sig_digits (0,7,0,10,low); |
||
95 | // font_sig_digits(20,7,1,10,high); |
||
96 | } |