summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: ef36f0b949c15103cc0bae7b52b03692cbd3b2b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <Arduino.h>

#include "config.h"

#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#include <ESP32Servo.h> 
#include <ezButton.h>
#include <OneWire.h>
#include <DallasTemperature.h>

/* todo
 * pobierac temp z onewire (wybierz jakes piny) i aktualizowac w loopie co np 10 sekund.
 * 
 * po wcisnieciu jakiegos guzika jest powinno być wybudzenie wyświetlacza. 
 * przyciski up/down zaznaczam gdy chce zmienić histereze, temp int lub temp ext. po wybraniu kliknąć
 * confirm i wtedy up/down do zmiany temeratury, po zakończeniu exit. Do obsługi przycisków masz ezButton.
 *
 * zasada będzie taka, że jak jest mniej niż min temp internal to serwo zamyka zupełnie zawór. 
 * jeśli jest między min internal a max external to zawór otworzony w 70%.
 * Jak więcej niż max external to zawór otworzony na 100%.
 *
 * serwo ma 270 stopni, ale uwzględniając przekładnie 3 stopnie na serwie to 1 stopień na zaworze.
 * 0 stopni to zawór zamknięty (0%)
 * 270 stopni to 90 stopni na zaworze, czyli jest otwarty w 100%.

   */

Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, TFT_RST);
Servo myServo;

OneWire current_external_wire(EXTERNAL_BUS);
OneWire current_internal_wire(INTERNAL_BUS);

DallasTemperature current_internal_sensor(&current_internal_wire);
DallasTemperature current_external_sensor(&current_external_wire);


float tempInternal;
float tempCurrent; 

float temp_min_internal;
float temp_max_external;

float temp_cur_internal;
float temp_cur_external;


void setupSensors(){
  internal_sensor.begin(); 
  external_sensor.begin();

  Serial.print("Searching for devices.");
  
  int internal_sensor_count = current_internal_sensor.getDeviceCount();
  int external_sensor_count = current_external_sensor.getDeviceCount();

  Serial.print("Internal sensors found: ");
  Serial.println(internal_sensor_count);

  Serial.print("External sensors found: ");
  Serial.println(external_sensor_count);

}


void setupDisplay(){ 

  SPI.begin(TFT_SCLK, -1, TFT_MOSI, TFT_CS);
  tft.init(240, 240); 
  tft.fillScreen(ST77XX_BLACK); 
  
  tft.setTextColor(ST77XX_CYAN);
  tft.setTextSize(3);

  tft.setCursor(0, 0);
  tft.print("TEMP INTERNAL");
  tft.setCursor(0, 25);
  tft.print("min: 50,5");
  tft.setCursor(0, 50);
  tft.print("cur: 67,1");

  tft.setCursor(0, 90);
  tft.print("TEMP EXTERNAL");
  tft.setCursor(0, 115);
  tft.print("max: 90,0");
  tft.setCursor(0, 140);
  tft.print("cur: 80,5");

  tft.setCursor(0, 180);
  tft.print("HYST: 5");
  tft.setCursor(0, 215);
  tft.print("VALVE: 70%");
}


void setup() {
  Serial.begin(115200);
  delay(100); 
  setupDisplay();
}

void loop() {
}