| 660 | } |
| 661 | |
| 662 | int AP_HAL__I2CDevice_transfer(lua_State *L) { |
| 663 | binding_argcheck(L, 3); |
| 664 | |
| 665 | AP_HAL::I2CDevice * ud = *check_AP_HAL__I2CDevice(L, 1); |
| 666 | |
| 667 | // Parse string of bytes to send |
| 668 | size_t send_len; |
| 669 | const uint8_t* send_data = (const uint8_t*)(lua_tolstring(L, 2, &send_len)); |
| 670 | |
| 671 | // Parse and setup rx buffer |
| 672 | uint32_t rx_len = get_uint8_t(L, 3); |
| 673 | uint8_t rx_data[rx_len]; |
| 674 | |
| 675 | // Transfer |
| 676 | ud->get_semaphore()->take_blocking(); |
| 677 | const bool success = ud->transfer(send_data, send_len, rx_data, rx_len); |
| 678 | ud->get_semaphore()->give(); |
| 679 | |
| 680 | if (!success) { |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | // Return a string |
| 685 | lua_pushlstring(L, (const char *)rx_data, rx_len); |
| 686 | return 1; |
| 687 | } |
| 688 | |
| 689 | #if AP_SCRIPTING_CAN_SENSOR_ENABLED |
| 690 | int lua_get_CAN_device(lua_State *L) { |
nothing calls this directly
no test coverage detected