kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Committer:
shimogamo
Date:
Wed Oct 14 13:44:32 2015 +0000
Revision:
9:d1fc0805ec7d
Parent:
8:ca92cb674004
Init??????

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 9:d1fc0805ec7d 14 pitchrate = Global::gettrimpitchrate();
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 9:d1fc0805ec7d 49 }
shimogamo 0:2a15bd367891 50
shimogamo 0:2a15bd367891 51 void Trim::update(){
shimogamo 9:d1fc0805ec7d 52 pitchrate = Global::gettrimpitchrate();
shimogamo 9:d1fc0805ec7d 53
shimogamo 0:2a15bd367891 54 if(_upsw == 0){
shimogamo 0:2a15bd367891 55 upswstatus = 0;
shimogamo 0:2a15bd367891 56 }else if((_upsw == 1)&&(upswstatus == 0)){
shimogamo 0:2a15bd367891 57 pitchup();
shimogamo 0:2a15bd367891 58 upswstatus = 1;
shimogamo 0:2a15bd367891 59 }
shimogamo 0:2a15bd367891 60
shimogamo 0:2a15bd367891 61 if(_downsw == 0){
shimogamo 0:2a15bd367891 62 downswstatus = 0;
shimogamo 0:2a15bd367891 63 }else if((_downsw == 1)&&(downswstatus == 0)){
shimogamo 0:2a15bd367891 64 pitchdown();
shimogamo 0:2a15bd367891 65 downswstatus = 1;
shimogamo 0:2a15bd367891 66 }
shimogamo 0:2a15bd367891 67
shimogamo 8:ca92cb674004 68 Global::settrimpitch(calc(trimpitch));
shimogamo 0:2a15bd367891 69 Global::setinttrimpitch(trimpitch);
shimogamo 0:2a15bd367891 70
shimogamo 0:2a15bd367891 71 }