嵌入式 C PWM 调光器到 Django 网络应用程序

Embedded C PWM dimmer to Django web app

我开发了带 MOSFET 的 PWM 调光器,用于嵌入式 C 中的 220V 灯,它通过 GPIO 引脚和 OpenWRT 上的 运行 工作。

这是低级代码(具有寄存器访问权限)。

我有两个控制亮度的按钮(连接在输入 GPIO 引脚上,我可以在程序中增加和减少 PWM 频率)。

我想在我控制亮度的 Django 网络应用程序中实现两个按钮或滚动,而不是通过 GPIO。

如何将此 C 程序嵌入到 Django 网络应用程序并连接到网络滚动条或按钮?

有没有什么方法可以在 C 程序和 Django 网络应用程序之间进行交互,在我的例子中是网络滚动或按钮,而不是 GPIO?

也许最好的方法是 运行 将提高频率的程序与降低频率的程序分开,并且 运行 当按下按钮时,但我如何使用滚动来实现?

我是初学者

非常感谢。

这是代码的开头:

#define BCM2708_PERI_BASE 0x3F000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
#define PWM_BASE (BCM2708_PERI_BASE 0x20C000 +) /* PWM controller*/
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000)

#define PWM_CTL 0
#define PWM_RNG1 4
#define PWM_DAT1 5

#define PWMCLK_CNTL 40
#define PWMCLK_DIV 41

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

...

Django 是用 Python 编写的。您正在使用 BCM2708,听起来像 Raspberry Pi 2.

您可以使用已经为您编写的 Python 库,例如raspberry-gpio-python and there is already such functionality so no need to reinvent the wheel. Here is documentation about controlling PWM from Python.

还有更多选择。

您还可以在 Raspberry Pi for controlling GPIO

上查看使用 Flask(而非 Django)的替代实现