Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
leon0399 committed Jan 9, 2023
2 parents 963f4a5 + fc13d0c commit 2694600
Show file tree
Hide file tree
Showing 52 changed files with 1,329 additions and 1,236 deletions.
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
BasedOnStyle: Chromium
AllowShortBlocksOnASingleLine: 'false'
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: 'false'
CompactNamespaces: 'false'
Language: Cpp
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: 'true'
UseTab: Never
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

[CMakeLists.txt]
indent_style = space
indent_size = 4
max_line_length = 80

[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
indent_size = 2
cpp_indent_case_contents_when_block = true
cpp_new_line_before_open_brace_namespace = same_line

[*.md]
trim_trailing_whitespace = false

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
# - run: git checkout HEAD^2
Expand All @@ -57,11 +57,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
Expand All @@ -70,13 +70,13 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Cache pip
uses: actions/cache@v3
with:
Expand All @@ -102,7 +102,7 @@ jobs:
pip install --upgrade platformio
pio upgrade --dev
pio pkg update --global
- name: Build
run: |
pio run --environment bhaptics_tactsuit_x40
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ jobs:
with:
asset_name: ${{matrix.target}}.zip
file: ./build/firmware.zip
tag: ${{github.ref}}
tag: ${{github.ref}}
40 changes: 19 additions & 21 deletions firmware/auto_output.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
#include "auto_output.h"

Point2D* getPoint(uint16_t x, uint16_t y, uint16_t x_max, uint16_t y_max)
{
const uint16_t x_coord = 1 == x_max ? 1 : UINT16_MAX * (1 / ((float)x_max - 1)) * ((float)x);
const uint16_t y_coord = 1 == y_max ? 1 : UINT16_MAX * (1 / ((float)y_max - 1)) * ((float)y);
Point2D* getPoint(uint16_t x, uint16_t y, uint16_t x_max, uint16_t y_max) {
const uint16_t x_coord =
1 == x_max ? 1 : UINT16_MAX * (1 / ((float)x_max - 1)) * ((float)x);
const uint16_t y_coord =
1 == y_max ? 1 : UINT16_MAX * (1 / ((float)y_max - 1)) * ((float)y);

return new Point2D(x_coord, y_coord);
return new Point2D(x_coord, y_coord);
}

outputMap_t transformAutoOutput(std::vector<std::vector<OutputWriter*>> map2d)
{
outputMap_t points{};
outputMap_t transformAutoOutput(std::vector<std::vector<OutputWriter*>> map2d) {
outputMap_t points{};

size_t y_max = map2d.size();
size_t y_max = map2d.size();

for (size_t y = 0; y < y_max; ++y)
{
auto row = map2d.at(y);
size_t x_max = row.size();
for (size_t y = 0; y < y_max; ++y) {
auto row = map2d.at(y);
size_t x_max = row.size();

for (size_t x = 0; x < x_max; ++x)
{
OutputWriter* wr = row.at(x);
Point2D* coord = getPoint(x, y, x_max, y_max);
for (size_t x = 0; x < x_max; ++x) {
OutputWriter* wr = row.at(x);
Point2D* coord = getPoint(x, y, x_max, y_max);

points[*coord] = wr;
}
points[*coord] = wr;
}
}

return points;
}
return points;
}
16 changes: 8 additions & 8 deletions firmware/battery/abstract_battery.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "battery/abstract_battery.h"
#include <Arduino.h>

void AbstractBattery::loop()
{
auto now_ms = millis();
void AbstractBattery::loop() {
auto now_ms = millis();

if (now_ms - this->last_battery_sample >= BATTERY_SAMPLE_RATE) {
this->last_battery_sample = now_ms;
if (now_ms - this->last_battery_sample >= BATTERY_SAMPLE_RATE) {
this->last_battery_sample = now_ms;

this->level = this->updateLevel();
this->level = this->updateLevel();

Serial.printf(">>\t%s: %3u (took %lu ms)\n", __PRETTY_FUNCTION__, this->level, now_ms - millis());
}
Serial.printf(">>\t%s: %3u (took %lu ms)\n", __PRETTY_FUNCTION__,
this->level, now_ms - millis());
}
};
5 changes: 2 additions & 3 deletions firmware/battery/adc_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <Arduino.h>

uint8_t ADCBattery::updateLevel()
{
return map(analogRead(this->pin), 0.0f, 4095.0f, 0, 255);
uint8_t ADCBattery::updateLevel() {
return map(analogRead(this->pin), 0.0f, 4095.0f, 0, 255);
}
21 changes: 21 additions & 0 deletions firmware/battery/ina219.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "openhaptics.h"
#include "battery/ina219.h"
#include "config/battery.h"

void INA219_BatteryLevel::setup()
{
this->active = this->sensor->begin();
}

uint8_t INA219_BatteryLevel::updateLevel()
{
if (!this->active) {
return 0;
}

auto batteryVoltage = this->sensor->getBusVoltage_V();
// TODO: change this linear transformation to smth more useful
auto batteryPercentage = (batteryVoltage - 3.0) / 0.96;

return map(batteryPercentage, 0.0f, 1.0f, 0, 255);
}
6 changes: 5 additions & 1 deletion firmware/battery/max17048.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ void MAX1704_BatteryLevel::setup()

uint8_t MAX1704_BatteryLevel::updateLevel()
{
return this->gauge->getSOC();
if (!this->active) {
return 0;
}

return this->gauge->getSOC();
}
12 changes: 5 additions & 7 deletions firmware/component.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "component.h"

void Component::setup()
{}

void Component::loop()
{}
#include "component.h"

void Component::setup() {}

void Component::loop() {}
34 changes: 15 additions & 19 deletions firmware/components/serial_plotter.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#include "openhaptics.h"
#include "components/serial_plotter.h"

void SerialPlotter_OutputStates::setup()
{
this->serial->begin(115200);
}

void SerialPlotter_OutputStates::loop()
{
for (auto &_c : *App.getOutput()->getComponents())
{
for (auto &_s : *_c.second->getOutputStates())
{
this->serial->printf("%5u \t", _s.second.intensity);
}
}
this->serial->println();
}
#include "components/serial_plotter.h"
#include "openhaptics.h"

void SerialPlotter_OutputStates::setup() {
this->serial->begin(115200);
}

void SerialPlotter_OutputStates::loop() {
for (auto& _c : *App.getOutput()->getComponents()) {
for (auto& _s : *_c.second->getOutputStates()) {
this->serial->printf("%5u \t", _s.second.intensity);
}
}
this->serial->println();
}
Loading

0 comments on commit 2694600

Please sign in to comment.