X-Git-Url: https://git.rvb.name/rtl-433.git/blobdiff_plain/ca13278b24eb61443559bcb61e64627fba3d8823..6d15c6f967221af825cf84e3ed12b96c763b127b:/src/devices/kerui.c diff --git a/src/devices/kerui.c b/src/devices/kerui.c new file mode 100644 index 0000000..99c569c --- /dev/null +++ b/src/devices/kerui.c @@ -0,0 +1,98 @@ +/* Kerui PIR sensor +* +* Code derrived from akhan_100F14.c +* +* Such as +* http://www.ebay.co.uk/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xkerui+pir.TRS0&_nkw=kerui+pir&_sacat=0 +*/ + +#include "rtl_433.h" +#include "pulse_demod.h" +#include "util.h" +#include "data.h" + +static int kerui_callback(bitbuffer_t *bitbuffer) { + + int isKerui = 0; + data_t *data; + char time_str[LOCAL_TIME_BUFLEN]; + uint32_t ID; + uint32_t dataBits; + + char *CMD; + + bitrow_t *bb = bitbuffer->bb; + + for (int i=0; inum_rows; i++) { + uint8_t *b = bb[i]; + + //invert bits, short pulse is 0, long pulse is 1 + b[0] = ~b[0]; + b[1] = ~b[1]; + b[2] = ~b[2]; + + unsigned bits = bitbuffer->bits_per_row[i]; + + if (bits == 25) { + local_time_str(0, time_str); + + ID = (b[0] << 12) | (b[1] << 4) | (b[2] >> 4); + dataBits = b[2] & 0x0F; + + switch (dataBits) { + case 0xa: + isKerui = 1; + CMD = "0xa (PIR)"; + break; + case 0xe: + isKerui = 1; + CMD = "0xe (DOOR)"; + break; + default: + isKerui = 0; + break; + } + + } + + if (isKerui == 1) break; + + } + + if (isKerui == 1) { + data = data_make( "time", "", DATA_STRING, time_str, + "device", "", DATA_STRING, "Kerui Sensor", + "id", "ID (20bit)", DATA_FORMAT, "0x%x", DATA_INT, ID, + "data", "Data (4bit)", DATA_STRING, CMD, + NULL); + data_acquired_handler(data); + return 1; + } else { + return 0; + } +} + +static char *output_fields[] = { + "time", + "device", + "id", + "data", + "other", + NULL +}; + +PWM_Precise_Parameters pwm_precise_parameters_kerui = { + .pulse_tolerance = 20, + .pulse_sync_width = 0, +}; + +r_device kerui = { + .name = "Kerui Sensor", + .modulation = OOK_PULSE_PWM_RAW, + .short_limit = 340, + .long_limit = 1200, + .reset_limit = 1800, + .json_callback = &kerui_callback, + .disabled = 0, + .demod_arg = (uintptr_t)&pwm_precise_parameters_kerui, +};