An infinite horizon optimal control problem for some switching systems