-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tachometer Gauge Split to it's own file
- Loading branch information
Showing
8 changed files
with
312 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(e28-cluster) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := e28-cluster | ||
|
||
include $(IDF_PATH)/make/project.mk | ||
|
||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := e28-cluster | ||
|
||
include $(IDF_PATH)/make/project.mk | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
idf_component_register(SRCS "main.c" | ||
"fuel_gauge.c" | ||
"temp_gauge.c" | ||
"speedometer_gauge.c" | ||
INCLUDE_DIRS ".") | ||
idf_component_register(SRCS "main.c" | ||
"fuel_gauge.c" | ||
"temp_gauge.c" | ||
"speedometer_gauge.c" | ||
"tachometer_gauge.c" | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# | ||
# "main" pseudo-component makefile. | ||
# | ||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | ||
|
||
# | ||
# "main" pseudo-component makefile. | ||
# | ||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
#include "esp_err.h" | ||
#include "esp_log.h" | ||
|
||
#include <driver/gpio.h> | ||
#include <driver/dac.h> | ||
|
||
static dac_channel_t fuel_gauge_channel = -1; | ||
static gpio_num_t low_fuel_indicator_pin = -1; | ||
|
||
/** | ||
* Setup the temperature gauge output. | ||
* | ||
* @param gauge dac output pin | ||
* @param low_fuel_indicator output pin | ||
*/ | ||
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) { | ||
if(gauge != -1) { | ||
esp_err_t error = dac_output_enable(gauge); | ||
if(error == ESP_OK) { | ||
fuel_gauge_channel = gauge; | ||
} | ||
} | ||
|
||
if(low_fuel_indicator != -1 && | ||
( | ||
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are | ||
low_fuel_indicator > GPIO_NUM_39 // input only | ||
)) { | ||
gpio_config_t config = { | ||
.pin_bit_mask = low_fuel_indicator, | ||
.mode = GPIO_MODE_OUTPUT, | ||
.pull_up_en = GPIO_PULLUP_DISABLE, | ||
.pull_down_en = GPIO_PULLDOWN_ENABLE, | ||
.intr_type = GPIO_INTR_DISABLE | ||
}; | ||
esp_err_t error = gpio_config(&config); | ||
if(error == ESP_OK) { | ||
low_fuel_indicator_pin = low_fuel_indicator; | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Set the position of the fuel gauge in terms of % full | ||
* | ||
* @param percent_full for the gauge to point to | ||
*/ | ||
void write_to_fuel_gauge(int percent_full) { | ||
if(fuel_gauge_channel == -1) { | ||
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
int voltage = 70 + ((percent_full * 80) / 100); | ||
voltage &= 255; | ||
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full); | ||
dac_output_voltage(fuel_gauge_channel, voltage); | ||
} | ||
} | ||
|
||
/** | ||
* Turns the low fuel indicator light on if it's hooked up. | ||
*/ | ||
void enable_low_fuel_indicator() { | ||
if(low_fuel_indicator_pin == -1) { | ||
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
gpio_set_level(low_fuel_indicator_pin, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Turns the low fuel indicator light off if it's hooked up. | ||
*/ | ||
void disable_low_fuel_indicator() { | ||
if(low_fuel_indicator_pin == -1) { | ||
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
gpio_set_level(low_fuel_indicator_pin, 0); | ||
} | ||
#include "esp_err.h" | ||
#include "esp_log.h" | ||
|
||
#include <driver/gpio.h> | ||
#include <driver/dac.h> | ||
|
||
static dac_channel_t fuel_gauge_channel = -1; | ||
static gpio_num_t low_fuel_indicator_pin = -1; | ||
|
||
/** | ||
* Setup the temperature gauge output. | ||
* | ||
* @param gauge dac output pin | ||
* @param low_fuel_indicator output pin | ||
*/ | ||
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) { | ||
if(gauge != -1) { | ||
esp_err_t error = dac_output_enable(gauge); | ||
if(error == ESP_OK) { | ||
fuel_gauge_channel = gauge; | ||
} | ||
} | ||
|
||
if(low_fuel_indicator != -1 && | ||
( | ||
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are | ||
low_fuel_indicator > GPIO_NUM_39 // input only | ||
)) { | ||
gpio_config_t config = { | ||
.pin_bit_mask = low_fuel_indicator, | ||
.mode = GPIO_MODE_OUTPUT, | ||
.pull_up_en = GPIO_PULLUP_DISABLE, | ||
.pull_down_en = GPIO_PULLDOWN_ENABLE, | ||
.intr_type = GPIO_INTR_DISABLE | ||
}; | ||
esp_err_t error = gpio_config(&config); | ||
if(error == ESP_OK) { | ||
low_fuel_indicator_pin = low_fuel_indicator; | ||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Set the position of the fuel gauge in terms of % full | ||
* | ||
* @param percent_full for the gauge to point to | ||
*/ | ||
void write_to_fuel_gauge(int percent_full) { | ||
if(fuel_gauge_channel == -1) { | ||
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
int voltage = 70 + ((percent_full * 80) / 100); | ||
voltage &= 255; | ||
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full); | ||
dac_output_voltage(fuel_gauge_channel, voltage); | ||
} | ||
} | ||
|
||
/** | ||
* Turns the low fuel indicator light on if it's hooked up. | ||
*/ | ||
void enable_low_fuel_indicator() { | ||
if(low_fuel_indicator_pin == -1) { | ||
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
gpio_set_level(low_fuel_indicator_pin, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Turns the low fuel indicator light off if it's hooked up. | ||
*/ | ||
void disable_low_fuel_indicator() { | ||
if(low_fuel_indicator_pin == -1) { | ||
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first."); | ||
} else { | ||
gpio_set_level(low_fuel_indicator_pin, 0); | ||
} | ||
} |
Oops, something went wrong.