int SetBacklight() { int bvalue; printf("[LPMTd] :: Set backlight level to "); if(GetPowerState() == POWER_ON_BATTERY) { GetConfig("BACKLIGHT_BAT_VALUE", &bvalue); } else { GetConfig("BACKLIGHT_AC_VALUE", &bvalue); } if(bvalue > backlightMaxValue) { bvalue = backlightMaxValue; } printf("%d ", bvalue); FILE* fd = fopen(brightnessPath, "w"); if(!fd) { printf("[ FAIL ]\n"); return -1; } fprintf(fd, "%d", bvalue); fclose(fd); printf("[ OK ]\n"); return 0; }
int main() { printf("[LPMTd] :: Linux Power Management Tool v1.0\n"); signal(SIGTERM, signal_term); if(LoadConfig(CONFIG_FILE_PATH) || UPowerConnect() || FetchBacklightInfo() || FetchCpuInfo() || UpdatePowerState() || SetBacklight() || SetHDD_APM() || SetCpuFreq()) { printf("[LPMTd] :: Exit status (-1)\n"); return -1; } int new_pstate = WaitUPowerStateChange(); while(new_pstate >= 0) { if(new_pstate != GetPowerState()) { SetPowerState(new_pstate); if(SetBacklight() || SetHDD_APM() || SetCpuFreq()) { printf("[LPMTd] :: Exit status (-1)\n"); return -1; } } new_pstate = WaitUPowerStateChange(); } UPowerDisconnect(); ClearConfig(); printf("[LPMTd] :: Exit status (0)\n"); return 0; }
int SetHDD_APM() { unsigned int apm; char* select; if(GetPowerState() == POWER_ON_BATTERY) { GetConfig("APM_BAT_VALUE", &apm); } else { GetConfig("APM_AC_VALUE", &apm); } GetConfig("APM_SELECT_DEVICE", &select); if(!strcmp(select, "all-scsi")) { char *id = "abcdefgh"; unsigned int i; for(i = 0; i < 8; i++) { char dev[10]; sprintf(dev, "/dev/sd%c", id[i]); if(!access(dev, F_OK)) { printf("[LPMTd] :: Set APM level for SCSI device <%s> to %d ", dev, apm); if(ExecHdparm(dev, apm)) { printf("[ FAIL ]\n"); } else { printf("[ OK ]\n"); } } } } else { printf("[LPMTd] :: Set APM level for block device <%s> to %d ", select, apm); if(!access(select, F_OK)) { if(ExecHdparm(select, apm)) { printf("[ FAIL ]\n"); return -1; } else { printf("[ OK ]\n"); } } else { printf("[ FAIL ]\n"); return -1; } } return 0; }
bool FirewireChannel::Retune(void) { LOG(VB_CHANNEL, LOG_INFO, LOC + "Retune()"); if (FirewireDevice::kAVCPowerOff == GetPowerState()) { LOG(VB_GENERAL, LOG_ERR, LOC + "STB is turned off, must be on to retune."); return false; } if (current_channel) { QString freqid = QString::number(current_channel); return Tune(freqid, 0); } return false; }
bool FirewireChannel::Tune(const QString &freqid, int /*finetune*/) { LOG(VB_CHANNEL, LOG_INFO, QString("Tune(%1)").arg(freqid)); bool ok; uint channel = freqid.toUInt(&ok); if (!ok) return false; if (FirewireDevice::kAVCPowerOff == GetPowerState()) { LOG(VB_GENERAL, LOG_WARNING, LOC + "STB is turned off, must be on to set channel."); return true; // signal monitor will call retune later... } if (!device->SetChannel(fw_opts.model, 0, channel)) return false; current_channel = channel; return true; }