mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 09:42:42 +01:00 
			
		
		
		
	Added alternative variable calculations
This commit is contained in:
		@@ -246,6 +246,13 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
				
			|||||||
        charge_now = 0;
 | 
					        charge_now = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!capacity_exists && charge_now_exists && charge_full_exists) {
 | 
				
			||||||
 | 
					        if (charge_full != 0) {
 | 
				
			||||||
 | 
					          capacity_exists = true;
 | 
				
			||||||
 | 
					          capacity = charge_now * 100 / charge_full;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uint32_t power_now;
 | 
					      uint32_t power_now;
 | 
				
			||||||
      bool power_now_exists;
 | 
					      bool power_now_exists;
 | 
				
			||||||
      if (fs::exists(bat / "power_now")) {
 | 
					      if (fs::exists(bat / "power_now")) {
 | 
				
			||||||
@@ -259,6 +266,20 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
				
			|||||||
        power_now = 0;
 | 
					        power_now = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!current_now_exists && power_now_exists && voltage_now_exists) {
 | 
				
			||||||
 | 
					        if (voltage_now != 0){
 | 
				
			||||||
 | 
					          current_now_exists = true;
 | 
				
			||||||
 | 
					          current_now = (uint64_t)power_now * 1000000 / (uint64_t)voltage_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!voltage_now_exists && power_now_exists && current_now_exists) {
 | 
				
			||||||
 | 
					        if (current_now != 0) {
 | 
				
			||||||
 | 
					          voltage_now_exists = true;
 | 
				
			||||||
 | 
					          voltage_now = (uint64_t)power_now * 1000000 / (uint64_t)current_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uint32_t energy_now;
 | 
					      uint32_t energy_now;
 | 
				
			||||||
      bool energy_now_exists;
 | 
					      bool energy_now_exists;
 | 
				
			||||||
      if (fs::exists(bat / "energy_now")) {
 | 
					      if (fs::exists(bat / "energy_now")) {
 | 
				
			||||||
@@ -272,6 +293,20 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
				
			|||||||
        energy_now = 0;
 | 
					        energy_now = 0;
 | 
				
			||||||
      }  
 | 
					      }  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!charge_now_exists && energy_now_exists && voltage_now_exists) {
 | 
				
			||||||
 | 
					        if (voltage_now != 0){
 | 
				
			||||||
 | 
					          charge_now_exists = true;
 | 
				
			||||||
 | 
					          charge_now = (uint64_t)energy_now * 1000000 / (uint64_t)voltage_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!voltage_now_exists && energy_now_exists && charge_now_exists) {
 | 
				
			||||||
 | 
					        if (charge_now != 0) {
 | 
				
			||||||
 | 
					          voltage_now_exists = true;
 | 
				
			||||||
 | 
					          voltage_now = (uint64_t)energy_now * 1000000 / (uint64_t)charge_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uint32_t energy_full;
 | 
					      uint32_t energy_full;
 | 
				
			||||||
      bool energy_full_exists;
 | 
					      bool energy_full_exists;
 | 
				
			||||||
      if (fs::exists(bat / "energy_full")) {
 | 
					      if (fs::exists(bat / "energy_full")) {
 | 
				
			||||||
@@ -285,6 +320,20 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
				
			|||||||
        energy_full = 0;
 | 
					        energy_full = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!charge_full_exists && energy_full_exists && voltage_now_exists) {
 | 
				
			||||||
 | 
					        if (voltage_now != 0){
 | 
				
			||||||
 | 
					          charge_full_exists = true;
 | 
				
			||||||
 | 
					          charge_full = (uint64_t)energy_full * 1000000 / (uint64_t)voltage_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!voltage_now_exists && energy_full_exists && charge_full_exists) {
 | 
				
			||||||
 | 
					        if (charge_full != 0) {
 | 
				
			||||||
 | 
					          voltage_now_exists = true;
 | 
				
			||||||
 | 
					          voltage_now = (uint64_t)energy_full * 1000000 / (uint64_t)charge_full;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uint32_t energy_full_design;
 | 
					      uint32_t energy_full_design;
 | 
				
			||||||
      bool energy_full_design_exists;
 | 
					      bool energy_full_design_exists;
 | 
				
			||||||
      if (fs::exists(bat / "energy_full_design")) {
 | 
					      if (fs::exists(bat / "energy_full_design")) {
 | 
				
			||||||
@@ -298,6 +347,20 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
				
			|||||||
        energy_full_design = 0;
 | 
					        energy_full_design = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!charge_full_design_exists && energy_full_design_exists && voltage_now_exists) {
 | 
				
			||||||
 | 
					        if (voltage_now != 0){
 | 
				
			||||||
 | 
					          charge_full_design_exists = true;
 | 
				
			||||||
 | 
					          charge_full_design = (uint64_t)energy_full_design * 1000000 / (uint64_t)voltage_now;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (!voltage_now_exists && energy_full_design_exists && charge_full_design_exists) {
 | 
				
			||||||
 | 
					        if (charge_full_design != 0) {
 | 
				
			||||||
 | 
					          voltage_now_exists = true;
 | 
				
			||||||
 | 
					          voltage_now = (uint64_t)energy_full_design * 1000000 / (uint64_t)charge_full_design;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Show the "smallest" status among all batteries
 | 
					      // Show the "smallest" status among all batteries
 | 
				
			||||||
      if (status_gt(status, _status))
 | 
					      if (status_gt(status, _status))
 | 
				
			||||||
        status = _status;
 | 
					        status = _status;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user