Skip to content

Commit e46b412

Browse files
author
Ezra Boley
authored
Merge pull request #15 from FANTM/development
0.3.1 for release
2 parents 0c20659 + 3e6cb1c commit e46b412

24 files changed

Lines changed: 675 additions & 498 deletions

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a single version of Python
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Python application
4+
name: Test Python App
55

66
on:
77
push:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
jobs:
16+
deploy:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: '3.x'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
30+
export PATH="$PATH:$HOME/.poetry/bin"
31+
poetry install
32+
- name: Build package
33+
run: |
34+
export PATH="$PATH:$HOME/.poetry/bin"
35+
poetry build
36+
- name: Publish package
37+
run: |
38+
export PATH="$PATH:$HOME/.poetry/bin"
39+
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
40+
poetry publish
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Verify Version Update
5+
6+
on:
7+
pull_request:
8+
branches: [ main, development ]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python 3.9
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: 3.9
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
25+
export PATH="$PATH:$HOME/.poetry/bin"
26+
bash ./check_version.sh
27+
exit $?

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__/
2-
.mypy_cache/
2+
.mypy_cache/
3+
dist/
Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1-
#include "Libdevlpr.h"
2-
3-
#define PACK(pin, data) ((((pin) & 0x000F) << 12) | ((data) & 0x0FFF))
4-
51
/* Set these parameters based on your hardware setup */
6-
int NUM_DEVLPRS = 1;
2+
#define BAUD 2000000
3+
#define NUM_DEVLPRS 1
74
int DEVLPR_PINS[] = {A0};
5+
int EMG_VALS[NUM_DEVLPRS];
86
/*****************************************************/
97

10-
const int MAX_RESULTS = 2;
11-
volatile int results [MAX_RESULTS];
12-
volatile int resultNumber;
8+
byte bufOut[4];
9+
volatile bool dataReady = false;
1310

14-
unsigned long lastTickMicros = 0L;
15-
unsigned long microsSinceEMG = 0L;
16-
Devlpr dev(A0, FILTER_60HZ);
17-
void printEMG(Devlpr *d);
11+
ISR(TIMER0_COMPA_vect) { // Timer0 interrupt, 1kHz
12+
if (!dataReady) {
13+
for (int i = 0; i < NUM_DEVLPRS; i++) {
14+
EMG_VALS[i] = analogRead(DEVLPR_PINS[i]);
15+
}
16+
dataReady = true;
17+
}
18+
}
1819

1920
void setup() {
20-
Serial.begin(2000000);
21-
Serial.println();
22-
dev.scheduleFunction(printEMG, 1);
21+
cli(); // Stop interrupts
22+
//set timer0 interrupt at 1kHz
23+
TCCR0A = 0;// set entire TCCR0A register to 0
24+
TCCR0B = 0;// same for TCCR0B
25+
TCNT0 = 0;//initialize counter value to 0
26+
// set compare match register for 1khz increments
27+
OCR0A = 249;// = (16*10^6) / (1000*64) - 1 (must be <256)
28+
// turn on CTC mode
29+
TCCR0A |= (1 << WGM01);
30+
// Set CS01 and CS00 bits for 64 prescaler
31+
TCCR0B |= (1 << CS01) | (1 << CS00);
32+
// enable timer compare interrupt
33+
TIMSK0 |= (1 << OCIE0A);
34+
sei(); // Start interrupts
35+
36+
Serial.begin(BAUD);
2337
}
2438

2539
/* Safety check in case the alias of A0-A5 isn't directly mapped to the number
2640
we expect */
27-
uint8_t normalize_pin(int analogPin) {
41+
byte normalizePin(int analogPin) {
2842
switch (analogPin)
2943
{
3044
case A0:
@@ -45,21 +59,26 @@ uint8_t normalize_pin(int analogPin) {
4559
}
4660

4761
/* Helper function for formatting data in the way that the daemon expects */
48-
void fill_packet(uint8_t *buffOut, uint8_t pin, uint16_t data) {
49-
uint16_t payload = PACK(pin, data);
50-
buffOut[0] = ((payload & 0xFF00) >> 8) & 0x00FF;
51-
buffOut[1] = payload & 0xFF;
52-
buffOut[2] = '\r';
53-
buffOut[3] = '\n';
54-
}
55-
56-
void printEMG(Devlpr *d) {
57-
int filtered = d->windowPeakToPeakAmplitude(true);
58-
uint8_t buffOut[4];
59-
fill_packet(buffOut, normalize_pin(A0), (uint16_t) filtered);
60-
Serial.write(buffOut, 4);
62+
void fillPacket(byte *buffOut, byte pin, int value) {
63+
// pack 16-bits for the emg value and 4 bits for the pin into
64+
// three bytes in the following fashion (e=emg, p=pin)
65+
// eeee eee0
66+
// eeee eee0
67+
// eepp pp00
68+
// and terminate with a 1
69+
// 0000 0001
70+
buffOut[0] = (value >> 8) & 0xFE;
71+
buffOut[1] = (value >> 1) & 0xFE;
72+
buffOut[2] = ((value << 6) & 0xC0) | ((pin << 2) & 0x3C);
73+
buffOut[3] = 0x01;
6174
}
6275

6376
void loop() {
64-
dev.tick();
77+
if (dataReady) {
78+
for (int i = 0; i < NUM_DEVLPRS; i++) {
79+
fillPacket(bufOut, normalizePin(DEVLPR_PINS[i]), EMG_VALS[i]);
80+
Serial.write(bufOut, 4);
81+
}
82+
dataReady = false;
83+
}
6584
}

check_version.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
CURR_V=$(poetry version)
4+
cd ..
5+
git clone https://github.com/FANTM/devlprd devlprd-main
6+
cd devlprd-main
7+
MAIN_V=$(poetry version)
8+
cd ..
9+
rm -rf devlprd-main
10+
if [[ $MAIN_V = $CURR_V ]]
11+
then
12+
echo "Bump the version!"
13+
exit 1
14+
else
15+
exit 0
16+
fi

0 commit comments

Comments
 (0)