APM:Libraries
Config_Func.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../osd.h"
4 
5 
6 /* ******************************************************************/
7 // чтение и запись мелких объектов
8 void NOINLINE eeprom_read_len(byte *p, uint16_t e, uint16_t l){
9  for(;l!=0; l--) {
10  *p++ = OSD_EEPROM::read( e++ );
11  }
12 }
13 
14 NOINLINE void eeprom_write_len(byte *p, uint16_t e, uint16_t l){
15  byte b;
16  for(; l!=0; l--, e++) {
17  b = *p++;
18  OSD_EEPROM::write(e, b);
19  }
20 }
21 
22 
24  for(byte i=0;i<128;i++){
25  byte c=OSD_EEPROM::read( ( EEPROM_offs(strings) + i) );
26  if(c==0xFF) {
27  break; // clear EEPROM
28  }
29  if(c==0){ // end of string
30  if(n==0) { // we now printing?
31  return; // if yes then string is over
32  }
33  n--; // strings to skip
34  }
35  if(n==0) // our string!
36  cb(c);
37  }
38 
39 }
40 
41 
42 static inline float degrees(float v){
43  return v*180 / 3.14159265;
44 }
45 
46 static inline void osd_print_S(PGM_P f){
47  osd.print(f);
48 }
49 
50 
51 void delay_telem(){
52  delayMicroseconds((1000000/TELEMETRY_SPEED*10)); //время приема 1 байта
53 }
54 
55 static inline void delay_byte(){
56  if(!osd_available())
57  delay_telem();
58 }
59 
60 
61 #ifdef DEBUG
62 /* prints hex numbers with leading zeroes */
63 // copyright, Peter H Anderson, Baltimore, MD, Nov, '07
64 // source: http://www.phanderson.com/arduino/arduino_display.html
65 void print_hex(uint16_t v, byte num_places)
66 {
67  uint16_t mask=0;
68  byte num_nibbles, digit, n;
69 
70  for (n=1; n<=num_places; n++) {
71  mask = (mask << 1) | 0x0001;
72  }
73  v = v & mask; // truncate v to specified number of places
74 
75  num_nibbles = num_places / 4;
76  if ((num_places % 4) != 0) {
77  ++num_nibbles;
78  }
79  do {
80  digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
81  osd.print(digit, HEX);
82  }
83  while(--num_nibbles);
84 }
85 
86 void hex_dump(byte *p, uint16_t len) {
87  byte i;
88  uint16_t j;
89 
90  for(j=0;j<len; j+=8){
91  OSD::write_S(0xFF);
92  print_hex(j,8);
93  OSD::write_S(' ');
94  for(i=0; i<8; i++){
95  OSD::write_S(' ');
96  print_hex(p[i+j],8);
97  }
98  }
99 }
100 
101 void serial_print_hex(uint16_t v, byte num_places)
102 {
103  uint16_t mask=0;
104  byte num_nibbles, digit, n;
105 
106  for (n=1; n<=num_places; n++) {
107  mask = (mask << 1) | 0x0001;
108  }
109  v = v & mask; // truncate v to specified number of places
110 
111  num_nibbles = num_places / 4;
112  if ((num_places % 4) != 0) {
113  ++num_nibbles;
114  }
115  do {
116  digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
117  Serial.print(digit, HEX);
118  }
119  while(--num_nibbles);
120 }
121 
122 void serial_hex_dump(byte *p, uint16_t len) {
123  uint8_t i;
124  uint16_t j;
125 
126  for(j=0;j<len; j+=16){
127  Serial.write_S('\n'); Serial.wait();
128  serial_print_hex(j,16);
129  Serial.write_S(' ');
130  for(i=0; i<16; i++){
131  Serial.write_S(' ');
132  serial_print_hex(p[i+j],8);
133  Serial.wait();
134  }
135  }
136 }
137 #else
138 void serial_hex_dump(byte *p, uint16_t len) {}
139 #endif
140 
141 
142 
143 void inline millis_plus(uint32_t *dst, uint16_t inc) {
144  *dst = millis() + inc;
145 }
146 
147 
148 void inline long_plus(uint32_t *dst, uint16_t inc) {
149  *dst += inc;
150 }
151 
152 int inline long_diff(uint32_t *l1, uint32_t *l2) {
153  return (int)(l1-l2);
154 }
155 
156 extern const struct Measure *measure;
157 
158 float inline get_converth(){
159  return pgm_read_float(&measure->converth);
160 }
161 
162 float inline get_converts(){
163  return pgm_read_float(&measure->converts);
164 }
165 
166 float inline mul_converth(float f){
167  return get_converth() * f;
168 }
169 
170 
171 float inline mul_converts(float &f){
172  return f * get_converts();
173 }
174 
175 float inline f_div1000(float f){
176  return f/1000;
177 }
178 
179 uint16_t inline time_since(uint32_t *t){
180  return (uint16_t)(millis() - *t); // loop time no more 1000 ms
181 
182 }
183 void inline float_add(float &dst, float val){
184  dst+=val;
185 }
186 void inline calc_max(float &dst, float src){
187  if (dst < src) dst = src;
188 
189 }
190 void inline gps_norm(float &dst, long f){
191  dst = f / GPS_MUL;
192 }
193 
194 bool inline timeToScreen(){ // we should renew screen
195  return lflags.need_redraw && !vsync_wait;
196 }
197 
#define GPS_MUL
Definition: prototypes.h:46
const char * PGM_P
Definition: compat.h:23
void(* cb_putc)(uint8_t c)
Definition: prototypes.h:3
static void osd_print_S(PGM_P f)
Definition: Config_Func.h:46
static void delay_byte()
Definition: Config_Func.h:55
static void delayMicroseconds(uint16_t us)
Definition: compat.h:82
void calc_max(float &dst, float src)
Definition: Config_Func.h:186
void float_add(float &dst, float val)
Definition: Config_Func.h:183
float get_converth()
Definition: Config_Func.h:158
int long_diff(uint32_t *l1, uint32_t *l2)
Definition: Config_Func.h:152
float get_converts()
Definition: Config_Func.h:162
static float pgm_read_float(const void *v)
Definition: compat.h:40
static void write(uint16_t addr, uint8_t val)
Definition: osd_eeprom.cpp:38
void NOINLINE eeprom_read_len(byte *p, uint16_t e, uint16_t l)
Definition: Config_Func.h:8
bool timeToScreen()
Definition: Config_Func.h:194
void delay_telem()
Definition: Config_Func.h:51
void millis_plus(uint32_t *dst, uint16_t inc)
Definition: Config_Func.h:143
#define f(i)
NOINLINE void eeprom_write_len(byte *p, uint16_t e, uint16_t l)
Definition: Config_Func.h:14
uint32_t millis()
Definition: system.cpp:157
void serial_hex_dump(byte *p, uint16_t len)
Definition: Config_Func.h:138
uint16_t time_since(uint32_t *t)
Definition: Config_Func.h:179
float mul_converth(float f)
Definition: Config_Func.h:166
void gps_norm(float &dst, long f)
Definition: Config_Func.h:190
float v
Definition: Printf.cpp:15
uint8_t byte
Definition: compat.h:8
static uint8_t read(uint16_t addr)
Definition: osd_eeprom.cpp:34
int16_t osd_available()
static float degrees(float v)
Definition: Config_Func.h:42
#define NOINLINE
Definition: AP_Common.h:37
#define TELEMETRY_SPEED
Definition: Config.h:35
float f_div1000(float f)
Definition: Config_Func.h:175
void print_eeprom_string(byte n, cb_putc cb)
Definition: Config_Func.h:23
const struct Measure * measure
float mul_converts(float &f)
Definition: Config_Func.h:171
void long_plus(uint32_t *dst, uint16_t inc)
Definition: Config_Func.h:148