Skip to content

Commit cb68bde

Browse files
committed
initial commit
Mostly working .h files, no actual classes or libraries, mostly just demo code or test code snippets for various functions, ideas. May evolve over time
1 parent 4aa9a2b commit cb68bde

20 files changed

+1951
-0
lines changed

ansi.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ansi stuff, could always use printf instead of concat
2+
String ansiPRE = "\033"; // escape code
3+
String ansiHOME = "\033[H"; // cursor home
4+
String ansiESC = "\033[2J"; // esc
5+
String ansiCLC = "\033[?25l"; // invisible cursor
6+
7+
String ansiEND = "\033[0m"; // closing tag for styles
8+
String ansiBOLD = "\033[1m";
9+
10+
String ansiRED = "\033[41m"; // red background
11+
String ansiGRN = "\033[42m"; // green background
12+
String ansiBLU = "\033[44m"; // blue background
13+
14+
String ansiREDF = "\033[31m"; // red foreground
15+
String ansiGRNF = "\033[34m"; // green foreground
16+
String ansiBLUF = "\033[32m"; // blue foreground
17+
String BELL = "\a";
18+
19+
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
20+
printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"
21+
22+
// Telnet.print(ansiHOME+ansiCLC); // clear screen
23+
// Telnet.println("uptime: "+ansiBLU + ansiBOLD + (String)millis() + ansiEND + ansiEND+" ms");

creds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
String apikeya = "SOMEPRIVATEKEY";
3+
const char* SSID = "MYSSID";
4+
const char* PASS = "MYPASS";
5+
6+
const char* STASSID = SSID;
7+
const char* STAPSK = PASS;
8+

definitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
#define INDLEDPIN 13
4+
#define INDLEDISRGBW true

encoder.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Encoder Library
3+
* // https://github.com/soligen2010/encoder
4+
*/
5+
#include <ClickEncoder.h>
6+
7+
#define ENCODER_PINA 2 // not working
8+
#define ENCODER_PINB 16 // working
9+
#define ENCODER_BTN -1 // using analog, could maybe use rx/3?
10+
11+
int encoder_value;
12+
int encoder_numsteps =2; // Type 1
13+
// int encoder_numsteps = 4; // Type 2
14+
#define ENCODER_STEPS_PER_NOTCH 1 // Change this depending on which encoder is used
15+
ClickEncoder encoder = ClickEncoder(ENCODER_PINA,ENCODER_PINB,ENCODER_BTN,ENCODER_STEPS_PER_NOTCH);
16+
17+
void test_encoder(){
18+
bool pinclk = digitalRead(ENCODER_PINA) == LOW;
19+
bool pindata = digitalRead(ENCODER_PINB) == LOW;
20+
21+
if(pinclk && !pindata){
22+
Serial.println("pinclk");
23+
}
24+
25+
if(!pinclk && pindata){
26+
Serial.println("pindata");
27+
}
28+
29+
if(pinclk && pindata){
30+
Serial.println("both");
31+
}
32+
}
33+
34+
bool process_encoder(){
35+
// test_encoder();return;
36+
static uint32_t lastService = 0;
37+
static int16_t encoder_prev;
38+
// encoder_value; // running total
39+
40+
// // throttle
41+
// if (micros() - lastService <= 200) {
42+
// return;
43+
// }
44+
45+
encoder.service();
46+
47+
encoder_value += encoder.getValue();
48+
// if(encoder_value!=0) Serial.print(encoder_value);
49+
// workaround for
50+
if (abs(encoder_value - encoder_prev) >= encoder_numsteps) {
51+
// if (encoder_value != encoder_prev) {
52+
Serial.print("Encoder Value: ");
53+
Serial.print(encoder_value);
54+
Serial.print(" Dir: ");
55+
Serial.println((encoder_value > encoder_prev) ? "10" : "20"); // L:R ints for plotting
56+
Serial.print("\t");
57+
Serial.print(" Steps: ");
58+
Serial.print((encoder_value-encoder_prev)/encoder_numsteps);
59+
Serial.print("\t");
60+
encoder_prev = encoder_value;
61+
return true;
62+
}
63+
return false;
64+
}
65+
66+
uint16_t getEncoder(){
67+
return encoder_value;
68+
}
69+
70+
void init_encoder(){
71+
72+
}

httpd.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <ESP8266WiFi.h>
2+
#include <WiFiClient.h>
3+
#include <ESP8266WebServer.h>
4+
#include <ESP8266mDNS.h>
5+
6+
ESP8266WebServer server(80);
7+
8+
void handleRoot() {
9+
10+
11+
if(server.hasArg(F("ledindex"))){
12+
Serial.println("has arg ledindex");
13+
String pixel = server.arg(F("ledindex"));
14+
// ledIndex = pixel;
15+
setPixel(pixel.toInt());
16+
// strip.setPixelColor(pixel.toInt(),strip.Color(255,0,0));
17+
Serial.println("Setting pixel:" + (String)pixel);
18+
// strip.show();
19+
// delay(2000);
20+
server.send(200, "text/plain", "hello from esp8266! ledindex SET");
21+
22+
}
23+
24+
if(server.hasArg(F("pwm"))){
25+
Serial.println("has arg PWM");
26+
String pwmvalue = server.arg(F("pwm"));
27+
// ledIndex = pixel;
28+
// setPWM(pwmvalue.toInt());
29+
// strip.setPixelColor(pixel.toInt(),strip.Color(255,0,0));
30+
Serial.println("Setting PWM:" + (String)pwmvalue);
31+
// strip.show();
32+
// delay(2000);
33+
// server.send(200, "text/plain", "hello from esp8266! PWM set:" + (String)getPWM());
34+
}
35+
36+
// digitalWrite(LED_BUILTIN, 1);
37+
server.send(200, "text/plain", "hello from esp8266!");
38+
// digitalWrite(LED_BUILTIN, 0);
39+
}
40+
41+
void handleNotFound() {
42+
// digitalWrite(LED_BUILTIN, 1);
43+
String message = "File Not Found\n\n";
44+
message += "URI: ";
45+
message += server.uri();
46+
message += "\nMethod: ";
47+
message += (server.method() == HTTP_GET) ? "GET" : "POST";
48+
message += "\nArguments: ";
49+
message += server.args();
50+
message += "\n";
51+
for (uint8_t i = 0; i < server.args(); i++) {
52+
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
53+
}
54+
server.send(404, "text/plain", message);
55+
// digitalWrite(LED_BUILTIN, 0);
56+
}
57+
58+
void httpd_init(){
59+
if (MDNS.begin("esp8266")) {
60+
Serial.println("MDNS responder started");
61+
}
62+
63+
server.on("/", handleRoot);
64+
65+
server.on("/inline", []() {
66+
server.send(200, "text/plain", "this works as well");
67+
});
68+
69+
server.onNotFound(handleNotFound);
70+
71+
server.on("/", HTTP_OPTIONS, []() {
72+
server.sendHeader("Access-Control-Max-Age", "10000");
73+
server.sendHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
74+
server.sendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
75+
server.send(200, "text/plain", "" );
76+
});
77+
78+
server.on("/", HTTP_GET, []() {
79+
String response ;
80+
// ... some code to prepare the response data...
81+
82+
server.sendHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS");
83+
server.sendHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
84+
server.send(200, "text/plain", response.c_str() );
85+
});
86+
87+
server.begin();
88+
Serial.println("HTTP server started");
89+
}
90+
91+
void httpd_process(void) {
92+
server.handleClient();
93+
MDNS.update();
94+
}

i2c_fans.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <Adafruit_MCP4725.h>
2+
3+
Adafruit_MCP4725 dac;
4+
Adafruit_MCP4725 dacb;
5+
6+
int percvalue = 41; // (4095/100);
7+
8+
int fanAVCC = 500; // fan dac vcc in mv
9+
int fanALOW = 170; // fan turn on voltage
10+
int fanAHI = 300; // fan max voltage
11+
int dacscale = 4095/5;
12+
13+
int fanAVCC_out = 12; // 5.2;
14+
int fanBVCC_out = 5; // 5.2;
15+
// should I calculate hfe /beta here or is that even necessary?
16+
17+
//
18+
// 5.00/4095 = .0122
19+
// .012 * 170 = 21
20+
21+
// 4095 / 5.00 = 819
22+
//
23+
24+
int fanDacVoltage(int vcc){
25+
return vcc*dacscale;
26+
}
27+
28+
void fan_init(){
29+
dac.begin(0x60);
30+
dacb.begin(0x61);
31+
dac.setVoltage(0, true);
32+
dacb.setVoltage(0, true);
33+
}
34+
35+
void fanA(int perc){
36+
int value = constrain(percvalue*perc,0,4095);
37+
dac.setVoltage(value, false);
38+
Serial.println("[FAN] 1 " + (String)perc +"% -" + value);
39+
}
40+
41+
void fanB(int perc){
42+
int value = constrain(percvalue*perc,0,4095);
43+
dacb.setVoltage(value, false);
44+
Serial.println("[FAN] 2 " + (String)perc +"% -" + value);
45+
}
46+
47+
void fanAVolts(int value){
48+
value = constrain(value,0,fanAVCC); // mv
49+
value = (value*dacscale)/100;
50+
dac.setVoltage((value), false);
51+
Serial.println("[FAN] 1 " + (String) value);
52+
}
53+
54+
void fanAV(int value){
55+
value = constrain(value,0,4095);
56+
dac.setVoltage(value, false);
57+
Serial.println("[FAN] 1 " + (String) value);
58+
}
59+
60+
void fanBV(int value){
61+
value = constrain(value,0,4095);
62+
dacb.setVoltage(value, false);
63+
Serial.println("[FAN] 2 " + (String) value);
64+
}
65+
66+
void fanBVolts(int value){
67+
value = constrain(value,0,fanAVCC); // mv
68+
value = (value*dacscale)/100;
69+
dacb.setVoltage((value), false);
70+
Serial.println("[FAN] 2 " + (String) value);
71+
}
72+
73+
void fanTest(){
74+
int duration = 1000;
75+
76+
fanBVolts(500); //5v
77+
delay(duration);
78+
fanBVolts(300); //5v
79+
delay(duration);
80+
fanBVolts(230); //5v
81+
delay(duration);
82+
fanBVolts(0); //5v
83+
delay(duration);
84+
fanAVolts(500); // 12v
85+
delay(duration);
86+
fanAVolts(300); // 12v
87+
delay(duration);
88+
fanAVolts(230); // 12v
89+
delay(duration);
90+
fanAVolts(0); // 12v
91+
}

0 commit comments

Comments
 (0)