| 1665 | } |
| 1666 | |
| 1667 | void WBLink::wt_perform_update_thermal_protection() { |
| 1668 | if (!OHDPlatform::instance().is_x20()) { |
| 1669 | if (complainOnce = 0) { |
| 1670 | m_console->debug("thermal_protection, function started"); |
| 1671 | complainOnce = 1; |
| 1672 | } |
| 1673 | return; |
| 1674 | } |
| 1675 | if (OHDFilesystemUtil::exists(std::string(getConfigBasePath()) + |
| 1676 | "disable_thermal_limits.txt")) { |
| 1677 | m_thermal_protection_level = THERMAL_PROTECTION_NONE; |
| 1678 | return; |
| 1679 | } |
| 1680 | auto temp = openhd::x20_read_rtl8812au_thermal_sensor_degree(); |
| 1681 | if (temp <= 0) { |
| 1682 | m_thermal_protection_level = THERMAL_PROTECTION_NONE; |
| 1683 | return; |
| 1684 | } |
| 1685 | static auto THERMAL_LIMIT_VIDEO_REDUCED = 85; |
| 1686 | static auto THERMAL_LIMIT_VIDEO_OFF = 95; |
| 1687 | uint8_t new_thermal_protection_level; |
| 1688 | if (temp >= THERMAL_LIMIT_VIDEO_OFF) { |
| 1689 | // >=X degree, disable video |
| 1690 | new_thermal_protection_level = THERMAL_PROTECTION_VIDEO_DISABLED; |
| 1691 | } else if (temp >= THERMAL_LIMIT_VIDEO_REDUCED) { |
| 1692 | // >=X degree, throttle video |
| 1693 | new_thermal_protection_level = THERMAL_PROTECTION_RATE_REDUCED; |
| 1694 | } else { // no thermal protection |
| 1695 | new_thermal_protection_level = THERMAL_PROTECTION_NONE; |
| 1696 | } |
| 1697 | if (new_thermal_protection_level > m_thermal_protection_level) { |
| 1698 | // apply immediately |
| 1699 | m_thermal_protection_level = new_thermal_protection_level; |
| 1700 | m_thermal_protection_enable_tp = std::chrono::steady_clock::now(); |
| 1701 | } else if (new_thermal_protection_level < m_thermal_protection_level) { |
| 1702 | const auto elapsed_since_thermal_protection_enabled = |
| 1703 | std::chrono::steady_clock::now() - m_thermal_protection_enable_tp; |
| 1704 | // Every time some type of thermal protection is activated, it stays active |
| 1705 | // for at least X seconds to avoid oscillating |
| 1706 | if (elapsed_since_thermal_protection_enabled < std::chrono::seconds(10)) { |
| 1707 | return; |
| 1708 | } |
| 1709 | if (m_thermal_protection_level == THERMAL_PROTECTION_VIDEO_DISABLED) { |
| 1710 | // When video streaming is disabled, we only re-enable it once we have |
| 1711 | // cooled down significantly |
| 1712 | if (temp <= 70) { |
| 1713 | m_thermal_protection_level = new_thermal_protection_level; |
| 1714 | } |
| 1715 | } else { |
| 1716 | m_thermal_protection_level = new_thermal_protection_level; |
| 1717 | } |
| 1718 | } |
| 1719 | } |
nothing calls this directly
no test coverage detected