Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update libraries to the latest x.x.1 variant. move examples to the li…
…braries folder, plus a little formatting makes them visible as examples in the Arduino IDE. Add ID107 example that uses u8g2 for the OLED, and internal libraries for the heart rate sensor and accelerometer (Note: SoftwareI2C works with the heartrate sensor, but not the accelerometer). Add MPOW DS-D6 variant using pin mapping from @fanoush
- Loading branch information
Showing
30 changed files
with
979 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
libraries/examples/Examples/ID107_u8g2_sensors_clock/ID107_OLED.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#ifndef ID107_OLED_H | ||
#define ID107_OLED_H | ||
|
||
#include "ID107_sensors.h" | ||
|
||
#include <U8g2lib.h> | ||
#include <SPI.h> | ||
|
||
U8G2_SH1106_64X32_1_4W_HW_SPI u8g2(U8G2_R0, OLED_CS, OLED_DC, OLED_RST); | ||
|
||
class ID107_OLED{ | ||
private: | ||
const uint8_t _numPages = 4; | ||
uint32_t _splashTime; | ||
uint8_t _pageNum; | ||
time_t compileTime(); | ||
|
||
ID107_sensors _id107_sensors; | ||
|
||
void splash(uint32_t splash_time_ms); | ||
void draw(); | ||
public: | ||
ID107_OLED(uint32_t splash_time_ms = 2000): _splashTime(splash_time_ms), _pageNum(0) {} | ||
~ID107_OLED() {} | ||
void begin(); | ||
void heartrate(uint8_t ambiant_sensor = 0); | ||
void accelerometer(); | ||
void clock(); | ||
void nextPage(); | ||
uint8_t getPageCount() { return _numPages; } | ||
void drawPage(uint8_t pageNum = 0); | ||
}; | ||
|
||
void ID107_OLED::begin() | ||
{ | ||
_id107_sensors.begin(); | ||
|
||
u8g2.begin(); | ||
u8g2.setFont(u8g2_font_6x10_tf); | ||
u8g2.setFontRefHeightExtendedText(); | ||
u8g2.setDrawColor(1); | ||
u8g2.setFontPosTop(); | ||
u8g2.setFontDirection(0); | ||
|
||
splash(_splashTime); | ||
} | ||
|
||
void ID107_OLED::drawPage(uint8_t pageNum) | ||
{ | ||
switch(pageNum) { | ||
case 0: | ||
heartrate(0); break; | ||
case 1: | ||
heartrate(1); break; | ||
case 2: | ||
accelerometer(); break; | ||
default: | ||
clock(); | ||
} | ||
} | ||
|
||
void ID107_OLED::draw() | ||
{ | ||
u8g2.firstPage(); | ||
do { | ||
u8g2.setFont(u8g2_font_6x10_tf); | ||
u8g2.drawStr( 0, 0, _id107_sensors.row[0].c_str()); | ||
u8g2.drawStr(0, 10, _id107_sensors.row[1].c_str()); | ||
u8g2.drawStr(0, 20, _id107_sensors.row[2].c_str()); | ||
} while ( u8g2.nextPage() ); | ||
} | ||
|
||
void ID107_OLED::nextPage() | ||
{ | ||
// increment the page number | ||
_pageNum = (_pageNum < _numPages - 1)?_pageNum + 1:0; | ||
|
||
// draw the page | ||
drawPage(_pageNum); | ||
} | ||
|
||
|
||
void ID107_OLED::heartrate(uint8_t ambiant_sensor) | ||
{ | ||
_id107_sensors.get_heartrate(ambiant_sensor); | ||
|
||
draw(); | ||
} | ||
|
||
void ID107_OLED::accelerometer() | ||
{ | ||
_id107_sensors.get_accelerometer(); | ||
|
||
draw(); | ||
} | ||
|
||
void ID107_OLED::clock() | ||
{ | ||
_id107_sensors.get_clock(); | ||
|
||
draw(); | ||
} | ||
|
||
void ID107_OLED::splash(uint32_t splash_time_ms) | ||
{ | ||
_id107_sensors.row[0] = "github.com"; | ||
_id107_sensors.row[1] = "/micooke"; | ||
_id107_sensors.row[2] = __TIME__; | ||
|
||
draw(); | ||
|
||
delay(splash_time_ms); | ||
} | ||
|
||
#endif |
169 changes: 169 additions & 0 deletions
169
libraries/examples/Examples/ID107_u8g2_sensors_clock/ID107_sensors.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#ifndef ID107_SENSORS_H | ||
#define ID107_SENSORS_H | ||
|
||
#include <SoftwareI2C.h> | ||
|
||
#include <KX022.h> | ||
#include <Si114.h> | ||
|
||
#include <Timezone.h> // https://github.com/JChristensen/Timezone | ||
|
||
TimeChangeRule ACST = {"ACST", First, Sun, Apr, 3, 570}; // Australian Central Daylight Time = UTC +9:30 hours | ||
TimeChangeRule ACDT = {"ACDT", First, Sun, Oct, 2, 630}; // Australian Central Standard Time = UTC +10:30 hours | ||
Timezone AdelaideTimezone(ACST, ACDT); | ||
TimeChangeRule *tcr; // pointer to the time change rule, use to get TZ abbrev | ||
|
||
#ifdef ACCEL_HWI2C | ||
// Kx022 - Hardware I2C (Wire) | ||
KX022<> acc(Wire); | ||
|
||
// Si1143 - Software I2C | ||
SoftwareI2C sWire(PIN_WIRE1_SDA, PIN_WIRE1_SCL); | ||
PulsePlug<SoftwareI2C> pulse(sWire); | ||
#else | ||
// Kx022 - Software I2C (Wire) | ||
SoftwareI2C sWire(PIN_WIRE1_SDA, PIN_WIRE1_SCL); | ||
KX022<SoftwareI2C> acc(sWire); | ||
|
||
// Si1143 - Hardware I2C | ||
PulsePlug<> pulse(Wire); | ||
#endif | ||
|
||
class ID107_sensors{ | ||
private: | ||
uint8_t _retries; | ||
void float2chars(float &in, char (&out)[5]); | ||
time_t compileTime(); | ||
public: | ||
ID107_sensors(uint8_t retries = 5) : _retries(retries) {} | ||
~ID107_sensors() {} | ||
void begin(); | ||
void get_heartrate(uint8_t ambiant_sensor = 0); | ||
void get_accelerometer(); | ||
void get_clock(); | ||
String row[3]; | ||
}; | ||
|
||
void ID107_sensors::begin() | ||
{ | ||
// Clock | ||
setTime(AdelaideTimezone.toUTC(compileTime())); | ||
|
||
// Si1143 - Heartrate | ||
uint8_t attempts = 0; | ||
while ((pulse.isPresent() == false) & (attempts < _retries)) | ||
{ | ||
delay(100); | ||
++attempts; | ||
} | ||
if (pulse.isPresent()) | ||
{ | ||
pulse.init(); | ||
} | ||
|
||
// Kx022 - Accelerometer | ||
acc.init(); | ||
} | ||
|
||
void ID107_sensors::get_heartrate(uint8_t ambiant_sensor) | ||
{ | ||
if (pulse.isPresent()) | ||
{ | ||
pulse.readSensor(ambiant_sensor + 1); // sensorIdx = 1(HeartRate),2(Ambiant),3(Both) | ||
if (ambiant_sensor) | ||
{ | ||
|
||
row[0] = "VIS " + String(pulse.als_vis); | ||
row[1] = "IR " + String(pulse.als_ir); | ||
row[2] = ""; | ||
} | ||
else | ||
{ | ||
row[0] = "RED " + String(pulse.led_red); | ||
row[1] = "IR1 " + String(pulse.led_ir1); | ||
row[2] = "IR2 " + String(pulse.led_ir2); | ||
} | ||
} | ||
else | ||
{ | ||
row[0] = "Si1143 (HRM)"; | ||
row[1] = "Not"; | ||
row[2] = "Present"; | ||
} | ||
} | ||
|
||
void ID107_sensors::get_accelerometer() | ||
{ | ||
row[0] = "X "; | ||
row[1] = "Y "; | ||
row[2] = "Z "; | ||
|
||
char fltBuf[5]; | ||
float xyz[3]; | ||
acc.getAccelXYZ(xyz); | ||
|
||
float2chars(xyz[0],fltBuf); row[0] += String(fltBuf); | ||
float2chars(xyz[1],fltBuf); row[1] += String(fltBuf); | ||
float2chars(xyz[2],fltBuf); row[2] += String(fltBuf); | ||
} | ||
|
||
void ID107_sensors::get_clock() | ||
{ | ||
time_t utc = now(); | ||
time_t local = AdelaideTimezone.toLocal(utc, &tcr); | ||
|
||
char timeString[10]; | ||
|
||
sprintf(timeString, "%.2d:%.2d:%.2d", hour(local), minute(local), second(local)); | ||
|
||
char dateString[11]; | ||
|
||
sprintf(dateString, "%.2d/%.2d/%d", day(local), month(local), year(local)); | ||
/* | ||
char dayString[7]; | ||
char monthYearString[9]; | ||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer) | ||
strcpy(m, monthShortStr(month(local))); | ||
sprintf(dayString, "%s %.2d", dayShortStr(weekday(local)), day(local)); | ||
sprintf(buf, "%s %d", m, year(local)); | ||
*/ | ||
row[0] = timeString; | ||
row[1] = dateString; | ||
row[2] = ""; | ||
} | ||
|
||
// Function to return the compile date and time as a time_t value | ||
time_t ID107_sensors::compileTime() | ||
{ | ||
const time_t FUDGE(4); // fudge factor to allow for compile time (seconds, YMMV) | ||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec"; | ||
char chMon[3], *m; | ||
tmElements_t tm; | ||
|
||
strncpy(chMon, compDate, 3); | ||
chMon[3] = '\0'; | ||
m = strstr(months, chMon); | ||
tm.Month = ((m - months) / 3 + 1); | ||
|
||
tm.Day = atoi(compDate + 4); | ||
tm.Year = atoi(compDate + 7) - 1970; | ||
tm.Hour = atoi(compTime); | ||
tm.Minute = atoi(compTime + 3); | ||
tm.Second = atoi(compTime + 6); | ||
time_t t = makeTime(tm); | ||
return t + FUDGE; // add fudge factor to allow for compile time | ||
} | ||
|
||
void ID107_sensors::float2chars(float &in, char (&out)[5]) | ||
{ | ||
bool sign_bit = (in < 0); | ||
uint16_t tmp = sign_bit?(-in * 10):(in * 10); | ||
out[0] = (sign_bit)?'-':' '; | ||
out[1] = char('0' + (tmp / 10)); | ||
out[2] = '.'; | ||
out[3] = char('0' + (tmp % 10)); | ||
out[4] = '\0'; | ||
} | ||
|
||
#endif |
Oops, something went wrong.