/* This function loops forever --------------------------------------------*/
void loop()
{
	if (millis() - old_time >= 500){
		socValue = FUEL.getSoC();

		PMIC.setInputCurrentLimit(500);
	//D0 to D7
		for(uint8_t i = 0;i<8;i++){
			digitalWrite(i,!digitalRead(i));
		}

		//A0 to A5
		for(uint8_t i = 10;i<17;i++){
			digitalWrite(i,!digitalRead(i));
		}

		//B0 to B5, C0 to C5
		for(uint8_t i = 24;i<36;i++){
			digitalWrite(i,!digitalRead(i));
		}
		old_time = millis();
	}

	if (millis() - pubSoc >= 5*60000){
		Particle.publish("soc"+deviceName, String(FUEL.getSoC()), 120, PRIVATE);
		pubSoc = millis();
	}

}
/* This function is called once at start up ----------------------------------*/
void setup()
{
	if (System.deviceID() == "5b0033000e51343035353132")
		deviceName = "-3g";

	RGB.brightness(10);
	Serial.begin(9600);
	PMIC.begin();
	FUEL.quickStart();
	Serial.println("");

	//D0 to D7
	for(uint8_t i = 0;i<8;i++){
		pinMode(i,OUTPUT);
		digitalWrite(i,LOW);
	}

	//A0 to A5
	for(uint8_t i = 10;i<17;i++){
		pinMode(i,OUTPUT);
		digitalWrite(i,LOW);
	}

	//B0 to B5, C0 to C5
	for(uint8_t i = 24;i<36;i++){
		pinMode(i,OUTPUT);
		digitalWrite(i,LOW);
	}

	electronMDM.setDebug(3); // enable this for debugging issues

	delay(3000);
    DEBUG_D("\e[0;36mHello from the Electron! Boot time is: %d\r\n",millis());

	Particle.connect(); // blocking call to connect

	//Register all the Tinker functions
	Particle.function("digitalread", tinkerDigitalRead);
  Particle.function("digitalwrite", tinkerDigitalWrite);

	Particle.function("analogread", tinkerAnalogRead);
	Particle.function("analogwrite", tinkerAnalogWrite);
	Particle.variable("soc",&socValue,DOUBLE);
	Particle.variable("test","test-string",STRING);

	PMIC.setInputCurrentLimit(150);
}
示例#3
0
void updatePower(void) {

    //Serial1.println("Setting input voltage limit");
    //power.setInputVoltageLimit(4);
    //delay(50);

    Serial1.println("Setting input current limit");
    power.setInputCurrentLimit(500);
    delay(50);

    //Serial1.println("Force DPDM detection");
    //power.enableDPDM();
    //delay(500);

    //Serial1.println("Forcing charge enable");
    //power.enableCharging();
    //delay(50);

    //Serial1.println("Enabling the buck regulator");
    //power.enableBuck();
    //delay(50);

    //This will run in a loop
    Serial1.print("Power good: ");
    Serial1.println(power.isPowerGood());

    Serial1.print("System Status: ");
    Serial1.println(power.getSystemStatus(), BIN);

    byte status = 0;
    status = power.getSystemStatus();
    if (status & 0b00000001) Serial1.println("In regulation: YES");
    else Serial1.println("In regulation: NO");

    //if (status & 0b00000010) Serial1.println("HOT");
    //else Serial1.println("Normal");

    if (status & 0b00000100) Serial1.println("Power: Good");
    else Serial1.println("Power: Bad");

    if (status & 0b00000100) Serial1.println("In DPM mode: YES");
    else Serial1.println("In DPM mode: NO");

    if ((status & 0b00110000) == 0x00) //00
        Serial1.println("Not charging");
    if ((status & 0b00110000) == 0x30) //11
        Serial1.println("Charge termination done");
    if ((status & 0b00110000) == 0x10) //01
        Serial1.println("Pre charging");
    if ((status & 0b00110000) == 0x20) //10
        Serial1.println("Fast charging");

    if ((status & 0b11000000) == 0x00) //00
        Serial1.println("no input/dpdm detection incomplete");
    if ((status & 0b11000000) == 0x40) //01
        Serial1.println("USB Host");
    if ((status & 0b11000000) == 0x80) //10
        Serial1.println("Adaptor Port");
    if ((status & 0b11000000) == 0xC0) //11
        Serial1.println("OTG");



    Serial1.print("Input Register: ");
    Serial1.println(power.readInputSourceRegister(), BIN);

    Serial1.print("Term/Timer Register: ");
    Serial1.println(power.readChargeTermRegister(), BIN);

    Serial1.print("Misc Operation Register: ");
    Serial1.println(power.readOpControlRegister(), BIN);

    Serial1.print("Charge current control register: ");
    Serial1.println(power.getChargeCurrent(), BIN);

    Serial1.println(" ---------- ");

    delay(2000);
}