I'm thinking read the input every 100mS, have a counter for high or low.
If see it high 10 times, call it solid high.
If see it low 10 times, call it solid low.
If see if change one way or the other after starting a count, set a possibly_variable flag.
if the count then stays high or low, go back to calling it solid high or low.
If the level changes a 2nd time, call it variable.
Keep wathing to see that it keeps changing, and when it stops, go back to the solid high/low state.