Rev 5 | 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; |
||
| 32 | drawLine(AP_SCALE(si*si2-xs)+xo,yo-AP_SCALE(co*si2-ys), |
||
| 33 | AP_SCALE(si*2-xs)+xo,yo-AP_SCALE(co*2-ys), INVERT); |
||
| 34 | drawLine(AP_SCALE(si*si2+xs)+xo,yo-AP_SCALE(co*si2+ys), |
||
| 35 | AP_SCALE(si*2+xs)+xo,yo-AP_SCALE(co*2+ys), INVERT); |
||
| 36 | |||
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | /* initialise */ |
||
| 42 | void dial_size(uint8_t size) |
||
| 43 | { |
||
| 44 | siz=size; |
||
| 45 | } |
||
| 46 | |||
| 47 | void dial_draw_scale(uint8_t low, uint8_t high,uint8_t width, uint8_t num_step) |
||
| 48 | { |
||
| 49 | int sz; |
||
| 50 | int ang; |
||
| 51 | int step = a1*2 / (4 * (high-low)); |
||
| 52 | int t; |
||
| 53 | ang = -a1; |
||
| 54 | for(t=low*4; t <= high* 4 ; t++) |
||
| 55 | { |
||
| 56 | int si = ap_sin(ang); |
||
| 57 | int co = ap_cos(ang); |
||
| 58 | |||
| 59 | int len; |
||
| 60 | switch(t % 4) |
||
| 61 | { |
||
| 62 | case 0: |
||
| 63 | { |
||
| 64 | uint8_t v = t/4; |
||
| 65 | // if((v % num_step) == 0) |
||
| 66 | // { |
||
| 67 | // char buff[2]; |
||
| 68 | // char * p = buff+1; |
||
| 69 | // int d = 1; |
||
| 70 | // buff[1] = v %10 + '0'; |
||
| 71 | // if(v>=10) |
||
| 72 | // { |
||
| 73 | // p = buff; |
||
| 74 | // d= 2; |
||
| 75 | // buff[0] = v/10 + '0'; |
||
| 76 | // } |
||
| 77 | // |
||
| 78 | // print_large_string(p,AP_SCALE((siz-width/2-3)*si)+xo - d *4, |
||
| 79 | // yo - AP_SCALE((siz - width / 2 ) * co), d); |
||
| 80 | // |
||
| 81 | // } |
||
| 82 | len=2; |
||
| 83 | } |
||
| 84 | break; |
||
| 85 | case 1: |
||
| 86 | case 3: |
||
| 87 | len = width/4; |
||
| 88 | break; |
||
| 89 | case 2: |
||
| 90 | len = width/2; |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | drawLine(AP_SCALE((siz)*si) + xo, yo - AP_SCALE((siz)*co), |
||
| 96 | AP_SCALE((siz-len)*si) +xo, yo - AP_SCALE((siz-len)*co), 1); |
||
| 97 | ang += step; |
||
| 98 | } |
||
| 99 | |||
| 100 | |||
| 101 | } |
||
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | void dial_origin(uint8_t x, uint8_t y) |
||
| 106 | { |
||
| 107 | xo=x; yo=y; |
||
| 108 | } |