kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Tue Oct 13 13:10:21 2015 +0000
Revision:
8:ca92cb674004
Parent:
3:e3c41153e5fe
Child:
9:d1fc0805ec7d
play????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimogamo 0:2a15bd367891 1 #include "mbed.h"
shimogamo 0:2a15bd367891 2 #include "Trim.h"
shimogamo 0:2a15bd367891 3 #include "Global.h"
shimogamo 0:2a15bd367891 4 //PullUpに注意
shimogamo 8:ca92cb674004 5 Trim::Trim(PinName upsw, PinName downsw)
shimogamo 8:ca92cb674004 6 : _upsw(upsw), _downsw(downsw){
shimogamo 0:2a15bd367891 7
shimogamo 0:2a15bd367891 8 _upsw.mode(PullUp);
shimogamo 0:2a15bd367891 9 _downsw.mode(PullUp);
shimogamo 0:2a15bd367891 10
shimogamo 0:2a15bd367891 11 upswstatus = 1;
shimogamo 0:2a15bd367891 12 downswstatus = 1;
shimogamo 0:2a15bd367891 13
shimogamo 0:2a15bd367891 14 pitchrate = 0.5;
shimogamo 0:2a15bd367891 15 }
shimogamo 0:2a15bd367891 16
shimogamo 0:2a15bd367891 17
shimogamo 0:2a15bd367891 18 void Trim::pitchup(){
shimogamo 0:2a15bd367891 19 trimpitch--;
shimogamo 0:2a15bd367891 20 clamp(trimpitch,-7,7);
shimogamo 0:2a15bd367891 21 printf("trimpitch = %d\n",trimpitch);
shimogamo 0:2a15bd367891 22 }
shimogamo 0:2a15bd367891 23
shimogamo 0:2a15bd367891 24 void Trim::pitchdown(){
shimogamo 0:2a15bd367891 25 trimpitch++;
shimogamo 0:2a15bd367891 26 clamp(trimpitch,-7,7);
shimogamo 0:2a15bd367891 27 printf("trimpitch = %d\n",trimpitch);
shimogamo 0:2a15bd367891 28 }
shimogamo 0:2a15bd367891 29
shimogamo 0:2a15bd367891 30 void Trim::clamp(int &value, int min, int max){
shimogamo 0:2a15bd367891 31 if(value < min) {
shimogamo 0:2a15bd367891 32 value = min;
shimogamo 0:2a15bd367891 33 } else if(value > max) {
shimogamo 0:2a15bd367891 34 value = max;
shimogamo 0:2a15bd367891 35 }
shimogamo 0:2a15bd367891 36 }
shimogamo 0:2a15bd367891 37
shimogamo 0:2a15bd367891 38 void Trim::clamp(double &value, double min, double max){
shimogamo 0:2a15bd367891 39 if(value < min) {
shimogamo 0:2a15bd367891 40 value = min;
shimogamo 0:2a15bd367891 41 } else if(value > max) {
shimogamo 0:2a15bd367891 42 value = max;
shimogamo 0:2a15bd367891 43 }
shimogamo 0:2a15bd367891 44 }
shimogamo 0:2a15bd367891 45
shimogamo 0:2a15bd367891 46
shimogamo 8:ca92cb674004 47 double Trim::calc(int trimpitch){
shimogamo 8:ca92cb674004 48 return (double)trimpitch*pitchrate;
shimogamo 8:ca92cb674004 49 }
shimogamo 0:2a15bd367891 50
shimogamo 0:2a15bd367891 51 void Trim::update(){
shimogamo 0:2a15bd367891 52 if(_upsw == 0){
shimogamo 0:2a15bd367891 53 upswstatus = 0;
shimogamo 0:2a15bd367891 54 }else if((_upsw == 1)&&(upswstatus == 0)){
shimogamo 0:2a15bd367891 55 pitchup();
shimogamo 0:2a15bd367891 56 upswstatus = 1;
shimogamo 0:2a15bd367891 57 }
shimogamo 0:2a15bd367891 58
shimogamo 0:2a15bd367891 59 if(_downsw == 0){
shimogamo 0:2a15bd367891 60 downswstatus = 0;
shimogamo 0:2a15bd367891 61 }else if((_downsw == 1)&&(downswstatus == 0)){
shimogamo 0:2a15bd367891 62 pitchdown();
shimogamo 0:2a15bd367891 63 downswstatus = 1;
shimogamo 0:2a15bd367891 64 }
shimogamo 0:2a15bd367891 65
shimogamo 8:ca92cb674004 66 Global::settrimpitch(calc(trimpitch));
shimogamo 0:2a15bd367891 67 Global::setinttrimpitch(trimpitch);
shimogamo 0:2a15bd367891 68
shimogamo 0:2a15bd367891 69 }