Minor tweaks
-add fontConv -make rolloPos display current position of (first) selected rollo -usability enhancements and fixes -increase max. number of Rollos -TODO: ADD METHOD TO SAVE DESIRED LOWER END POSITION
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "tahoma.h"
|
||||
#include "settings.h"
|
||||
extern constexpr char Tahoma::serverURL[];
|
||||
extern Tahoma::rolloCommand_t Tahoma::movement[];
|
||||
Tahoma::Tahoma(void) {}
|
||||
@@ -10,7 +11,8 @@ uint8_t Tahoma::getMyDevices(bool _force_update) {
|
||||
if (!numDevs || _force_update) {
|
||||
HTTPClient http; // Create an HTTP client object
|
||||
String url = serverURL;
|
||||
url += "?action=myactors"; // Construct the URL to fetch all devices
|
||||
url += "?action=myactors&filter=";
|
||||
url += Settings::prefs.hostname; // Construct the URL to fetch all devices
|
||||
http.begin(url); // Initialize the HTTP connection
|
||||
int httpCode = http.GET(); // Send the GET request and get the response code
|
||||
if (httpCode > 0) { // Check if the request was successful
|
||||
@@ -27,6 +29,7 @@ uint8_t Tahoma::getMyDevices(bool _force_update) {
|
||||
doc[i]["name"]
|
||||
.as<String>(); // Get the device URL from the JSON response
|
||||
devicelist[i].index = doc[i]["id"];
|
||||
devicelist[i].selected = false;
|
||||
numDevs++;
|
||||
}
|
||||
}
|
||||
@@ -42,25 +45,38 @@ uint8_t Tahoma::getMyDevices(bool _force_update) {
|
||||
return numDevs;
|
||||
}
|
||||
|
||||
bool Tahoma::isDeviceSelected(uint8_t deviceIndex) {
|
||||
return devicelist[deviceIndex].selected;
|
||||
}
|
||||
|
||||
Tahoma::rolloCommand_t Tahoma::getPos(int8_t deviceIndex) {
|
||||
rolloCommand_t pos = {0};
|
||||
if (deviceIndex == -1)
|
||||
deviceIndex = currentDevIndex;
|
||||
if(deviceIndex < 0){
|
||||
for(uint8_t i=0; i<numDevs;i++){
|
||||
if(devicelist[i].selected){
|
||||
deviceIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deviceIndex < numDevs) {
|
||||
HTTPClient http; // Create an HTTP client object
|
||||
String url = serverURL;
|
||||
url += "?action=pos&device=" +
|
||||
String(devicelist[deviceIndex]
|
||||
.index); // Construct the URL to fetch all devices
|
||||
Serial.println(url);
|
||||
Serial.println(url);
|
||||
http.begin(url); // Initialize the HTTP connection
|
||||
int httpCode = http.GET(); // Send the GET request and get the response code
|
||||
if (httpCode > 0) { // Check if the request was successful
|
||||
JsonDocument doc; // Create a JSON document to parse the response
|
||||
String response = http.getString(); // Get the response as a string
|
||||
if (!deserializeJson(doc, response)) { // Check if the JSON was decoded wthout error
|
||||
if (!deserializeJson(
|
||||
doc, response)) { // Check if the JSON was decoded wthout error
|
||||
Serial.println("doc has content");
|
||||
pos.rotation = doc["rotation"].as<uint8_t>(); // Get the device URL from the JSON response
|
||||
pos.rotation =
|
||||
doc["rotation"]
|
||||
.as<uint8_t>(); // Get the device URL from the JSON response
|
||||
pos.position = doc["position"].as<uint8_t>();
|
||||
Serial.println(pos.rotation);
|
||||
Serial.println(pos.position);
|
||||
@@ -136,6 +152,14 @@ uint8_t Tahoma::sendMove(uint8_t deviceIndex, uint8_t position,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Tahoma::moveSelected(uint8_t position, uint8_t rotation) {
|
||||
for (uint8_t i = 0; i < numDevs; i++) {
|
||||
if (devicelist[i].selected) {
|
||||
sendMove(i, position, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Tahoma::sendfinalRot(uint8_t deviceIndex) {
|
||||
uint8_t ret = 0;
|
||||
HTTPClient http; // Create an HTTP client object
|
||||
@@ -159,13 +183,12 @@ uint8_t Tahoma::sendfinalRot(uint8_t deviceIndex) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Tahoma::setCurrentDev(uint8_t i) {
|
||||
void Tahoma::selectDev(uint8_t i,bool _select) {
|
||||
if (i <= numDevs) {
|
||||
currentDevIndex = i;
|
||||
devicelist[i].selected = _select;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Tahoma::getCurrentDev() { return currentDevIndex; }
|
||||
|
||||
void Tahoma::loop(void) {
|
||||
for (uint8_t i = 0; i < numDevs; i++) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <HTTPClient.h>
|
||||
#include <Ticker.h>
|
||||
#include <ArduinoJson.h> // Include the ArduinoJson library for JSON parsing
|
||||
#define MAX_NUM_DEVICES 5 // Maximum number of devices to fetch
|
||||
#define MAX_NUM_DEVICES 11 // Maximum number of devices to fetch
|
||||
|
||||
class Tahoma {
|
||||
public:
|
||||
@@ -22,6 +22,7 @@ typedef union {
|
||||
typedef struct {
|
||||
String name; // Device name
|
||||
uint16_t index; // Device URL
|
||||
bool selected;
|
||||
} device_t;
|
||||
// Constructor with hostname and token
|
||||
// Initializes the Tahoma object with the provided hostname and token
|
||||
@@ -33,14 +34,14 @@ typedef union {
|
||||
rolloCommand_t getPos(int8_t deviceIndex=-1);
|
||||
uint8_t sendMove(uint8_t deviceIndex, uint8_t position, uint8_t rotation);
|
||||
uint8_t sendfinalRot(uint8_t deviceIndex);
|
||||
void setCurrentDev(uint8_t i);
|
||||
uint8_t getCurrentDev();
|
||||
void moveSelected(uint8_t position, uint8_t rotation);
|
||||
void selectDev(uint8_t i, bool _selected);
|
||||
bool isDeviceSelected(uint8_t deviceIndex);
|
||||
void loop(void);
|
||||
device_t devicelist[MAX_NUM_DEVICES];
|
||||
uint8_t numDevs{0};
|
||||
static rolloCommand_t movement[MAX_NUM_DEVICES];
|
||||
private:
|
||||
uint8_t currentDevIndex{0};
|
||||
bool checkMovement(uint8_t deviceIndex);
|
||||
static constexpr char serverURL[]{"http://nas.local/smart/ajax/tahoma.php"}; // Hostname of the Tahoma system
|
||||
Ticker movementCheckTicker;
|
||||
|
||||
@@ -494,6 +494,8 @@ void showRolloPosScreen(lv_event_t *e) {
|
||||
Tahoma::rolloCommand_t pos = tahoma.getPos();
|
||||
lv_slider_set_value(objects.rolloPos, pos.position, LV_ANIM_OFF);
|
||||
lv_arc_set_value(objects.rolloRot, pos.rotation * 9);
|
||||
lv_obj_send_event(objects.rolloRot,LV_EVENT_VALUE_CHANGED,NULL);
|
||||
lv_obj_send_event(objects.rolloPos,LV_EVENT_VALUE_CHANGED,NULL);
|
||||
}
|
||||
objects.debugScr = NULL;
|
||||
objects.mainScr = NULL;
|
||||
@@ -573,7 +575,7 @@ void setRolloListText(void) {
|
||||
} else {
|
||||
txt = "Rollos wählen";
|
||||
}
|
||||
lv_obj_set_style_anim_duration(objects.selDevicesLbl, 70*(lv_text_get_width(txt.c_str(),txt.length(),&symbol_font_12,0)-100), LV_PART_MAIN);
|
||||
lv_obj_set_style_anim_duration(objects.selDevicesLbl, 50*(lv_text_get_width(txt.c_str(),txt.length(),&symbol_font_12,0)), LV_PART_MAIN);
|
||||
lv_label_set_text(objects.selDevicesLbl, txt.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -216,15 +216,17 @@ void create_screen_menu() {
|
||||
|
||||
void rolloCheckbox_add(const char *txt, void *_tahomaDevice, bool _checked) {
|
||||
lv_obj_t *obj = lv_checkbox_create(objects.deviceDropdown);
|
||||
lv_obj_set_size(obj, LV_SIZE_CONTENT, 25);
|
||||
lv_obj_set_style_min_width(obj,lv_pct(95),LV_PART_MAIN);
|
||||
lv_checkbox_set_text(obj, txt);
|
||||
lv_obj_set_user_data(obj, _tahomaDevice);
|
||||
lv_obj_set_style_bg_image_src(obj, SYM_CHECK,
|
||||
LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_border_color(obj, lv_color_hex(0xff5D636E),
|
||||
lv_obj_set_style_border_color(obj, lv_color_hex(0xff000000),
|
||||
LV_PART_INDICATOR | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_color(obj, lv_palette_darken(LV_PALETTE_GREEN, 3),
|
||||
LV_PART_INDICATOR | LV_STATE_CHECKED);
|
||||
lv_obj_set_style_text_font(obj,&symbol_font_12,LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_font(obj,&symbol_font_16,LV_STATE_DEFAULT| LV_PART_INDICATOR);
|
||||
if (_checked)
|
||||
lv_obj_add_state(obj, LV_STATE_CHECKED);
|
||||
lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
@@ -268,7 +270,7 @@ void create_screen_rollos() {
|
||||
}*/
|
||||
{ // rolloChooser BTN
|
||||
lv_obj_t *obj = lv_btn_create(parent_obj);
|
||||
lv_obj_set_size(obj, 130, 30);
|
||||
lv_obj_set_size(obj, 130, 35);
|
||||
lv_obj_set_pos(obj, 55, 20);
|
||||
lv_obj_set_style_bg_color(obj, lv_color_hex(0xff2f3237),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
@@ -296,7 +298,7 @@ label scrolls back to the initial position*/
|
||||
{ // UP BTN
|
||||
lv_obj_t *obj = lv_btn_create(parent_obj);
|
||||
lv_obj_set_size(obj, 120, 60);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, -15);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, -18);
|
||||
lv_obj_set_style_bg_color(obj, lv_color_hex(0xff2f3237),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_add_event_cb(obj, moveRolloUp, LV_EVENT_RELEASED, NULL);
|
||||
@@ -313,7 +315,7 @@ label scrolls back to the initial position*/
|
||||
{ // DOWN BTN
|
||||
lv_obj_t *obj = lv_btn_create(parent_obj);
|
||||
lv_obj_set_size(obj, 120, 60);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, 55);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, 52);
|
||||
lv_obj_set_style_bg_color(obj, lv_color_hex(0xff2f3237),
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_add_event_cb(obj, moveRolloDown, LV_EVENT_RELEASED, NULL);
|
||||
@@ -623,9 +625,9 @@ void create_screen_rolloPos() {
|
||||
{
|
||||
lv_obj_t *obj = lv_label_create(parent_obj);
|
||||
objects.debugTxt = obj;
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, -85);
|
||||
lv_obj_align(obj, LV_ALIGN_CENTER, 0, -87);
|
||||
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_label_set_text(obj, "Gewählte Rollos manuell positionieren");
|
||||
lv_label_set_text(obj, "Gewählte Rollos\nmanuell positionieren");
|
||||
lv_obj_set_style_text_align(obj, LV_TEXT_ALIGN_CENTER,
|
||||
LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_font(obj, &symbol_font_12,
|
||||
|
||||
Reference in New Issue
Block a user