Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nplan committed Jun 29, 2023
2 parents 0ccfbf1 + 83a69e0 commit 45a63e8
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Firmware/HomeButtonsArduino/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ void AppSMStates::UserInputFinishState::loop() {
#endif
}
sm().btn_event_ = btn_event;
sm().button_handler_.clear();
return transition_to<NetConnectingState>();
}
break;
Expand Down Expand Up @@ -865,6 +866,15 @@ void AppSMStates::NetConnectingState::loop() {
sm()._publish_sensors();
sm().device_state_.persisted().failed_connections = 0;
return transition_to<CmdShutdownState>();
} else if (sm().button_handler_.is_press_finished()) {
// abort on button press
if (sm().button_handler_.get_event().action == Button::SINGLE) {
sm().info("button press - user cancelled, aborting...");
return transition_to<CmdShutdownState>();
} else {
sm().button_handler_.clear();
}

} else if (millis() >= NET_CONNECT_TIMEOUT) {
sm().warning("network connect timeout.");
if (sm().boot_cause_ == BootCause::BUTTON) {
Expand Down
2 changes: 1 addition & 1 deletion Firmware/HomeButtonsArduino/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// ------ device ------
static constexpr char MANUFACTURER[] = "PLab";
static constexpr char SW_VERSION[] = "v2.2.0";
static constexpr char SW_VERSION[] = "v2.2.1";

// ------ URLs ------
#ifndef HOMEBUTTONS_MINI
Expand Down
16 changes: 14 additions & 2 deletions Firmware/HomeButtonsArduino/src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ void Display::draw_main() {
draw_mdi(icon.c_str(), icon_size, x, y);
// draw text
uint16_t max_text_width = WIDTH - icon_size - h_padding;
u8g2.setFont(u8g2_font_helvB24_te);
if (text.index_of('_') == 0) {
// force small font
text = text.substring(1);
u8g2.setFont(u8g2_font_helvB18_te);
} else {
u8g2.setFont(u8g2_font_helvB24_te);
}
uint16_t w, h;
w = u8g2.getUTF8Width(text.c_str());
h = u8g2.getFontAscent();
Expand Down Expand Up @@ -422,7 +428,13 @@ void Display::draw_main() {
u8g2.print(text.c_str());
} else {
uint16_t max_label_width = WIDTH - min_btn_clearance;
u8g2.setFont(u8g2_font_helvB24_te);
if (label.index_of('_') == 0) {
// force small font
label = label.substring(1);
u8g2.setFont(u8g2_font_helvB18_te);
} else {
u8g2.setFont(u8g2_font_helvB24_te);
}
uint16_t w, h;
w = u8g2.getUTF8Width(label.c_str());
h = u8g2.getFontAscent();
Expand Down
20 changes: 10 additions & 10 deletions Firmware/HomeButtonsArduino/src/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ static WiFiManager wifi_manager;
static WiFiManagerParameter device_name_param("device_name", "Device Name", "",
20);
static WiFiManagerParameter mqtt_server_param("mqtt_server", "MQTT Server", "",
15);
32);
static WiFiManagerParameter mqtt_port_param("mqtt_port", "MQTT Port", "", 6);
static WiFiManagerParameter mqtt_user_param("mqtt_user", "MQTT User", "", 50);
static WiFiManagerParameter mqtt_user_param("mqtt_user", "MQTT User", "", 64);
static WiFiManagerParameter mqtt_password_param("mqtt_password",
"MQTT Password", "", 50);
"MQTT Password", "", 64);
static WiFiManagerParameter base_topic_param("base_topic", "Base Topic", "",
50);
64);
static WiFiManagerParameter discovery_prefix_param("disc_prefix",
"Discovery Prefix", "", 50);
"Discovery Prefix", "", 64);
static WiFiManagerParameter static_ip_param("static_ip", "Static IP", "", 15);
static WiFiManagerParameter gateway_param("gateway", "Gateway", "", 15);
static WiFiManagerParameter subnet_param("subnet", "Subnet Mask", "", 15);
Expand Down Expand Up @@ -146,17 +146,17 @@ void start_setup(DeviceState& device_state, Display& display,
// parameters
device_name_param.setValue(device_state.device_name().c_str(), 20);
mqtt_server_param.setValue(
device_state.user_preferences().mqtt.server.c_str(), 15);
device_state.user_preferences().mqtt.server.c_str(), 32);
mqtt_port_param.setValue(
String(device_state.user_preferences().mqtt.port).c_str(), 6);
mqtt_user_param.setValue(device_state.user_preferences().mqtt.user.c_str(),
50);
64);
mqtt_password_param.setValue(
device_state.user_preferences().mqtt.password.c_str(), 50);
device_state.user_preferences().mqtt.password.c_str(), 64);
base_topic_param.setValue(
device_state.user_preferences().mqtt.base_topic.c_str(), 50);
device_state.user_preferences().mqtt.base_topic.c_str(), 64);
discovery_prefix_param.setValue(
device_state.user_preferences().mqtt.discovery_prefix.c_str(), 50);
device_state.user_preferences().mqtt.discovery_prefix.c_str(), 64);
static_ip_param.setValue(
device_state.user_preferences().network.static_ip.toString().c_str(), 15);
gateway_param.setValue(
Expand Down
4 changes: 4 additions & 0 deletions Firmware/HomeButtonsArduino/src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ void DeviceState::load_all(HardwareDefinition& hw) {
_load_factory(hw);
load_user();
load_persisted();
size_t free_entries = get_free_entries();
info("nvs free entries: %d", free_entries);
}

void DeviceState::clear_all() {
Expand All @@ -176,6 +178,8 @@ void DeviceState::clear_all() {
clear_persisted();
}

size_t DeviceState::get_free_entries() { return preferences_.freeEntries(); }

const ButtonLabel& DeviceState::get_btn_label(uint8_t i) const {
static ButtonLabel noLabel;
if (i < NUM_BUTTONS) {
Expand Down
2 changes: 2 additions & 0 deletions Firmware/HomeButtonsArduino/src/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class DeviceState : public Logger {
void load_all(HardwareDefinition& hw);
void clear_all();

size_t get_free_entries();

// TODO: maybe should be somewhere else
StaticString<32> get_ap_ssid() const {
return StaticString<32>("HB-") + factory_.random_id.c_str();
Expand Down
20 changes: 19 additions & 1 deletion docs/mini/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,25 @@ You can start Wi-Fi setup again by pressing any button. Please make sure to ente

## Display a Custom Message {#custom_message}

A custom message can be shown on the e-paper display by publishing a retained payload to the `{base_topic}/{device_name}/disp_msg` topic. The message will be displayed when the device wakes up on button press or sensor publish. You can clear the message by pressing any button.
A custom message can be shown on the e-paper display by publishing a retained payload to the `{base_topic}/{device_name}/cmd/disp_msg` topic. The message will be displayed when the device wakes up on button press or sensor publish. You can clear the message by pressing any button.

Message will not be wrapped automatically. You must include line breaks `\n` in the payload.

Example *Home Assistant* publish service call YAML:

```yaml
service: mqtt.publish
data:
topic: homebuttons/HB Mini 123/cmd/disp_msg
payload: "Line 1\nLine 2"
retain: true
```

`mosquitto_pub` example:

```bash
mosquitto_pub -h <broker_host> -t <topic> -m $'Line 1\nLine 2'
```

## Opening The Case {#opening_case}

Expand Down
25 changes: 24 additions & 1 deletion docs/original/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Labels can be:

Enter any text you want. Labels support UTF-8 with special characters. *Home Buttons* will choose between two font sizes automatically. It can display around **5** letters in large font and around **7** letters in smaller font.

> To force small font, prepend text with an underscore: `_`. Example: `_Bedroom`.
#### Icons :material-home:

You can choose any of the [Material Design Icons](https://materialdesignicons.com/){:target="_blank"}. Enter the icon name in the label field in the format `mdi:{icon name}`. For example, `mdi:lightbulb-auto-outline`.
Expand All @@ -40,6 +42,9 @@ Icons are downloaded from a *Github* repository. For that purpose an internet co
In label field, enter: `mdi:{icon name} {text}`. For example, `mdi:lightbulb Bedroom`. There must be a single space separating the icon name and the text. Label name must always be first. The actual position of the icon will be before or after the text, based on the location of the button.

>Icons are slightly smaller in this mode.
> To force small font, prepend text with an underscore: `_`. Example: `mdi:lightbulb _Bedroom`.
### Configure Button Actions

To configure button actions, click "+" on the *Automations* card, select one of the buttons and set up an automation with *Home Assistant*'s editor.
Expand Down Expand Up @@ -180,7 +185,25 @@ You can start Wi-Fi setup again by pressing any button. Please make sure to ente

## Display a Custom Message {#custom_message}

A custom message can be shown on the e-paper display by publishing a retained payload to the `{base_topic}/{device_name}/disp_msg` topic. The message will be displayed when the device wakes up on button press or sensor publish. You can clear the message by pressing any button.
A custom message can be shown on the e-paper display by publishing a retained payload to the `{base_topic}/{device_name}/cmd/disp_msg` topic. The message will be displayed when the device wakes up on button press or sensor publish. You can clear the message by pressing any button.

Message will not be wrapped automatically. You must include line breaks `\n` in the payload.

Example *Home Assistant* publish service call YAML:

```yaml
service: mqtt.publish
data:
topic: homebuttons/HB Mini 123/cmd/disp_msg
payload: "Line 1\nLine 2"
retain: true
```

`mosquitto_pub` example:

```bash
mosquitto_pub -h <broker_host> -t <topic> -m $'Line 1\nLine 2'
```

## Opening The Case {#opening_case}

Expand Down

0 comments on commit 45a63e8

Please sign in to comment.