diff --git a/include/osw_ui.h b/include/osw_ui.h index 9980f326f..6a4f90887 100644 --- a/include/osw_ui.h +++ b/include/osw_ui.h @@ -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: diff --git a/src/apps/main/switcher.cpp b/src/apps/main/switcher.cpp index 26841b549..570eb9018 100644 --- a/src/apps/main/switcher.cpp +++ b/src/apps/main/switcher.cpp @@ -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 diff --git a/src/apps/tools/config_mgmt.cpp b/src/apps/tools/config_mgmt.cpp index e3e105219..591283d4b 100644 --- a/src/apps/tools/config_mgmt.cpp +++ b/src/apps/tools/config_mgmt.cpp @@ -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) { diff --git a/src/hal/power.cpp b/src/hal/power.cpp index 670bff174..787c8fec1 100644 --- a/src/hal/power.cpp +++ b/src/hal/power.cpp @@ -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(); }; diff --git a/src/hal/sensors.cpp b/src/hal/sensors.cpp index ac3c5b2e9..8ce3ce627 100644 --- a/src/hal/sensors.cpp +++ b/src/hal/sensors.cpp @@ -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, ®Set, 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, ®Set, 1, &bma); + bma400_check_rslt("bms400_set_regs 0x1f", rslt); + + // get the current setting for 0x21 + rslt = bma400_get_regs(0x21, ®Set, 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, ®Set, 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]; @@ -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); @@ -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); @@ -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); diff --git a/src/osw_ui.cpp b/src/osw_ui.cpp index 75ea36b80..149b8a55d 100644 --- a/src/osw_ui.cpp +++ b/src/osw_ui.cpp @@ -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()); @@ -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);