31 #define IRLOCK_I2C_ADDRESS 0x54 33 #define IRLOCK_SYNC 0xAA55AA55 49 printf(
"Starting IRLock on I2C\n");
61 if (!
dev->
transfer(
nullptr, 0, (uint8_t *)&sync_word, 4)) {
69 while (count-- && sync_word !=
IRLOCK_SYNC && sync_word != 0) {
77 sync_word = (sync_word>>8) | (uint32_t(sync_byte)<<24);
88 ret_x = (-0.00293875727162397f*pix_x + 0.470201163459835f)/(4.43013552642296e-6
f*((pix_x - 160.0
f)*(pix_x - 160.0
f)) +
89 4.79331390531725e-6
f*((pix_y - 100.0f)*(pix_y - 100.0
f)) - 1.0
f);
90 ret_y = (-0.003056843086277f*pix_y + 0.3056843086277f)/(4.43013552642296e-6
f*((pix_x - 160.0
f)*(pix_x - 160.0f)) +
91 4.79331390531725e-6
f*((pix_y - 100.0f)*(pix_y - 100.0
f)) - 1.0
f);
99 if (!
dev->
transfer(
nullptr, 0, (uint8_t*)&irframe,
sizeof(irframe))) {
107 uint32_t crc = irframe.signature + irframe.pixel_x + irframe.pixel_y + irframe.pixel_size_x + irframe.pixel_size_y;
108 if (crc != irframe.checksum) {
120 struct frame irframe;
131 float corner1_pos_x, corner1_pos_y, corner2_pos_x, corner2_pos_y;
147 static uint32_t lastt;
150 printf(
"pos_x:%.5f pos_y:%.5f size_x:%.6f size_y:%.5f\n",
160 bool new_data =
false;
int printf(const char *fmt,...)
#define IRLOCK_I2C_ADDRESS
virtual PeriodicHandle register_periodic_callback(uint32_t period_usec, PeriodicCb)=0
#define HAL_SEMAPHORE_BLOCK_FOREVER
virtual bool take(uint32_t timeout_ms) WARN_IF_UNUSED=0
virtual Semaphore * new_semaphore(void)
irlock_target_info _target_info
void init(int8_t bus) override
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
virtual bool transfer(const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len)=0
AP_HAL::I2CDeviceManager * i2c_mgr
void pixel_to_1M_plane(float pix_x, float pix_y, float &ret_x, float &ret_y)
bool read_block(struct frame &irframe)
struct IRLock::AP_IRLock_Flags _flags
#define FUNCTOR_BIND_MEMBER(func, rettype,...)
virtual OwnPtr< AP_HAL::I2CDevice > get_device(uint8_t bus, uint8_t address, uint32_t bus_clock=400000, bool use_smbus=false, uint32_t timeout_ms=4)=0
AP_HAL::OwnPtr< AP_HAL::Device > dev
bool sync_frame_start(void)