aboutsummaryrefslogtreecommitdiffhomepage
path: root/source/Core/Threads/OperatingModes/Sleep.cpp
blob: ec97c252464a71c5a040bc180e8d295df29534da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "OperatingModes.h"

OperatingMode gui_SolderingSleepingMode(const ButtonState buttons, guiContext *cxt) {
#ifdef NO_SLEEP_MODE
  return OperatingMode::Soldering;
#endif
  // Drop to sleep temperature and display until movement or button press

  // user moved or pressed a button, go back to soldering
  // If in the first two seconds we disable this to let accelerometer warm up

#ifdef POW_DC
  if (checkForUnderVoltage()) {
    return OperatingMode::HomeScreen; // return non-zero on error
  }
#endif

  if (cxt->scratch_state.state4) {
    // Hibernating mode
    currentTempTargetDegC = 0;
  } else {
    if (getSettingValue(SettingsOptions::TemperatureInF)) {
      currentTempTargetDegC = TipThermoModel::convertFtoC(min(getSettingValue(SettingsOptions::SleepTemp), getSettingValue(SettingsOptions::SolderingTemp)));
    } else {
      currentTempTargetDegC = min(getSettingValue(SettingsOptions::SleepTemp), getSettingValue(SettingsOptions::SolderingTemp));
    }
  }
  // draw the lcd
  uint16_t tipTemp = getSettingValue(SettingsOptions::TemperatureInF) ? TipThermoModel::getTipInF() : TipThermoModel::getTipInC();

  OLED::clearScreen();
  OLED::setCursor(0, 0);
  if (getSettingValue(SettingsOptions::DetailedSoldering)) {
    OLED::print(translatedString(Tr->SleepingAdvancedString), FontStyle::SMALL);
    OLED::setCursor(0, 8);
    OLED::print(translatedString(Tr->SleepingTipAdvancedString), FontStyle::SMALL);
    OLED::printNumber(tipTemp, 3, FontStyle::SMALL);
    if (getSettingValue(SettingsOptions::TemperatureInF)) {
      OLED::print(SmallSymbolDegF, FontStyle::SMALL);
    } else {
      OLED::print(SmallSymbolDegC, FontStyle::SMALL);
    }

    OLED::print(SmallSymbolSpace, FontStyle::SMALL);
    printVoltage();
    OLED::print(SmallSymbolVolts, FontStyle::SMALL);
  } else {
    OLED::print(translatedString(Tr->SleepingSimpleString), FontStyle::LARGE);
    OLED::printNumber(tipTemp, 3, FontStyle::LARGE);
    OLED::printSymbolDeg(FontStyle::EXTRAS);
  }

  OLED::refresh();
  GUIDelay();

  if (!shouldBeSleeping()) {
    return cxt->previousMode;
  }

  if (shouldShutdown()) {
    // shutdown
    currentTempTargetDegC = 0;
    return OperatingMode::HomeScreen;
  }
  if (cxt->scratch_state.state4) {
    return OperatingMode::Hibernating;
  } else {
    return OperatingMode::Sleeping;
  }
}