mirror of
https://github.com/okalachev/flix.git
synced 2026-01-12 22:17:45 +00:00
Compare commits
1 Commits
stm
...
remove-esp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94fe93020d |
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@@ -29,13 +29,6 @@ jobs:
|
|||||||
run: sed -i 's/^#define WIFI_ENABLED 1$/#define WIFI_ENABLED 0/' flix/flix.ino && make
|
run: sed -i 's/^#define WIFI_ENABLED 1$/#define WIFI_ENABLED 0/' flix/flix.ino && make
|
||||||
- name: Check c_cpp_properties.json
|
- name: Check c_cpp_properties.json
|
||||||
run: tools/check_c_cpp_properties.py
|
run: tools/check_c_cpp_properties.py
|
||||||
- name: Build for Black Pill F411CE (STM32)
|
|
||||||
run: |
|
|
||||||
arduino-cli config set board_manager.additional_urls https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
|
|
||||||
arduino-cli core install STMicroelectronics:stm32
|
|
||||||
arduino-cli board listall STMicroelectronics:stm32
|
|
||||||
arduino-cli lib install "Preferences"
|
|
||||||
make BOARD=STMicroelectronics:stm32:GenF4:pnum=BLACKPILL_F411CE
|
|
||||||
|
|
||||||
build_macos:
|
build_macos:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|||||||
@@ -1,5 +1,2 @@
|
|||||||
board_manager:
|
|
||||||
additional_urls:
|
|
||||||
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
|
|
||||||
network:
|
network:
|
||||||
connection_timeout: 1h
|
connection_timeout: 1h
|
||||||
|
|||||||
@@ -25,32 +25,30 @@ const int MOTOR_FRONT_LEFT = 3;
|
|||||||
|
|
||||||
void setupMotors() {
|
void setupMotors() {
|
||||||
print("Setup Motors\n");
|
print("Setup Motors\n");
|
||||||
#ifdef ESP32
|
|
||||||
|
// configure pins
|
||||||
ledcAttach(MOTOR_0_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
ledcAttach(MOTOR_0_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
||||||
ledcAttach(MOTOR_1_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
ledcAttach(MOTOR_1_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
||||||
ledcAttach(MOTOR_2_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
ledcAttach(MOTOR_2_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
||||||
ledcAttach(MOTOR_3_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
ledcAttach(MOTOR_3_PIN, PWM_FREQUENCY, PWM_RESOLUTION);
|
||||||
#else
|
|
||||||
analogWriteResolution(PWM_RESOLUTION);
|
|
||||||
analogWriteFrequency(PWM_FREQUENCY);
|
|
||||||
#endif
|
|
||||||
sendMotors();
|
sendMotors();
|
||||||
print("Motors initialized\n");
|
print("Motors initialized\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDutyCycle(float value) {
|
int getDutyCycle(float value) {
|
||||||
value = constrain(value, 0, 1);
|
value = constrain(value, 0, 1);
|
||||||
float pwm = mapf(value, 0, 1, PWM_MIN, PWM_MAX);
|
float pwm = mapff(value, 0, 1, PWM_MIN, PWM_MAX);
|
||||||
if (value == 0) pwm = PWM_STOP;
|
if (value == 0) pwm = PWM_STOP;
|
||||||
float duty = mapf(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1);
|
float duty = mapff(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1);
|
||||||
return round(duty);
|
return round(duty);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMotors() {
|
void sendMotors() {
|
||||||
analogWrite(MOTOR_0_PIN, getDutyCycle(motors[0]));
|
ledcWrite(MOTOR_0_PIN, getDutyCycle(motors[0]));
|
||||||
analogWrite(MOTOR_1_PIN, getDutyCycle(motors[1]));
|
ledcWrite(MOTOR_1_PIN, getDutyCycle(motors[1]));
|
||||||
analogWrite(MOTOR_2_PIN, getDutyCycle(motors[2]));
|
ledcWrite(MOTOR_2_PIN, getDutyCycle(motors[2]));
|
||||||
analogWrite(MOTOR_3_PIN, getDutyCycle(motors[3]));
|
ledcWrite(MOTOR_3_PIN, getDutyCycle(motors[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool motorsActive() {
|
bool motorsActive() {
|
||||||
|
|||||||
10
flix/util.h
10
flix/util.h
@@ -6,15 +6,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#ifdef ESP32
|
|
||||||
#include <soc/soc.h>
|
#include <soc/soc.h>
|
||||||
#include <soc/rtc_cntl_reg.h>
|
#include <soc/rtc_cntl_reg.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
const float ONE_G = 9.80665;
|
const float ONE_G = 9.80665;
|
||||||
extern float t;
|
extern float t;
|
||||||
|
|
||||||
float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
|
float mapf(long x, long in_min, long in_max, float out_min, float out_max) {
|
||||||
|
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
|
||||||
|
}
|
||||||
|
|
||||||
|
float mapff(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +41,7 @@ float wrapAngle(float angle) {
|
|||||||
|
|
||||||
// Disable reset on low voltage
|
// Disable reset on low voltage
|
||||||
void disableBrownOut() {
|
void disableBrownOut() {
|
||||||
#ifdef ESP32
|
|
||||||
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA);
|
REG_CLR_BIT(RTC_CNTL_BROWN_OUT_REG, RTC_CNTL_BROWN_OUT_ENA);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim and split string by spaces
|
// Trim and split string by spaces
|
||||||
|
|||||||
Reference in New Issue
Block a user