// save a fence point
void AP_Limit_Geofence::set_fence_point_with_index(Vector2l &point, uint8_t i)
{
    if (i >= (unsigned)fence_total()) {
        // not allowed
        return;
    }

    _storage.write_uint32(i * 8, point.x);
    _storage.write_uint32(i * 8+4, point.y);

    _boundary_uptodate = false;
}
/*
 *  fence boundaries fetch/store
 */
Vector2l AP_Limit_Geofence::get_fence_point_with_index(uint8_t i)
{
    Vector2l ret;

    if (i > (unsigned) fence_total()) {
        return Vector2l(0,0);
    }

    // read fence point
    ret.x = _storage.read_uint32(i * 8);
    ret.y = _storage.read_uint32(i * 8+4);

    return ret;
}
/*
 *  fence boundaries fetch/store
 */
Vector2l AP_Limit_Geofence::get_fence_point_with_index(uint8_t i)
{
    uintptr_t mem;
    Vector2l ret;

    if (i > (unsigned) fence_total()) {
        return Vector2l(0,0);
    }

    // read fence point
    mem = _eeprom_fence_start + (i * _fence_wp_size);
    ret.x = EPROM->eeprom_read_dword((uint32_t *)mem);
    mem += sizeof(uint32_t);
    ret.y = EPROM->eeprom_read_dword((uint32_t *)mem);

    return ret;
}
// save a fence point
void AP_Limit_Geofence::set_fence_point_with_index(Vector2l &point, uint8_t i)
{
    uintptr_t mem;

    if (i >= (unsigned)fence_total()) {
        // not allowed
        return;
    }

    mem = _eeprom_fence_start + (i * _fence_wp_size);

    EPROM->eeprom_write_dword((uint32_t *)mem, point.x);
    mem += sizeof(uint32_t);
    EPROM->eeprom_write_dword((uint32_t *)mem, point.y);

    _boundary_uptodate = false;
}