Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Control/Trim.cpp
- Committer:
- shimogamo
- Date:
- 2015-10-13
- Revision:
- 8:ca92cb674004
- Parent:
- 3:e3c41153e5fe
- Child:
- 9:d1fc0805ec7d
File content as of revision 8:ca92cb674004:
#include "mbed.h"
#include "Trim.h"
#include "Global.h"
//PullUpに注意
Trim::Trim(PinName upsw, PinName downsw)
: _upsw(upsw), _downsw(downsw){
_upsw.mode(PullUp);
_downsw.mode(PullUp);
upswstatus = 1;
downswstatus = 1;
pitchrate = 0.5;
}
void Trim::pitchup(){
trimpitch--;
clamp(trimpitch,-7,7);
printf("trimpitch = %d\n",trimpitch);
}
void Trim::pitchdown(){
trimpitch++;
clamp(trimpitch,-7,7);
printf("trimpitch = %d\n",trimpitch);
}
void Trim::clamp(int &value, int min, int max){
if(value < min) {
value = min;
} else if(value > max) {
value = max;
}
}
void Trim::clamp(double &value, double min, double max){
if(value < min) {
value = min;
} else if(value > max) {
value = max;
}
}
double Trim::calc(int trimpitch){
return (double)trimpitch*pitchrate;
}
void Trim::update(){
if(_upsw == 0){
upswstatus = 0;
}else if((_upsw == 1)&&(upswstatus == 0)){
pitchup();
upswstatus = 1;
}
if(_downsw == 0){
downswstatus = 0;
}else if((_downsw == 1)&&(downswstatus == 0)){
pitchdown();
downswstatus = 1;
}
Global::settrimpitch(calc(trimpitch));
Global::setinttrimpitch(trimpitch);
}