mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 17:48:11 +00:00
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
/*
|
|
This project is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Multiprotocol is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
/************************/
|
|
/** Convert routines **/
|
|
/************************/
|
|
int16_t map( int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max)
|
|
{
|
|
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
|
long y ;
|
|
x -= in_min ;
|
|
y = out_max - out_min ;
|
|
y *= x ;
|
|
x = y / (in_max - in_min) ;
|
|
return x + out_min ;
|
|
}
|
|
|
|
// Channel value is converted to 8bit values full scale
|
|
uint8_t convert_channel_8b(uint8_t num)
|
|
{
|
|
return (uint8_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,0,255));
|
|
}
|
|
|
|
// Channel value is converted to 8bit values to provided values scale
|
|
uint8_t convert_channel_8b_scale(uint8_t num,uint8_t min,uint8_t max)
|
|
{
|
|
return (uint8_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,min,max));
|
|
}
|
|
|
|
// Channel value is converted sign + magnitude 8bit values
|
|
uint8_t convert_channel_s8b(uint8_t num)
|
|
{
|
|
uint8_t ch;
|
|
ch = convert_channel_8b(num);
|
|
return (ch < 128 ? 127-ch : ch);
|
|
}
|
|
|
|
// Channel value is converted to 10bit values
|
|
uint16_t convert_channel_10b(uint8_t num)
|
|
{
|
|
return (uint16_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,1,1023));
|
|
}
|
|
|
|
// Channel value is multiplied by 1.5
|
|
uint16_t convert_channel_frsky(uint8_t num)
|
|
{
|
|
return Servo_data[num] + Servo_data[num]/2;
|
|
}
|
|
|
|
// Channel value is converted for HK310
|
|
void convert_channel_HK310(uint8_t num, uint8_t *low, uint8_t *high)
|
|
{
|
|
uint16_t temp=0xFFFF-(4*Servo_data[num])/3;
|
|
*low=(uint8_t)(temp&0xFF);
|
|
*high=(uint8_t)(temp>>8);
|
|
}
|
|
|
|
// Channel value is limited to PPM_100
|
|
uint16_t limit_channel_100(uint8_t ch)
|
|
{
|
|
if(Servo_data[ch]>servo_max_100)
|
|
return servo_max_100;
|
|
else
|
|
if (Servo_data[ch]<servo_min_100)
|
|
return servo_min_100;
|
|
return Servo_data[ch];
|
|
}
|
|
|