From 301b757f134e213fc67dd40beea260ef33d9ff14 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Wed, 14 Dec 2011 21:16:41 +0000 Subject: [PATCH] cleanups revision 500!!!! --- rf433rcv/pc/Makefile | 10 +++++++- rf433rcv/pc/reset.c | 41 +++++++++++++++++++++++++++++++++ rf433rcv/teensy/Makefile | 5 ++-- rf433rcv/teensy/analog.c | 57 ---------------------------------------------- rf433rcv/teensy/analog.h | 15 ------------ 5 files changed, 52 insertions(+), 76 deletions(-) create mode 100644 rf433rcv/pc/reset.c delete mode 100644 rf433rcv/teensy/analog.c delete mode 100644 rf433rcv/teensy/analog.h diff --git a/rf433rcv/pc/Makefile b/rf433rcv/pc/Makefile index 6badbc0..8626087 100644 --- a/rf433rcv/pc/Makefile +++ b/rf433rcv/pc/Makefile @@ -36,7 +36,7 @@ endif OBJS = $(PROG).o hid.o -all: $(TARGET) compress uncompress +all: $(TARGET) compress uncompress reset compress: compress.c $(CC) -o compress compress.c @@ -48,6 +48,11 @@ $(PROG): $(OBJS) $(CC) -o $(PROG) $(OBJS) $(LIBS) $(STRIP) $(PROG) + +reset: hid.o reset.o + $(CC) -o reset reset.o hid.o $(LIBS) + $(STRIP) reset + $(PROG).exe: $(PROG) cp $(PROG) $(PROG).exe @@ -59,6 +64,9 @@ $(PROG).dmg: $(PROG) hid.o: hid_$(OS).c hid.h $(CC) $(CFLAGS) -c -o $@ $< +reset.o: reset.c + $(CC) $(CFLAGS) -c -o $@ $< + clean: rm -f *.o $(PROG) $(PROG).exe $(PROG).dmg rm -rf tmp diff --git a/rf433rcv/pc/reset.c b/rf433rcv/pc/reset.c new file mode 100644 index 0000000..956ad80 --- /dev/null +++ b/rf433rcv/pc/reset.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#if defined(OS_LINUX) || defined(OS_MACOSX) +#include +#include +#elif defined(OS_WINDOWS) +#include +#endif + +#include "hid.h" + + +void sendstr(char * tosend) +{ + rawhid_send(0, tosend, strlen(tosend),1000); +} + +int mtime_diff(struct timeval high,struct timeval low) +{ + int result=1000*(high.tv_sec-low.tv_sec); + result+=high.tv_usec/1000-low.tv_usec/1000; + return result; +} + +int main (int argc, char *argv[]) +{ + // C-based example is 16C0:0480:FFAB:0200 + int r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200); + if (r <= 0) { + // Arduino-based example is 16C0:0486:FFAB:0200 + r = rawhid_open(1, 0x16C0, 0x0486, 0xFFAB, 0x0200); + if (r <= 0) { + printf("no rawhid device found\n"); + return -1; + } + } + sendstr("r"); // clear the buffer + return 0; +} diff --git a/rf433rcv/teensy/Makefile b/rf433rcv/teensy/Makefile index 41b9a12..df03245 100644 --- a/rf433rcv/teensy/Makefile +++ b/rf433rcv/teensy/Makefile @@ -46,8 +46,7 @@ TARGET = example # List C source files here. (C dependencies are automatically generated.) SRC = $(TARGET).c \ - usb_rawhid.c \ - analog.c + usb_rawhid.c # MCU name, you MUST set this to match the board you are using @@ -444,7 +443,7 @@ gccversion : # Program the device. program: $(TARGET).hex $(TARGET).eep - echo -n r | ../pc/rawhid_test || true + ../pc/reset || true ~/teensy_loader_cli/teensy_loader_cli -mmcu=atmega32u4 -w $(TARGET).hex diff --git a/rf433rcv/teensy/analog.c b/rf433rcv/teensy/analog.c deleted file mode 100644 index 99bf3b6..0000000 --- a/rf433rcv/teensy/analog.c +++ /dev/null @@ -1,57 +0,0 @@ -// Simple analog to digitial conversion, similar to Wiring/Arduino - -#include -#include - -#include "analog.h" - - -#if defined(__AVR_ATmega32U4__) - -uint8_t analog_reference_config_val = 0x40; - -static const uint8_t PROGMEM adc_mapping[] = { - 0, 1, 4, 5, 6, 7, 13, 12, 11, 10, 9, 8 -}; - -int analogRead(uint8_t pin) -{ - uint8_t low, adc; - - if (pin >= 12) return 0; - adc = pgm_read_byte(adc_mapping + pin); - if (adc < 8) { - DIDR0 |= (1 << adc); - ADCSRB = 0; - ADMUX = analog_reference_config_val | adc; - } else { - adc -= 8; - DIDR2 |= (1 << adc); - ADCSRB = (1<= 8) return 0; - DIDR0 |= (1 << pin); - ADMUX = analog_reference_config_val | pin; - ADCSRA = (1< - -#if defined(__AVR_AT90USB162__) -#define analogRead(pin) (0) -#define analogReference(ref) -#else -int16_t analogRead(uint8_t pin); -extern uint8_t analog_reference_config_val; -#define analogReference(ref) (analog_reference_config_val = (ref) << 6) -#endif - -#endif -- 1.7.10.4