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.
auxiliar.cpp
00001 00002 #include "declaraciones.h" 00003 00004 00005 extern Serial pc; 00006 extern volatile byte estado; 00007 00008 00009 00010 00011 //*************************************************************** 00012 // * DEVUELVE VALOR DENTRO DEL LIMITE 00013 //*************************************************************** 00014 long constrain(long valor, long minimo, long maximo){ 00015 00016 return (valor < minimo)? minimo : ((valor > maximo)? maximo : valor); 00017 } 00018 00019 00020 //*************************************************************** 00021 // * EXTRAPOLA VALOR EN UN RANGO 00022 //*************************************************************** 00023 long map(long valor, long minimo_in, long maximo_in, long minimo_out, long maximo_out){ 00024 00025 long val = (valor < minimo_in)? minimo_in : ((valor > maximo_in)? maximo_in : valor); 00026 00027 float dif_in = (float)maximo_in - (float)minimo_in; 00028 float dif_out = (float)maximo_out - (float)minimo_out; 00029 float conv = dif_out/dif_in; 00030 val = (long)(((float)val * conv)+0.5) + minimo_out; 00031 return val; 00032 } 00033 00034 00035 00036 void PrintValorDecimal(char *txt, int32_t valor){ 00037 pc.printf("%s: %d\r\n", txt, valor); 00038 } 00039 00040 00041 void PrintValorFloat(char *txt, float valor){ 00042 pc.printf("%s: %f\r\n", txt, valor); 00043 } 00044 00045 00046 00047 void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes 00048 { 00049 for (int i=0; i<length; i++) { 00050 pc.printf("0x%02x ", data[i]); 00051 } 00052 } 00053 00054 00055 00056 00057 // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 00058 // devuelve grados 00059 void grados(float pos, int res[]){ // devuelve grados 00060 00061 res[0] = int(pos); 00062 pos -= res[0]; 00063 pos *= 60; 00064 res[1] = int(pos); 00065 pos -= res[1]; 00066 pos *= 60; 00067 res[2] = int(pos); 00068 } 00069 00070 00071 00072 /* 00073 * CALCULA CHECKSUM 00074 */ 00075 uint16_t checksum(uint8_t *buf, uint16_t nb){ 00076 uint16_t chk=0; 00077 00078 for(uint8_t i=0; i<nb; i++){ 00079 chk += buf[i]; 00080 } 00081 chk ^= 0xffff; 00082 return chk; 00083 }
Generated on Fri Jul 15 2022 16:48:31 by
1.7.2