/* ADS7844 register emulation Code by Andrew Tridgell November 2011 */ #ifndef _SITL_ADC_H #define _SITL_ADC_H #include #define NOISE_BITS 4 static inline float noise_generator(void) { float noise = ((unsigned)random()) & ((1<= 0x1000) { next_value = 0xFFF; } next_value = (next_value << 3); return *this; } /* read from UDR2 fetches a byte from the channel */ operator int() { uint8_t ret; if (idx & 1) { ret = (value&0xFF); value = next_value; } else { ret = (value>>8); } idx ^= 1; return ret; } /* interface to set a channel value from SITL */ void set(uint8_t i, float v) { channels[i] = v; } }; #endif // _SITL_ADC_H