Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
npetrovski committed Sep 1, 2019
0 parents commit ee1d24f
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
*.o
dist

# Object files
*.o
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
/.idea
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
CC=arm-hisiv300-linux-gcc
USER_CFLAGS=-march=armv5te -mcpu=arm926ej-s -I/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include -L/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/lib
USER_LDFLAGS=
AR=arm-hisiv300-linux-ar
RANLIB=arm-hisiv300-linux-ranlib
STRIP=arm-hisiv300-linux-strip

TARGET = led

BUILD_DIR = dist
SRC_DIR = src
INCLUDE_DIR = include

CFLAGS = -Os
LIBS =

.PHONY: default all clean directories

default: directories $(TARGET)
all: default

OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(wildcard $(SRC_DIR)/*.c))
SOURCES = $(wildcard $(SRC_DIR)/*.c)
HEADERS = $(wildcard $(INCLUDE_DIR)/*.h)

$(OBJECTS): $(SOURCES) $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall $(LIBS) -o $(BUILD_DIR)/$@
$(STRIP) $(BUILD_DIR)/$(TARGET)

directories:
mkdir -p $(BUILD_DIR)

clean:
rm -f $(BUILD_DIR)/*.o
rm -f $(BUILD_DIR)/$(TARGET)
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Led Control for Xiaomi's YI Home cameras

Simple LED (light-emitting diode) control interface on `cpld_periph` kernel module for YI Home camera

Supported cams:
* 720p 47US

## Build

```sh
$ cd yi-home-led
$ make
```

### Usage
```sh
Usage: led <options>

Options:
-b[fast|slow|pulse|on|off] Blue led mode
-y[fast|slow|on|off] Yellow led mode
-l[on|off] Light on/off

Example: led -bon -lon
```
4 changes: 4 additions & 0 deletions include/led.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int32_t DEVICE_NUM = 0x70;

int32_t open_cpld();
void run2(int32_t fd, int offset);
95 changes: 95 additions & 0 deletions src/led.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#include "../include/led.h"

int32_t open_cpld() {
int32_t fd;
if (access("/dev/cpld_periph", F_OK) == 0) {
fd = open("/dev/cpld_periph", O_RDWR);
} else {
fd = -1;
}
return fd;
}

void usage() {
puts("Led Control v0.1\n\nUsage: led <options>\n\nOptions: \n\t-b[fast|slow|pulse|on|off] Blue led mode\n\t-y[fast|slow|on|off] Yellow led mode\n\t-l[on|off] Light on/off \n\nExample: led -bon -lon\n");
}

void run2(int32_t fd, int offset) {
ioctl(fd, (DEVICE_NUM << 8) + offset );
}

int main(int argc, char *argv[]) {
if (argc <= 1) {
usage();
return 1;
}

int32_t fd = open_cpld();
if (fd < 0) {
puts("Error: cannot open /dev/cpld_periph");
return 1;
}

int opt;
while((opt = getopt(argc, argv, ":b:y:l:")) != -1)
{
switch (opt) {
case 'b':
if (strcmp(optarg, "on") == 0) {
run2(fd, 0x0a);
run2(fd, 0x01);
}

if (strcmp(optarg, "off") == 0) {
run2(fd, 0x02);
}

if (strcmp(optarg, "fast") == 0) {
run2(fd, 0x03);
}

if (strcmp(optarg, "slow") == 0) {
run2(fd, 0x04);
}

if (strcmp(optarg, "pulse") == 0) {
run2(fd, 0x05);
}
break;
case 'y':
if (strcmp(optarg, "on") == 0) {
run2(fd, 0x09);
run2(fd, 0x02);
}
if (strcmp(optarg, "fast") == 0) {
run2(fd, 0x0b);
}

if (strcmp(optarg, "slow") == 0) {
run2(fd, 0x0c);
}

if (strcmp(optarg, "off") == 0) {
run2(fd, 0x0a);
}
break;
case 'l':
if (strcmp(optarg, "on") == 0) {
run2(fd, 0x1c);
}
if (strcmp(optarg, "off") == 0) {
run2(fd, 0x1b);
}
break;
case '?':
usage();
break;
}
}

return 0;
}

0 comments on commit ee1d24f

Please sign in to comment.