void BatteryCheck_Task(void * pvParameters) {
	uint16_t vbat;
	uint8_t safe_counter = 0;
	uint8_t normal_counter = 0;

	vTaskDelay(3 * delay_time_based);
	printf("Battery Check Task activated \r\n");

	while (1) {
		vbat = battery_read();
		printf("vbat = %" PRIu16 " mV\t", vbat);

		if (HK_frame.mode_status_flag == safe_mode) {
			while (1) {
				vTaskDelay(30 * delay_time_based);
				vbat = battery_read();
				printf("(safe)vbat = %04u mV \t", vbat);
				if ( (int)vbat > (int)parameters.vbat_recover_threshold) {
					safe_counter ++;
					printf("Batt outcounter = %d\n", safe_counter);
					if (safe_counter >= 6) {
						safe_counter = 0;
						Leave_safe_mode();
						break;
					}
				}
				else {
					printf("\n");
					safe_counter = 0;
				}
			}
		}
		else {
			if ( (int) vbat < (int) parameters.vbat_safe_threshold && vbat != 0) {
				normal_counter ++;
				printf("Batt outcounter = %d\n", normal_counter);
				if (normal_counter >= 6) {
					printf("safe mode detected\n");
					generate_Error_Report(1, vbat);
					HK_frame.mode_status_flag = safe_mode;
					normal_counter = 0;
				}
			}
			else {
				printf("\n");
				normal_counter = 0;
			}
		}
		vTaskDelay(30 * delay_time_based);
	}
	/** End of Task, Should Never Reach This */
	vTaskDelete(NULL);
}
Exemplo n.º 2
0
int main(void)
{
    char buf[16];
    char labels[2][16] = {
        "Luftdruck",
        "Windgeschw.",
    };
    char units[2][16] = {
        "Pa",
        "m/s",
    };
    float (*functions[2]) () = {
        barometer_read,
        anemometer_read,
    };

    init();
    while(1)
    {
        lcd_set_battery_level(battery_read());
        float2string(buf, functions[selection]());
        sprintf(buf, "%s %s", buf, units[selection]);
        lcd_set_label(labels[selection], buf);
        lcd_update();
    }
    return 0;
}
Exemplo n.º 3
0
void battery_set_wakeup_percentage(bool charging, bool suspend)
{
	int battlowpercent[] = {20,13,11,9,6,5,4,3,2,1,0};
	nyx_battery_status_t batt;
	int nextchk = 0,i = 0;

	if(!battDev)
		return;

	POWERDLOG(LOG_DEBUG, "In %s\n",__FUNCTION__);
	battery_read(&batt);
	sendBatteryStatus();

	if(charging) {
		nextchk = 0;
	}
	else if(suspend) {
		for(i=0; battlowpercent[i]!=0; i++) {
			if(batt.percentage > battlowpercent[i])
			{
				nextchk=battlowpercent[i];
				break;
			}
		}
	}
	else
		nextchk=batt.percentage;

	POWERDLOG(LOG_DEBUG, "Setting percent limit to %d\n",nextchk);

	nyx_battery_set_wakeup_percentage(battDev, nextchk);
}
Exemplo n.º 4
0
static BatteryState StateAuthenticOrNot(void)
{
    nyx_battery_status_t battery;

    battery_read(&battery);

    if(ChargerIsCharging() && battery.current <= 0 )
    {
    	POWERDLOG(LOG_INFO,"%d: BATTERY DISCHARGING ....",discharge_count);
    	discharge_count++;
    }
    else
    	discharge_count = 0;

    if(discharge_count == MAX_DISCHARGE_COUNT)
    {
    	POWERDLOG(LOG_CRIT,"Battery discharging while on charger");
        discharge_count = 0;
    }

    if(!battery.present)
    {
        return kBatteryDebounce;
    }

    if(sample_is_new(&battery))
    	sendBatteryStatus();

    return kBatteryLast;
}
Exemplo n.º 5
0
/**
 * @brief State "removed".
 */
static BatteryState StateRemoved(void)
{
    nyx_battery_status_t battery;

    battery_read(&battery);

    if (battery.present)
        return kBatteryInserted;
    else
        return kBatteryLast;
}
Exemplo n.º 6
0
static BatteryState StateDebounce(void)
{
    static int debounce_bad = 0;
    nyx_battery_status_t battery;

    battery_read(&battery);
    if (battery.present) {
        debounce_bad = 0;
        return kBatteryInserted;
    }
    else if (++debounce_bad > BAD_SAMPLES_THRESHOLD) {

        POWERDLOG(LOG_INFO, "Battery has been removed.\n");
        battery_search(true);
        return kBatteryRemoved;
    }
    return kBatteryLast;
}