Topic: Control element switch does not work with element edit field.
Element "switch" with "edit field" doesn't work together.
Element switch returns itself back to position "ON", in this example.
In code there is only switch: switch_1, edit field: edit_1 and text field: text_1.
Example is like the clock which increments 1s counter to text field and to edit field.
When switch is "ON" counter counts up.
When switch is "OFF" counter stops and gets new starting value from edit field edit_1.
Problem is: Switch doesn't want to stay in position "OFF". It magically, physically returns itself to position "ON".
If I put constant integer value, instead counter value seconds, to field edit_1, there is no problem with switch position.
What to do?
/*
-- EditFieldTest --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.6 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.8.01 or later version;
- for iOS 1.5.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
#include <ESP8266WiFi.h>
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "Your SSID"
#define REMOTEXY_WIFI_PASSWORD "Your password"
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376
#define REMOTEXY_CLOUD_TOKEN "4d178e96e6d799971862231c2839c06f"
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255, 3, 0, 11, 0, 38, 0, 13, 13, 1,
2, 0, 19, 36, 28, 12, 2, 26, 31, 31,
79, 78, 0, 79, 70, 70, 0, 7, 52, 23,
17, 21, 7, 2, 26, 2, 67, 4, 23, 27,
14, 6, 2, 26, 11
};
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t switch_1; // =1 if switch ON and =0 if OFF
int16_t edit_1; // 32767.. +32767
// output variables
char text_1[11]; // string UTF8 end zero
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
bool sec; // one second status, 0 or 1
int16_t delay_time = 1000; // delay [ms] for one second
unsigned long time_now; // used for delay without delay();
int16_t seconds; // clock counter for display
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
//------------------------------------------------------------------------
void setup()
{
RemoteXY_Init ();
}
//------------------------------------------------------------------------
void loop()
{
RemoteXY_Handler ();
Clock(); // 1s clock for counter display
ShowClock(); // 1s increment counter display
}
//------------------------------------------------------------------------
void Clock() // Delay 1s without "delay();"
{
if (millis() > time_now + delay_time)
{
time_now = millis();
sec = 1; // flag for to check 1s counter
}
}
//------------------------------------------------------------------------
void ShowClock() // Show 1s counter to edit field and to text field
{
if (RemoteXY.switch_1 == 1 && sec == 1) // Switch is "ON"
{
sec = 0; // only one increment per second
seconds += 1; // increment 1s counter
/* PROBLEM: If row below is allowed (= not commented).
OFF-state of the switch_1 automatically returns to ON-state.
So, you can't set OFF-state at all.
edit_1 has been set to use integer variables.
*/
RemoteXY.edit_1 = seconds; // with this, switch_1 cannot be turned to OFF-state
// This text field update works fine:
sprintf (RemoteXY.text_1, "%d", seconds); // print seconds to field text_1
}
else if (RemoteXY.switch_1 == 0) // Switch is "OFF"
{
seconds = RemoteXY.edit_1; // get new start value for second counter
}
}