Subversion Repositories libOLED

Rev

Rev 7 | Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 10
Line 8... Line 8...
8
#include "libOLED/ap_math.H"
8
#include "libOLED/ap_math.H"
9
#include "libOLED/displayclass.H"
9
#include "libOLED/displayclass.H"
10
#include "libOLED/fontclass.H"
10
#include "libOLED/fontclass.H"
11
#include "libOLED/displayDial.H"
11
#include "libOLED/displayDial.H"
12
 
12
 
13
 
-
 
14
static ap_math math;
13
static ap_math math;
15
// this is the number of degrees between top centre of scale and
14
// 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.
15
// left or right hand end of scale : 90 degrees produces a semicircle.
17
 
16
 
18
 
-
 
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_)
17
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_)
20
{
18
{
21
 
-
 
22
}
19
}
23
 
20
 
24
/* position is integer from 0 to SINE_STEPS */
21
/* position is integer from 0 to SINE_STEPS */
25
void
-
 
26
displayDial_t::draw_needle (int16_t position)
22
void displayDial_t::draw_needle(int16_t position)
27
{
23
{
28
  int ang = math.SINE_SCALING * ((position - (math.SINE_STEPS/2)) * m_a1) / (math.SINE_STEPS/2);
24
  int ang = math.SINE_SCALING * ((position - (math.SINE_STEPS / 2)) * m_a1) / (math.SINE_STEPS / 2);
29
 
25
 
30
  int si = math.ap_sin (ang);
26
  int si = math.ap_sin(ang);
31
  int co = math.ap_cos (ang);
27
  int co = math.ap_cos(ang);
32
 
28
 
33
  /* calculate a shift for a second side of the needle */
29
  /* calculate a shift for a second side of the needle */
34
  int xl = math.ap_sin (ang - math.SINE_STEPS);
30
  int xl = math.ap_sin(ang - math.SINE_STEPS);
35
  int yl = math.ap_cos (ang - math.SINE_STEPS);
31
  int yl = math.ap_cos(ang - math.SINE_STEPS);
36
 
32
 
37
  int si2 = m_siz + 2;
33
  int si2 = m_siz + 2;
38
  int si3 = 2 * m_siz / 3;
34
  int si3 = 2 * m_siz / 3;
39
 
35
 
40
  int xs,ys;
36
  int xs, ys;
41
  // three parallel lines
37
  // three parallel lines
42
  xs = -xl;
38
  xs = -xl;
43
  ys = -yl;
39
  ys = -yl;
44
  int step;
40
  int step;
45
  for(step =0; step < 3; step++)
41
  for (step = 0; step < 3; step++)
46
    {
42
  {
47
    m_display.drawLine (math.AP_SCALE(si*si2-xs) + m_xo, m_yo - math.AP_SCALE(co * si2 - ys),
43
    m_display.drawLine(math.AP_SCALE(si * si2 - xs) + m_xo, m_yo - math.AP_SCALE(co * si2 - ys),
48
 
44
 
49
    math.AP_SCALE(si*si3-xs) + m_xo,m_yo - math.AP_SCALE(co * si3 - ys), INVERT);
45
                       math.AP_SCALE(si * si3 - xs) + m_xo, m_yo - math.AP_SCALE(co * si3 - ys), INVERT);
50
    xs+=xl;
46
    xs += xl;
51
    ys+=yl;
47
    ys += yl;
52
    }
48
  }
53
 }
49
}
54
 
-
 
55
 
50
 
56
void displayDial_t::draw_scale ( int16_t low, int16_t high, uint8_t width, uint8_t num_step,int16_t scale)
51
void displayDial_t::draw_scale(int16_t low, int16_t high, uint8_t width, uint8_t num_step, int16_t scale)
57
{
52
{
58
 
53
 
59
  int ang;
54
  int ang;
60
  m_low = low;
55
  m_low = low;
61
  m_high = high;
56
  m_high = high;
62
  int sc_low  = low/scale;
57
  int sc_low = low / scale;
63
  int sc_high = high/scale;
58
  int sc_high = high / scale;
64
  int step = 256 * m_a1 * 2 / (4 * (sc_high - sc_low));
59
  int step = 256 * m_a1 * 2 / (4 * (sc_high - sc_low));
65
  int t;
60
  int t;
66
  ang = -m_a1 * 256;
61
  ang = -m_a1 * 256;
67
  for (t = sc_low * 4; t <= sc_high * 4; t++)
62
  for (t = sc_low * 4; t <= sc_high * 4; t++)
68
    {
63
  {
69
      int si = math.ap_sin ((ang*math.SINE_SCALING) / 256);
64
    int si = math.ap_sin((ang * math.SINE_SCALING) / 256);
70
      int co = math.ap_cos ((ang*math.SINE_SCALING) / 256);
65
    int co = math.ap_cos((ang * math.SINE_SCALING) / 256);
71
 
66
 
72
      int len;
67
    int len;
73
      switch (t % 4)
68
    switch (t % 4)
74
        {
69
    {
75
        case 0:
70
    case 0:
76
          len = width;
71
      len = width;
77
          break;
72
      break;
78
        case 1:
73
    case 1:
79
        case 3:
74
    case 3:
80
        case -1:
75
    case -1:
81
        case -3:
76
    case -3:
82
          len = width / 4;
77
      len = width / 4;
83
          break;
78
      break;
84
        case 2:
79
    case 2:
85
        case -2:
80
    case -2:
86
          len = width / 2;
81
      len = width / 2;
87
          break;
82
      break;
88
        }
-
 
89
 
-
 
90
      m_display.drawLine (math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz) * co),
-
 
91
      math.AP_SCALE((m_siz-len)*si) + m_xo,
-
 
92
                m_yo - math.AP_SCALE((m_siz - len) * co), WHITE);
-
 
93
      ang += step;
-
 
94
    }
83
    }
95
 
84
 
-
 
85
    m_display.drawLine(math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz)*co),
-
 
86
                       math.AP_SCALE((m_siz - len) * si) + m_xo,
-
 
87
                       m_yo - math.AP_SCALE((m_siz - len) * co), WHITE);
-
 
88
    ang += step;
-
 
89
  }
96
}
90
}
97
 
91
 
98
 
-
 
99
void displayDial_t::draw_limits()
92
void displayDial_t::draw_limits()
100
{
93
{
101
  m_display.fontSigDigits (small_font, 0,56,0,10,m_low,WHITE);
94
  m_display.fontSigDigits(small_font, 0, 56, 0, 10, m_low, WHITE);
102
  m_display.fontSigDigits (small_font, 120,56,1,10,m_high,WHITE);
95
  m_display.fontSigDigits(small_font, 120, 56, 1, 10, m_high, WHITE);
103
}
96
}