Event-Driven Control and Optimization in Hybrid Systems