Skip to content

Commit

Permalink
add begin with internal update and blockly test example
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernLuig committed Dec 9, 2024
1 parent ce82d9f commit 00f1857
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 3 deletions.
26 changes: 26 additions & 0 deletions examples/serial-test-with-blockly/serial-test-with-blockly.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Code generated by senseBox Blockly on Mon Dec 09 2024 15:38:04 GMT+0100
// (Mitteleuropäische Normalzeit)

#include <SolarChargerSB041.h>;
#include <senseBoxIO.h>

SolarChargerSB041 charger;

void setup() {
SerialUSB.begin(9600);
charger.begin();
}

void loop() {
charger.update();
SerialUSB.println(charger.isChargerConnected());
SerialUSB.println(charger.getSolarPanelVoltage());
SerialUSB.println(charger.getBatteryVoltage());
SerialUSB.println(charger.isCharging());
SerialUSB.println(charger.isFastCharging());
SerialUSB.println(charger.getBatteryLevel());
SerialUSB.println(charger.isGoodInputVoltage());
SerialUSB.println(charger.isBatteryPresent());
SerialUSB.println(charger.getBatteryTemperature());
delay(1000);
}
119 changes: 119 additions & 0 deletions examples/serial-test-with-blockly/serial-test-with-blockly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<xml xmlns="https://developers.google.com/blockly/xml" board="mcu">
<block type="arduino_functions" id="QWW|$jB8+*EL;}|#uA" deletable="false" x="57" y="93">
<data>mcu</data>
<statement name="SETUP_FUNC">
<block type="init_serial_monitor" id="nEsHJKo+=*Mg,cc=q/FJ">
<field name="SERIAL_ID">SerialUSB</field>
<field name="SPEED">9600</field>
</block>
</statement>
<statement name="LOOP_FUNC">
<block type="print_serial_monitor" id=",`jaH4;5(YijV927u^I)">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="Je+3@%}!AZ}^1|Znl~gE">
<field name="MEASUREMENT">isChargerConnected</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="%Y0SXpaiCtVlO`cV=HPl">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id=";aEDSG{h0B))vvDi1`~=">
<field name="MEASUREMENT">getSolarPanelVoltage</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="aq,-(Pg:BR=!/VV3goWv">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="8?yR6%Q1G(54=k0QRTCm">
<field name="MEASUREMENT">getBatteryVoltage</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="s3[km^j3gJz;$j/K#nB]">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="9ngshxkaUwCDxKWWw6Z+">
<field name="MEASUREMENT">isCharging</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id=";.,o+3n:l/?e9#6d+hyu">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="yttMb/{7e*[18Cj!!NP}">
<field name="MEASUREMENT">isFastCharging</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="`:t7SQK?zt!u.KeOP(FL">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id=")}tt[W*BQpLubb6_gkeF">
<field name="MEASUREMENT">getBatteryLevel</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="z=FLu-4x2dK(SKpoA5-:">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="vHOf]NwRb:tq#aY#aq+3">
<field name="MEASUREMENT">isGoodInputVoltage</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="L=I+stWnjpEUG)CXGvAA">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="z`-jzmA:RQHEdFO@=Y4h">
<field name="MEASUREMENT">isBatteryPresent</field>
</block>
</value>
<next>
<block type="print_serial_monitor" id="mAP+k}yh^-E50Y4rm.I`">
<field name="SERIAL_ID">SerialUSB</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="sensebox_solar_charger_SB041" id="[Pg8nO,LZf1xb#5@}jUA">
<field name="MEASUREMENT">getBatteryTemperature</field>
</block>
</value>
<next>
<block type="time_delay" id="3SO2|~do5uzp+1Dsc?RI">
<value name="DELAY_TIME_MILI">
<block type="math_number" id="e}clfG`QACY.BeMeubbv">
<field name="NUM">1000</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</xml>
5 changes: 2 additions & 3 deletions examples/serial-test/serial-test.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <SolarChargerSB041.h>
#include <Wire.h>
// #include <senseBoxIO.h> // only needer fo senseBox MCU
#include <senseBoxIO.h> // only needer fo senseBox MCU

SolarChargerSB041 charger;

void setup() {
Wire.begin();
charger.begin();
Serial.begin(9600);
}

Expand Down
5 changes: 5 additions & 0 deletions src/SolarChargerSB041.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ SolarChargerSB041::SolarChargerSB041(uint8_t address)
batteryPresent(false),
batteryTemperature(-1) {}

void SolarChargerSB041::begin() {
Wire.begin();
SolarChargerSB041::update();
}

/*
* I2C i/f with following info on address 0x32:
* - Register 0: cell voltage, 20mV/LSB
Expand Down
1 change: 1 addition & 0 deletions src/SolarChargerSB041.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SolarChargerSB041 {
public:
SolarChargerSB041(uint8_t address = 0x32);

void begin();
void update();
bool isChargerConnected() const;
float getSolarPanelVoltage() const;
Expand Down

0 comments on commit 00f1857

Please sign in to comment.