diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml deleted file mode 100644 index 5e1d3d3..0000000 --- a/.github/workflows/python.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Unit Tests - -on: - push: - branches: [ main ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - testing: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - - name: Run tests - run: | - pytest - - diff --git a/.venv/bin/flask b/.venv/bin/flask new file mode 100755 index 0000000..d58b7a5 --- /dev/null +++ b/.venv/bin/flask @@ -0,0 +1,8 @@ +#!/home/schufeli/Github/backend/.venv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from flask.cli import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/.venv/bin/normalizer b/.venv/bin/normalizer new file mode 100755 index 0000000..601fb19 --- /dev/null +++ b/.venv/bin/normalizer @@ -0,0 +1,8 @@ +#!/home/schufeli/Github/backend/.venv/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from charset_normalizer.cli.normalizer import cli_detect +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(cli_detect()) diff --git a/.venv/include/site/python3.10/greenlet/greenlet.h b/.venv/include/site/python3.10/greenlet/greenlet.h new file mode 100644 index 0000000..c788b2f --- /dev/null +++ b/.venv/include/site/python3.10/greenlet/greenlet.h @@ -0,0 +1,161 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; -*- */ + +/* Greenlet object interface */ + +#ifndef Py_GREENLETOBJECT_H +#define Py_GREENLETOBJECT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* This is deprecated and undocumented. It does not change. */ +#define GREENLET_VERSION "1.0.0" + +#if PY_VERSION_HEX >= 0x30B00A6 +# define GREENLET_PY311 1 + /* _PyInterpreterFrame moved to the internal C API in Python 3.11 */ +# include +#else +# define GREENLET_PY311 0 +# define _PyCFrame CFrame +#endif + +typedef struct _greenlet { + PyObject_HEAD + char* stack_start; + char* stack_stop; + char* stack_copy; + intptr_t stack_saved; + struct _greenlet* stack_prev; + struct _greenlet* parent; + PyObject* run_info; + struct _frame* top_frame; + int recursion_depth; +#if GREENLET_PY311 + _PyInterpreterFrame *current_frame; + _PyStackChunk *datastack_chunk; + PyObject **datastack_top; + PyObject **datastack_limit; +#endif + PyObject* weakreflist; +#if PY_VERSION_HEX >= 0x030700A3 + _PyErr_StackItem* exc_info; + _PyErr_StackItem exc_state; +#else + PyObject* exc_type; + PyObject* exc_value; + PyObject* exc_traceback; +#endif + PyObject* dict; +#if PY_VERSION_HEX >= 0x030700A3 + PyObject* context; +#endif +#if PY_VERSION_HEX >= 0x30A00B1 + _PyCFrame* cframe; +#endif +} PyGreenlet; + +#define PyGreenlet_Check(op) PyObject_TypeCheck(op, &PyGreenlet_Type) +#define PyGreenlet_MAIN(op) (((PyGreenlet*)(op))->stack_stop == (char*)-1) +#define PyGreenlet_STARTED(op) (((PyGreenlet*)(op))->stack_stop != NULL) +#define PyGreenlet_ACTIVE(op) (((PyGreenlet*)(op))->stack_start != NULL) +#define PyGreenlet_GET_PARENT(op) (((PyGreenlet*)(op))->parent) + +/* C API functions */ + +/* Total number of symbols that are exported */ +#define PyGreenlet_API_pointers 8 + +#define PyGreenlet_Type_NUM 0 +#define PyExc_GreenletError_NUM 1 +#define PyExc_GreenletExit_NUM 2 + +#define PyGreenlet_New_NUM 3 +#define PyGreenlet_GetCurrent_NUM 4 +#define PyGreenlet_Throw_NUM 5 +#define PyGreenlet_Switch_NUM 6 +#define PyGreenlet_SetParent_NUM 7 + +#ifndef GREENLET_MODULE +/* This section is used by modules that uses the greenlet C API */ +static void** _PyGreenlet_API = NULL; + +# define PyGreenlet_Type \ + (*(PyTypeObject*)_PyGreenlet_API[PyGreenlet_Type_NUM]) + +# define PyExc_GreenletError \ + ((PyObject*)_PyGreenlet_API[PyExc_GreenletError_NUM]) + +# define PyExc_GreenletExit \ + ((PyObject*)_PyGreenlet_API[PyExc_GreenletExit_NUM]) + +/* + * PyGreenlet_New(PyObject *args) + * + * greenlet.greenlet(run, parent=None) + */ +# define PyGreenlet_New \ + (*(PyGreenlet * (*)(PyObject * run, PyGreenlet * parent)) \ + _PyGreenlet_API[PyGreenlet_New_NUM]) + +/* + * PyGreenlet_GetCurrent(void) + * + * greenlet.getcurrent() + */ +# define PyGreenlet_GetCurrent \ + (*(PyGreenlet * (*)(void)) _PyGreenlet_API[PyGreenlet_GetCurrent_NUM]) + +/* + * PyGreenlet_Throw( + * PyGreenlet *greenlet, + * PyObject *typ, + * PyObject *val, + * PyObject *tb) + * + * g.throw(...) + */ +# define PyGreenlet_Throw \ + (*(PyObject * (*)(PyGreenlet * self, \ + PyObject * typ, \ + PyObject * val, \ + PyObject * tb)) \ + _PyGreenlet_API[PyGreenlet_Throw_NUM]) + +/* + * PyGreenlet_Switch(PyGreenlet *greenlet, PyObject *args) + * + * g.switch(*args, **kwargs) + */ +# define PyGreenlet_Switch \ + (*(PyObject * \ + (*)(PyGreenlet * greenlet, PyObject * args, PyObject * kwargs)) \ + _PyGreenlet_API[PyGreenlet_Switch_NUM]) + +/* + * PyGreenlet_SetParent(PyObject *greenlet, PyObject *new_parent) + * + * g.parent = new_parent + */ +# define PyGreenlet_SetParent \ + (*(int (*)(PyGreenlet * greenlet, PyGreenlet * nparent)) \ + _PyGreenlet_API[PyGreenlet_SetParent_NUM]) + +/* Macro that imports greenlet and initializes C API */ +/* NOTE: This has actually moved to ``greenlet._greenlet._C_API``, but we + keep the older definition to be sure older code that might have a copy of + the header still works. */ +# define PyGreenlet_Import() \ + { \ + _PyGreenlet_API = (void**)PyCapsule_Import("greenlet._C_API", 0); \ + } + +#endif /* GREENLET_MODULE */ + +#ifdef __cplusplus +} +#endif +#endif /* !Py_GREENLETOBJECT_H */ diff --git a/api/main.py b/api/main.py index cf529d7..651f48b 100644 --- a/api/main.py +++ b/api/main.py @@ -1,2 +1,55 @@ -#!/usr/bin/env python +from distutils.log import debug +from flask import Flask, render_template +from flask_socketio import SocketIO, emit, send +import RPi.GPIO as GPIO +import time +import threading + +GPIO.setmode(GPIO.BOARD) +GPIO.setup(38, GPIO.IN) + +current_kmh = 0 + +app = Flask(__name__) +socketio = SocketIO(app, cors_allowed_origins="*") + +@app.route('/') +def index(): + return render_template('index.html') + +def calculate_rpm(cycles_per_second): + revperminute = cycles_per_second * 60 + meterperminute = revperminute * 90 / 100 + return str(round((meterperminute / 16.667))) + +def main(): + global current_kmh + counter = 1 + last = 0 + def counter_loop(): + nonlocal last + nonlocal counter + while True: + data = GPIO.input(38) + if last != data: + last = data + counter += 1 + + th = threading.Thread(target=counter_loop) + th.start() + + while True: + counter_before = counter + time.sleep(0.5) + counter_after = counter + + ticks_per_s = counter_after - counter_before + cycles_per_second = ticks_per_s / 6 + current_kmh = calculate_rpm(cycles_per_second) + socketio.emit("currentVelocity", current_kmh) + socketio.emit("currentRPM", cycles_per_second * 60) + +threading.Thread(target=main).start() + +socketio.run(app=app, host="192.168.0.100", debug=True) diff --git a/api/templates/index.html b/api/templates/index.html new file mode 100644 index 0000000..286af08 --- /dev/null +++ b/api/templates/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + +

Komax gocart api

+ + \ No newline at end of file diff --git a/api/test/test_api.py b/api/test/test_api.py deleted file mode 100644 index cc70157..0000000 --- a/api/test/test_api.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_example(): - assert 1 == 1 \ No newline at end of file diff --git a/library/test/test_library.py b/library/test/test_library.py deleted file mode 100644 index cc70157..0000000 --- a/library/test/test_library.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_example(): - assert 1 == 1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8b91fdf..59f5565 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,35 @@ +aiohttp==3.8.3 +aiosignal==1.2.0 +async-timeout==4.0.2 attrs==22.1.0 +bidict==0.22.0 +charset-normalizer==2.1.1 +click==8.1.3 exceptiongroup==1.0.0 +Flask==2.2.2 +Flask-SocketIO==5.3.1 +frozenlist==1.3.1 +gevent==22.10.1 +gevent-websocket==0.10.1 +greenlet==1.1.3.post0 +idna==3.4 iniconfig==1.1.1 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.1 +marshmallow==2.21.0 +multidict==6.0.2 packaging==21.3 pluggy==1.0.0 pyparsing==3.0.9 pytest==7.2.0 +python-dateutil==2.8.2 +python-engineio==4.3.4 +python-socketio==5.7.2 +RPi.GPIO==0.7.1 +six==1.16.0 tomli==2.0.1 -websockets==10.4 +Werkzeug==2.2.2 +yarl==1.8.1 +zope.event==4.5.0 +zope.interface==5.5.0