Ask any of my students what my favorite question is and they'll answer "What is the definition of a button tap?". I grilled them with that question until they finally understood it. A button tap is when the button is currently pressed and it wasn't pressed the last time you looked at it. That's exactly what you want. You want to transition the relay only once per button press.
Code:
static char p1_sw_top_prev = 0;
// check if the button is pressed and last loop it wasn't pressed
if ((p1_sw_top == 1) && (p1_sw_top_prev == 0))
{
// now transition your relay
if (relay1.fwd == 1)
{
relay1.fwd = 0;
relay1.rev = 1;
}
else
{
relay1.fwd = 1;
relay1.rev = 0;
}
}
p1_sw_top_prev = p1_sw_top;