more led stuff

This commit is contained in:
Wolfgang Hottgenroth 2019-10-31 21:54:18 +01:00
parent 236632cf63
commit 5e0187da1f
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 22 additions and 2 deletions

View File

@ -29,6 +29,7 @@ void isr() {
lastCounter = currentCounter; lastCounter = currentCounter;
ringbufferPut(diff); ringbufferPut(diff);
led(E_GREEN, true);
} }
void init() { void init() {
@ -65,13 +66,20 @@ int main (void) {
influxInit(&cfg); influxInit(&cfg);
start(); start();
uint32_t ledTick = 0;
while (1) { while (1) {
uint32_t diff = ringbufferGet(); uint32_t diff = ringbufferGet();
double f = 1.0 / (((double) diff) / 1000000.0); double f = 1.0 / (((double) diff) / 1000000.0);
// printf("%f\n", f); // printf("%f\n", f);
influxAddFrequency(f); influxAddFrequency(f);
ledTick++;
if (ledTick == 100) {
ledTick = 0;
led(E_GREEN, false);
}
} }
// will never be reached // will never be reached

View File

@ -6,6 +6,8 @@
#include <unistd.h> #include <unistd.h>
#include <libconfig.h> #include <libconfig.h>
#include "led.h"
const char INFLUXURL_KEY[] = "influxUrl"; const char INFLUXURL_KEY[] = "influxUrl";
const char DEFAULT_INFLUXURL[] = "http://172.16.3.15:8086/write?db=smarthome2&precision=ms"; const char DEFAULT_INFLUXURL[] = "http://172.16.3.15:8086/write?db=smarthome2&precision=ms";
@ -53,6 +55,8 @@ void influxInit(config_t *pCfg) {
static void influxSendRequest() { static void influxSendRequest() {
led(E_RED, false);
led(E_BLUE, true);
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(curl) { if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, influxUrl); curl_easy_setopt(curl, CURLOPT_URL, influxUrl);
@ -65,9 +69,11 @@ static void influxSendRequest() {
CURLcode res = curl_easy_perform(curl); CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK) { if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
led(E_RED, true);
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
led(E_BLUE, false);
} }
void influxAddFrequency(double f) { void influxAddFrequency(double f) {

View File

@ -22,5 +22,11 @@ void ledInit() {
void led (tColor color, bool state) { void led (tColor color, bool state) {
if (color == E_RED) {
digitalWrite(RED_OUT, state ? 1 : 0);
} elif (color = E_BLUE) {
digitalWrite(BLUE_OUT, state ? 1 : 0);
} elif (color = E_GREEN) {
digitalWrite(GREEN_OUT, state ? 1 : 0);
}
} }