Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
#include <unistd.h>
int main(int argc, char **argv) {
@sepfy
sepfy / muxing.c
Last active February 17, 2021 02:13
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
@sepfy
sepfy / monitor.c
Created February 14, 2021 14:00
libwpa_client monitor example
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/time.h>
#include <wpa_ctrl.h>
#define CTRL_INTERFACE_DIR "/var/run/wpa_supplicant/wlan0"
int main(int argc, char *argv[]) {
@sepfy
sepfy / control.c
Last active February 14, 2021 13:59
libwpa_client control example
#include <stdio.h>
#include <stdlib.h>
#include <wpa_ctrl.h>
#define CTRL_INTERFACE_DIR "/var/run/wpa_supplicant/wlan0"
int main(int argc, char *argv[]) {
struct wpa_ctrl *ctrl_conn;
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h> // for open
#include <unistd.h> // for close
#define IOCTL_MISCDEV_SET 0x00
#define IOCTL_MISCDEV_GET 0x01
@sepfy
sepfy / ioctl.c
Last active October 4, 2020 05:02
struct miscdev_data {
int val;
char data[64];
};
#define IOCTL_MISCDEV_SET 0x00
#define IOCTL_MISCDEV_GET 0x01
static long mydev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
@sepfy
sepfy / fops.c
Last active October 4, 2020 05:03
static ssize_t
mydev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos)
{
char tmp[] = "Kernel says hello";
printk("[%s][%d]\n", __func__, __LINE__);
copy_to_user(buf, tmp, sizeof(tmp));
*pos = 0;
return 0;
}
static struct miscdevice my_miscdev = {
.minor = 11,
.name = "misc_dev",
.fops = &mydev_fops,
};
static int __init init_modules(void)
{
int ret;
ret = misc_register(&my_miscdev);
#define BUZZER 23
#define BUTTON 21
static short int button_irq = 0;
static unsigned long flags = 0;
int buzzer_trigger = 0;
u32 trigger_jiffies;
static irqreturn_t button_isr(int irq, void *data)
static ssize_t attr_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
printk("[%s][%d]\n", __func__, __LINE__);
buzzer_trigger = simple_strtoul(buf, NULL, 10);
gpio_set_value(BUZZER, buzzer_trigger);
return count;
}