Skip to content

Commit

Permalink
Merge branch 'develop' into feat-snake-game
Browse files Browse the repository at this point in the history
  • Loading branch information
GPaddle authored May 15, 2021
2 parents ac4617d + bb26f12 commit 4739be0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 34 deletions.
3 changes: 2 additions & 1 deletion include/osw_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class OswUI {
uint16_t getWarningColor(void);
uint16_t getDangerColor(void);

void resetColors(void);
void reloadThemeColors(void);
void resetTextColors(void);
void setTextCursor(Button btn);

private:
Expand Down
12 changes: 8 additions & 4 deletions src/apps/main/switcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ void OswAppSwitcher::loop(OswHal* hal) {

if (_enableAutoSleep && *_rtcAppIndex == 0 && !hal->btnIsDown(_btn)) {
if (*_rtcAppIndex == 0 && (millis() - appOnScreenSince) > 15000) {
hal->gfx()->fill(rgb565(0, 0, 0));
hal->flushCanvas();
hal->deepSleep();
if(hal->btnIsDown(BUTTON_1) || hal->btnIsDown(BUTTON_2) || hal->btnIsDown(BUTTON_3)){
appOnScreenSince = millis();
}else{
hal->gfx()->fill(rgb565(0, 0, 0));
hal->flushCanvas();
hal->deepSleep();
}
}
}

hal->gfx()->resetText();
OswUI::getInstance()->resetColors(); // yes this resets the colors in hal->gfx()
OswUI::getInstance()->resetTextColors(); // yes this resets the colors in hal->gfx()
_apps[*_rtcAppIndex]->loop(hal);

// draw app switcher
Expand Down
3 changes: 2 additions & 1 deletion src/apps/tools/config_mgmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void handleDataJson() {

// TODO: error handling?
server->send(200, "application/json", "{\"success\":true}");
OswUI::getInstance()->resetColors();
OswUI::getInstance()->reloadThemeColors();
OswUI::getInstance()->resetTextColors();
}

void OswAppConfigMgmt::setup(OswHal* hal) {
Expand Down
6 changes: 4 additions & 2 deletions src/hal/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ void OswHal::deepSleep() {
// rtc_gpio_isolate(GPIO_NUM_33);
// rtc_gpio_isolate(GPIO_NUM_34);
// rtc_gpio_isolate(GPIO_NUM_35);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0 /* BTN_0 */, LOW);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_35 /* BMA_INT_2 / TAP */, HIGH);
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_0 /* BTN_0 */, LOW);
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_35 /* BMA_INT_2 / TAP */, HIGH);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_34 /* BMA_INT_1 */, HIGH);


esp_deep_sleep_start();
};
Expand Down
81 changes: 57 additions & 24 deletions src/hal/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,59 @@ int8_t bma400_interface_init(struct bma400_dev *bma400, uint8_t intf) {
return rslt;
}

void setupTiltToWake() {
int8_t rslt = 0;

// get current state of 0x1F register
uint8_t regSet = 0;
rslt = bma400_get_regs(0x1f, &regSet, 1, &bma);
bma400_check_rslt("bma400_get_regs 0x1f", rslt);

if (rslt != BMA400_OK) {
// we were NOT successful getting the 0x1f register
return;
}

// set orientation change used for interrupt
uint8_t data = BMA400_AXIS_X_EN & BMA400_DATA_SRC_ACCEL_FILT_LP;
rslt = bma400_set_regs(0x35, &data, 1, &bma);

// set the threshold for the twist
data = 0x7F;
rslt = bma400_set_regs(0x36, &data, 1, &bma);
bma400_check_rslt("bma400_set_regs 0x36", rslt);

// set stable time in 50ths of a second
data = 0x19;
rslt = bma400_set_regs(0x38, &data, 1, &bma);
bma400_check_rslt("bma400_set_regs 0x38", rslt);

// add orientation change to current interrupt settings
regSet = regSet & BMA400_AXIS_X_EN;
rslt = bma400_set_regs(0x1f, &regSet, 1, &bma);
bma400_check_rslt("bms400_set_regs 0x1f", rslt);

// get the current setting for 0x21
rslt = bma400_get_regs(0x21, &regSet, 1, &bma);
bma400_check_rslt("bma400_get_regs 0x21", rslt);

// add orientch to int1 map
if (rslt == BMA400_OK) {
regSet = regSet & 0x02;
rslt = bma400_set_regs(0x21, &regSet, 1, &bma);
} else {
data = 0x02;
rslt = bma400_set_regs(0x21, &data, 1, &bma);
}
}

// BlueDot_BMA400 bma400 = BlueDot_BMA400();
void IRAM_ATTR isrStep() { Serial.println("Step"); }
void IRAM_ATTR isrStep() {
// TODO: read INT_STAT0,INT_STAT1,INT_STAT2
// check which interrupt fired
}
void IRAM_ATTR isrTap() { Serial.println("Tap"); }

void OswHal::setupSensors() {
struct bma400_sensor_conf accel_setting[3] = {{}};
struct bma400_int_enable int_en[3];
Expand All @@ -174,22 +224,24 @@ void OswHal::setupSensors() {
rslt = bma400_get_sensor_conf(accel_setting, 3, &bma);
bma400_check_rslt("bma400_get_sensor_conf", rslt);

accel_setting[0].param.step_cnt.int_chan = BMA400_INT_CHANNEL_1;
setupTiltToWake(); // registers tilt on INT_CHANNEL_1

accel_setting[1].param.tap.int_chan = BMA400_INT_CHANNEL_2;
accel_setting[0].param.step_cnt.int_chan = BMA400_INT_CHANNEL_2;

accel_setting[1].param.tap.int_chan = BMA400_INT_CHANNEL_1;
accel_setting[1].param.tap.axes_sel = BMA400_TAP_Z_AXIS_EN; // BMA400_TAP_X_AXIS_EN | BMA400_TAP_Y_AXIS_EN |
accel_setting[1].param.tap.sensitivity = BMA400_TAP_SENSITIVITY_5;
accel_setting[1].param.tap.tics_th = BMA400_TICS_TH_6_DATA_SAMPLES;
accel_setting[1].param.tap.quiet = BMA400_QUIET_60_DATA_SAMPLES;
accel_setting[1].param.tap.quiet_dt = BMA400_QUIET_DT_4_DATA_SAMPLES;

// settings required for tap detection to work:
// settings required for tap detection to work
accel_setting[2].param.accel.odr = BMA400_ODR_200HZ;
accel_setting[2].param.accel.range = BMA400_RANGE_16G;
accel_setting[2].param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1;
accel_setting[2].param.accel.filt1_bw = BMA400_ACCEL_FILT1_BW_1;

/* Set the desired configurations to the sensor */
// Set the desired configurations to the sensor
rslt = bma400_set_sensor_conf(accel_setting, 3, &bma);
bma400_check_rslt("bma400_set_sensor_conf", rslt);

Expand All @@ -206,20 +258,6 @@ void OswHal::setupSensors() {
rslt = bma400_enable_interrupt(int_en, 3, &bma);
bma400_check_rslt("bma400_enable_interrupt", rslt);

// See: https://platformio.org/lib/show/7125/BlueDot%20BMA400%20Library
// bma400.parameter.I2CAddress = 0x14; // default I2C address
// bma400.parameter.powerMode = 0x02; // normal mode
// bma400.parameter.measurementRange = BMA400_RANGE_2G; // 2g range
// bma400.parameter.outputDataRate = BMA400_ODR_200HZ; // 200 Hz req. for tap detection
// bma400.parameter.oversamplingRate = 0x03; // highest oversampling

// _hasBMA400 = bma400.init() == 0x90;

// bma400.enableStepCounter();

// TODO: why is chip ID 0 ?
// Serial.println(bma400.checkID(), 16);

pinMode(BMA_INT_1, INPUT);
pinMode(BMA_INT_2, INPUT);

Expand All @@ -233,11 +271,6 @@ void OswHal::updateAccelerometer(void) {
int8_t rslt = BMA400_OK;
struct bma400_sensor_data data;

// bma400.readData();
// uint16_t int_status;
// rslt = bma400_get_interrupt_status(&int_status, &bma);
// bma400_check_rslt("bma400_get_interrupt_status", rslt);

rslt = bma400_get_steps_counted(&step_count, &act_int, &bma);
bma400_check_rslt("bma400_get_steps_counted", rslt);

Expand Down
7 changes: 5 additions & 2 deletions src/osw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ uint16_t OswUI::getSuccessColor(void) { return themeSuccessColor; }
uint16_t OswUI::getWarningColor(void) { return themeWarningColor; }
uint16_t OswUI::getDangerColor(void) { return themeDangerColor; }

void OswUI::resetColors(void) { //
_hal->gfx()->setTextColor(getForegroundColor(), getBackgroundColor());
void OswUI::reloadThemeColors(void) {
themeBackgroundColor = rgb888to565(OswConfigAllKeys::themeBackgroundColor.get());
themeForegroundColor = rgb888to565(OswConfigAllKeys::themeForegroundColor.get());
themePrimaryColor = rgb888to565(OswConfigAllKeys::themePrimaryColor.get());
Expand All @@ -40,6 +39,10 @@ void OswUI::resetColors(void) { //
themeDangerColor = rgb888to565(OswConfigAllKeys::themeDangerColor.get());
}

void OswUI::resetTextColors(void) { //
_hal->gfx()->setTextColor(getForegroundColor(), getBackgroundColor());
}

void OswUI::setTextCursor(Button btn) {
// TODO: this is an ugly hack and needs to go into the main repo
_hal->gfx()->setTextSize(2);
Expand Down

0 comments on commit 4739be0

Please sign in to comment.