Text this: Melnikov functions and limit cycle bifurcations for a class of piecewise Hamiltonian systems