function [value,isterminal,direction] = vteamEvents(t,w,p)
  
  Rm=(p.Roff*(w-p.won)+p.Ron*(p.woff-w))/(p.woff-p.won);
  vm=p.u(t)*Rm/(Rm+p.R);
  if p.Region==1
    value = [vm-p.voff;w-p.woff];
    isterminal = [1; 1]; % all events are terminal
    direction = [-1;+1]; % -1/+1 - the value is decreasing/increasing
  end
  if p.Region==2
    value = [vm-p.von;w-p.won];
    isterminal = [1; 1]; % all events are terminal
    direction = [+1;-1]; % -1/+1 - the value is decreasing/increasing
  end
  if p.Region==3
    value = [vm-p.voff;vm-p.von];
    isterminal = [1; 1]; % all events are terminal
    direction = [+1;-1]; % -1/+1 - the value is decreasing/increasing
  end
  if p.Region==4
    value = [vm-p.von];
    isterminal = [1]; % all events are terminal
    direction = [-1]; % -1/+1 - the value is decreasing/increasing
  end
  if p.Region==5
    value = [vm-p.voff];
    isterminal = [1]; % all events are terminal
    direction = [+1]; % -1/+1 - the value is decreasing/increasing
  end

