Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface for switch/push button startup #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions firmware/ray/ray.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ char lamp_nameall[128];
float boot_values[3];
float proportional_values[3];

typedef enum {
STARTUP_OFF = 0,
STARTUP_ON,
STARTUP_P_SWITCH,
STARTUP_ON_PB,
STARTUP_OFF_PB,
} startup_mode_t;

startup_mode_t startup_mode = STARTUP_OFF;

void setup(void){

/* start the serial port and switch on the PCB led */
Expand All @@ -32,14 +42,15 @@ void setup(void){
ohaut.on_config_defaults = [](ConfigMap *config) {
config->set("mode", "lamp");

config->set("startup_val_l0", "0");
config->set("startup_val_l0", "100");
config->set("startup_val_l1", "0");
config->set("startup_val_l2", "0");

config->set("pub_l0_bool", "false");
config->set("pub_l1_bool", "false");
config->set("pub_l2_bool", "false");
config->set("pub_all_bool", "true");
config->set("startup_mode", "1");

config->set("all_mode", "0"); /* default mode proportional */

Expand All @@ -49,8 +60,8 @@ void setup(void){
for (int led=0;led<3; led++)
boot_values[led] = getDimmerStartupVal(configData, led);

/* switch on leds */
dimmers.setup(boot_values, atoi((*configData)["all_mode"]));
/* switch on leds */
dimmers.setup(boot_values, atoi((*configData)["all_mode"]));

// Add virtual devices
sprintf(lamp_name1, "%s_l0", ohaut.get_host_id());
Expand All @@ -62,6 +73,8 @@ void setup(void){
if (configData->isTrue("pub_l1_bool")) ohaut.fauxmo->addDevice(lamp_name2);
if (configData->isTrue("pub_l2_bool")) ohaut.fauxmo->addDevice(lamp_name3);
if (configData->isTrue("pub_all_bool")) ohaut.fauxmo->addDevice(lamp_nameall);

startup_mode = getStartupMode(configData);
};

ohaut.on_http_server_ready = &setupHTTPApi;
Expand Down Expand Up @@ -124,3 +137,9 @@ float getDimmerStartupVal(ConfigMap *configData, int dimmer) {
if (val && strlen(val)) return atoi(val)/100.0;
else return 1.0;
}

startup_mode_t getStartupMode(ConfigMap *configData) {
const char *val = (*configData)["startup_mode"];
if (val && strlen(val)) return (startup_mode_t)atoi(val);
else return STARTUP_OFF;
}
26 changes: 24 additions & 2 deletions firmware/webapp/ray.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1>Current lamp values</h1>
</div></div>


<h1>Lamp startup settings (0-100 or empty to get it from net)</h1>
<h1>Lamp startup settings (0-100)</h1>

<div class="form-group"><label for="startup_val_l0" class="col-sm-3 control-label">Channel 0</label><div class="col-sm-7">
<input class="form-control" name="startup_val_l0" value=''>
Expand All @@ -44,7 +44,29 @@ <h1>Lamp startup settings (0-100 or empty to get it from net)</h1>
<input class="form-control" name="startup_val_l2" value=''>
</div></div>

<h1>Lamp "all" mode</h1>
<h1>Lamp startup</h1>
<div class="form-group">
<label for="startup_mode" class="col-sm-3 control-label">mode</label>
<div class="col-sm-7">
<select class="form-control" name="startup_mode" id="startup_mode" aria-describedby="startup_mode_help">
<option value="0">OFF</option>
<option value="1">ON</option>
<option value="2">Use P Switch input</option>
<option value="3">OFF (P is a push button)</option>
<option value="4">ON (P is a push button)</option>
</select>
<small id="startup_mode_help" class="form-text text-muted">
The lamp startup mode controls what happens when the lamp is powered on. <b>OFF</b> will
turn the lamp off, <b>ON</b> will turn the lamp on, and <b>Use P Switch input</b> will
use the P input to determine the lamp state. <b>OFF (P is a push button)</b> and
<b>ON (P is a push button)</b> will start OFF or ON, but will toggle the lamp state
when the P input is pressed.
</small>
</div>
</div>


<h1>Lamp "all" mode</h1>
<div class="form-group">
<label for="all_mode" class="col-sm-3 control-label">mode</label>
<div class="col-sm-7">
Expand Down