public static void MainMenu(SerialInputItem item) { var SystemStatus = new ArrayList(); _status.Display(SystemStatus, _clock, _schedule); _serialUI.Stop(); _serialUI.AddDisplayItem(Divider); _serialUI.AddDisplayItem(SystemStatus); _serialUI.AddDisplayItem("\r\n"); _serialUI.AddDisplayItem("Main Menu:\r\n"); _serialUI.AddInputItem(new SerialInputItem { Option = "1", Label = ": Show Schedule", Callback = ShowSchedule }); _serialUI.AddInputItem(new SerialInputItem { Option = "2", Label = ": Set Schedule", Callback = SetSchedule }); _serialUI.AddInputItem(new SerialInputItem { Option = "3", Label = ": Set Clock", Callback = SetClock, Context = 0 }); _serialUI.AddInputItem(new SerialInputItem { Option = "4", Label = ": Swith Heater ON / Resume Schedule", Callback = SwitchHeaterOn }); _serialUI.AddInputItem(new SerialInputItem { Option = "X", Label = ": Shutdown", Callback = Shutdown }); _serialUI.AddInputItem(new SerialInputItem { Callback = RefreshMainMenu }); _serialUI.Go(); }
public static void SwitchHeaterOn(SerialInputItem item) { Log("Switching heater state, please wait..."); _schedule.WaterHeaterManualOverride ^= true; _scheduleChange = true; RefreshMainMenu(null); while (_scheduleChange == true) { Thread.Sleep(10); } }
public static void ShowSchedule(SerialInputItem item) { var scheduleList = new ArrayList(); _schedule.Display(scheduleList); _serialUI.Stop(); _serialUI.AddDisplayItem(Divider); _serialUI.AddDisplayItem(scheduleList); _serialUI.Go(); RefreshMainMenu(null); }
public static void SetClock(SerialInputItem item) { _serialUI.Stop(); switch (item.Context) { case 0: _serialUI.Store.Clear(); _serialUI.AddDisplayItem(Divider); _serialUI.AddDisplayItem("Set Clock:\r\n"); _serialUI.AddInputItem(new SerialInputItem { Label = "Year (YYYY)?", Callback = SetClock, Context = 1, StoreKey = "clock.YYYY" }); break; case 1: _serialUI.AddInputItem(new SerialInputItem { Label = "Month (01-12)?", Callback = SetClock, Context = 2, StoreKey = "clock.MM" }); break; case 2: _serialUI.AddInputItem(new SerialInputItem { Label = "Day (01-31)?", Callback = SetClock, Context = 3, StoreKey = "clock.DD" }); break; case 3: _serialUI.AddInputItem(new SerialInputItem { Label = "Hour (00-23)?", Callback = SetClock, Context = 4, StoreKey = "clock.HH" }); break; case 4: _serialUI.AddInputItem(new SerialInputItem { Label = "Minute (00-59)?", Callback = SetClock, Context = 5, StoreKey = "clock.MN" }); break; case 5: _serialUI.AddInputItem(new SerialInputItem { Label = "Second (00-59)?", Callback = SetClock, Context = 6, StoreKey = "clock.SS" }); break; case 6: try { var dt = new DateTime( ToInt("clock.YYYY"), ToInt("clock.MM"), ToInt("clock.DD"), ToInt("clock.HH"), ToInt("clock.MN"), ToInt("clock.SS")); try { _clock.Set(dt); _scheduleChange = true; } catch (Exception e) { Log("Failed to set the clock. Exception: " + e); } } catch (Exception e) { Log("Invalid date/time input exception: " + e); } _serialUI.Store.Clear(); RefreshMainMenu(null); return; } _serialUI.Go(); }
public static void SetSchedule(SerialInputItem item) { _serialUI.Stop(); switch (item.Context) { case 0: _serialUI.Store.Clear(); _serialUI.AddDisplayItem(Divider); _serialUI.AddDisplayItem("Set Heater Weekly Schedule:\r\n"); _serialUI.AddInputItem(new SerialInputItem { Label = GetDayOfWeekSelectionString(), Callback = SetSchedule, Context = 1, StoreKey = "sched.dow" }); break; case 1: var timeslotList = new ArrayList(); var dow = ToInt("sched.dow"); if (dow >= 0 && dow <= 6) { _serialUI.AddDisplayItem("Select '" + _schedule.DayList[dow] + "' timeslot\r\n"); var slotCount = _schedule.GetDayTimeSlotList((DayOfWeek)dow, timeslotList); slotCount -= 1; _serialUI.Store["sched.maxSlot"] = slotCount.ToString(); _serialUI.AddDisplayItem(timeslotList); var slotSelection = "Timeslot (0-" + slotCount.ToString() + ")?"; _serialUI.AddInputItem(new SerialInputItem { Label = slotSelection, Callback = SetSchedule, Context = 2, StoreKey = "sched.timeSlot" }); } else { Log("Invalid week day input."); _serialUI.Store.Clear(); RefreshMainMenu(null); return; } break; case 2: var maxSlot = ToInt("sched.maxSlot"); var timeSlot = ToInt("sched.timeSlot"); if (timeSlot >= 0 && timeSlot <= maxSlot) { _serialUI.AddInputItem(new SerialInputItem { Label = "Begin Hour (00-23)?", Callback = SetSchedule, Context = 3, StoreKey = "sched.beginHour" }); } else { Log("Invalid timeslot input."); _serialUI.Store.Clear(); RefreshMainMenu(null); return; } break; case 3: _serialUI.AddInputItem(new SerialInputItem { Label = "End Hour (00-23)?", Callback = SetSchedule, Context = 4, StoreKey = "sched.endHour" }); break; case 4: _serialUI.AddInputItem(new SerialInputItem { Label = "Is this timeslot the same all week (Y/N)?", Callback = SetSchedule, Context = 5, StoreKey = "sched.sameAllWeek" }); break; case 5: var dayOfWeek = ToInt("sched.dow"); var timeSlotIndex = ToInt("sched.timeSlot"); var beginHour = ToInt("sched.beginHour"); var endHour = ToInt("sched.endHour"); var sameAllWeek = (string)_serialUI.Store["sched.sameAllWeek"]; var validTimeSlot = true; if ((beginHour >= 0 && beginHour <= 23) && (endHour >= 0 && endHour <= 23)) { if (beginHour > endHour && endHour == 0 || beginHour <= endHour) { validTimeSlot = true; } else { validTimeSlot = false; } } else { validTimeSlot = false; } if (validTimeSlot == false) { Log("Invalid Begin/End hour input."); Log("Hours must be between 0 and 23."); Log("Begin hour must be <= to End hour except if End hour is 0."); _serialUI.Store.Clear(); RefreshMainMenu(null); return; } if (sameAllWeek.ToLower() == "y") { _schedule.SetTimeSlot((DayOfWeek)dayOfWeek, timeSlotIndex, beginHour, endHour, true); } else { _schedule.SetTimeSlot((DayOfWeek)dayOfWeek, timeSlotIndex, beginHour, endHour, false); } SaveSchedule(); _serialUI.Store.Clear(); RefreshMainMenu(null); return; } _serialUI.Go(); }
public static void RefreshMainMenu(SerialInputItem item) { _showMainMenu = true; }
public static void Shutdown(SerialInputItem item) { _shutdown = true; }