Skip to content

Commit f6a7d31

Browse files
committed
Tachometer Gauge Split to it's own file
1 parent 4f6b1c6 commit f6a7d31

8 files changed

+312
-247
lines changed

code/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# The following lines of boilerplate have to be in your project's
2-
# CMakeLists in this exact order for cmake to work correctly
3-
cmake_minimum_required(VERSION 3.5)
4-
5-
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
66
project(e28-cluster)

code/Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#
2-
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3-
# project subdirectory.
4-
#
5-
6-
PROJECT_NAME := e28-cluster
7-
8-
include $(IDF_PATH)/make/project.mk
9-
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := e28-cluster
7+
8+
include $(IDF_PATH)/make/project.mk
9+

code/main/CMakeLists.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
idf_component_register(SRCS "main.c"
2-
"fuel_gauge.c"
3-
"temp_gauge.c"
4-
"speedometer_gauge.c"
5-
INCLUDE_DIRS ".")
1+
idf_component_register(SRCS "main.c"
2+
"fuel_gauge.c"
3+
"temp_gauge.c"
4+
"speedometer_gauge.c"
5+
"tachometer_gauge.c"
6+
INCLUDE_DIRS ".")

code/main/component.mk

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#
2-
# "main" pseudo-component makefile.
3-
#
4-
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5-
1+
#
2+
# "main" pseudo-component makefile.
3+
#
4+
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5+

code/main/fuel_gauge.c

+79-79
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
#include "esp_err.h"
2-
#include "esp_log.h"
3-
4-
#include <driver/gpio.h>
5-
#include <driver/dac.h>
6-
7-
static dac_channel_t fuel_gauge_channel = -1;
8-
static gpio_num_t low_fuel_indicator_pin = -1;
9-
10-
/**
11-
* Setup the temperature gauge output.
12-
*
13-
* @param gauge dac output pin
14-
* @param low_fuel_indicator output pin
15-
*/
16-
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) {
17-
if(gauge != -1) {
18-
esp_err_t error = dac_output_enable(gauge);
19-
if(error == ESP_OK) {
20-
fuel_gauge_channel = gauge;
21-
}
22-
}
23-
24-
if(low_fuel_indicator != -1 &&
25-
(
26-
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are
27-
low_fuel_indicator > GPIO_NUM_39 // input only
28-
)) {
29-
gpio_config_t config = {
30-
.pin_bit_mask = low_fuel_indicator,
31-
.mode = GPIO_MODE_OUTPUT,
32-
.pull_up_en = GPIO_PULLUP_DISABLE,
33-
.pull_down_en = GPIO_PULLDOWN_ENABLE,
34-
.intr_type = GPIO_INTR_DISABLE
35-
};
36-
esp_err_t error = gpio_config(&config);
37-
if(error == ESP_OK) {
38-
low_fuel_indicator_pin = low_fuel_indicator;
39-
}
40-
41-
}
42-
}
43-
44-
/**
45-
* Set the position of the fuel gauge in terms of % full
46-
*
47-
* @param percent_full for the gauge to point to
48-
*/
49-
void write_to_fuel_gauge(int percent_full) {
50-
if(fuel_gauge_channel == -1) {
51-
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first.");
52-
} else {
53-
int voltage = 70 + ((percent_full * 80) / 100);
54-
voltage &= 255;
55-
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full);
56-
dac_output_voltage(fuel_gauge_channel, voltage);
57-
}
58-
}
59-
60-
/**
61-
* Turns the low fuel indicator light on if it's hooked up.
62-
*/
63-
void enable_low_fuel_indicator() {
64-
if(low_fuel_indicator_pin == -1) {
65-
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
66-
} else {
67-
gpio_set_level(low_fuel_indicator_pin, 1);
68-
}
69-
}
70-
71-
/**
72-
* Turns the low fuel indicator light off if it's hooked up.
73-
*/
74-
void disable_low_fuel_indicator() {
75-
if(low_fuel_indicator_pin == -1) {
76-
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
77-
} else {
78-
gpio_set_level(low_fuel_indicator_pin, 0);
79-
}
1+
#include "esp_err.h"
2+
#include "esp_log.h"
3+
4+
#include <driver/gpio.h>
5+
#include <driver/dac.h>
6+
7+
static dac_channel_t fuel_gauge_channel = -1;
8+
static gpio_num_t low_fuel_indicator_pin = -1;
9+
10+
/**
11+
* Setup the temperature gauge output.
12+
*
13+
* @param gauge dac output pin
14+
* @param low_fuel_indicator output pin
15+
*/
16+
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) {
17+
if(gauge != -1) {
18+
esp_err_t error = dac_output_enable(gauge);
19+
if(error == ESP_OK) {
20+
fuel_gauge_channel = gauge;
21+
}
22+
}
23+
24+
if(low_fuel_indicator != -1 &&
25+
(
26+
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are
27+
low_fuel_indicator > GPIO_NUM_39 // input only
28+
)) {
29+
gpio_config_t config = {
30+
.pin_bit_mask = low_fuel_indicator,
31+
.mode = GPIO_MODE_OUTPUT,
32+
.pull_up_en = GPIO_PULLUP_DISABLE,
33+
.pull_down_en = GPIO_PULLDOWN_ENABLE,
34+
.intr_type = GPIO_INTR_DISABLE
35+
};
36+
esp_err_t error = gpio_config(&config);
37+
if(error == ESP_OK) {
38+
low_fuel_indicator_pin = low_fuel_indicator;
39+
}
40+
41+
}
42+
}
43+
44+
/**
45+
* Set the position of the fuel gauge in terms of % full
46+
*
47+
* @param percent_full for the gauge to point to
48+
*/
49+
void write_to_fuel_gauge(int percent_full) {
50+
if(fuel_gauge_channel == -1) {
51+
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first.");
52+
} else {
53+
int voltage = 70 + ((percent_full * 80) / 100);
54+
voltage &= 255;
55+
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full);
56+
dac_output_voltage(fuel_gauge_channel, voltage);
57+
}
58+
}
59+
60+
/**
61+
* Turns the low fuel indicator light on if it's hooked up.
62+
*/
63+
void enable_low_fuel_indicator() {
64+
if(low_fuel_indicator_pin == -1) {
65+
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
66+
} else {
67+
gpio_set_level(low_fuel_indicator_pin, 1);
68+
}
69+
}
70+
71+
/**
72+
* Turns the low fuel indicator light off if it's hooked up.
73+
*/
74+
void disable_low_fuel_indicator() {
75+
if(low_fuel_indicator_pin == -1) {
76+
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
77+
} else {
78+
gpio_set_level(low_fuel_indicator_pin, 0);
79+
}
8080
}

0 commit comments

Comments
 (0)