How to read information from a piecewise function?

I defined a periodic piece wise function y[x_] with some discrete steps with Piecewise command and two lists xv and yv, which are the end points and values of the pieces, respectively. y[x_] is shown below.

Then I do a shifted and linearly combined version from y[x_], e.g., ys = y[x] - 1/2 y[x - 120] - 1/2 y[x + 120]. ys[x_] is shown below.

My question is, how to "read" from the synthesized function ys the information of the end points and values of all pieces? For the example given, I would like two lists to be produced in the form of xsv = {-180, -150, -90, -30, 30, 90, 150, 180} and ysv = {-2, -1, 1, 2, 1, -1, -2}.

The code for this process is

xv = {-180, -90, 90, 180};
yv = {-1, 1, -1};
y[x_] := Piecewise[Table[{yv[[i]], xv[[i]] < Mod[x, 360, -180] < xv[[i + 1]]}, {i, Length[yv]}]];
Plot[y[x], {x, -180, 180}, Exclusions -> None]
ys = y[x] - 1/2 y[x - 120] - 1/2 y[x + 120];
Plot[ys, {x, -180, 180}, Exclusions -> None]


pw[x_] = PiecewiseExpand[ys, -180 < x < 180]


$$\begin{cases} -2 & x>150\lor x<-150 \\ -\frac{3}{2} & x=-150\lor x=150 \\ -1 & -150

Because the function is piecewise constant, we may apply the following trick to extract the discontinuities:

xsv = Join[{-180}, Union@Cases[D[pw[x], x][[1, 1, 2]], _?NumericQ, ∞], {180}]
ysv = Map[pw, MovingAverage[xsv, 2]]


{-180, -150, -90, -60, -30, 30, 60, 90, 150, 180}

{-2, -1, 1, 1, 2, 1, 1, -1, -2}

• I would like two lists to be produced in the form of xsv = {-180, -150, -90, -30, 30, 90, 150, 180} and ysv = {-2, -1, 1, 2, 1, -1, -2}. The function values at the transition points are also desired to be ignored. – nanjun Oct 31 '18 at 19:34