factor out gpio pulse logic