+ protected List<VibratorState> states;
+
+ public Vibrator() throws FileError
+ {
+ if (vibrator.init("neo1973:vibrator") != 0)
+ throw new FileError.NOENT("vibrator not found");
+
+ states = new List<VibratorState>();
+ }
+
+ public void turn_off()
+ {
+ vibrator.brightness = 0;
+ Memory.copy(vibrator.trigger, "none", 5);
+ vibrator.set();
+ }
+
+ public void push_state(VibratorState state)
+ {
+ states.prepend(state);
+ state.to_omhacks(ref vibrator);
+ vibrator.set();
+ }
+
+ public void pop_state(string name)
+ {
+ // Handle empty list
+ if (states == null) return;
+
+ // Track if the list head changed
+ weak List<VibratorState> old_top = states;
+
+ // Remove state "name" from the stack
+ for (weak List<VibratorState> i = states; i != null; i = i.next)
+ if (i.data.name == name)
+ {
+ states.delete_link(i);
+ break;
+ }
+
+ // If the list head changed, put into action the new top state
+ if (states != old_top)
+ if (states == null)
+ turn_off();
+ else {
+ // Activate the new top
+ states.data.to_omhacks(ref vibrator);
+ vibrator.set();
+ }
+ }
+
+ public void shutdown()
+ {
+ while (states != null)
+ states.delete_link(states);
+ turn_off();
+ }
+}
+
+public class Audio: zavai.Service
+{