diff --git a/Makefile b/Makefile index 39f16db4..4cd17ccd 100755 --- a/Makefile +++ b/Makefile @@ -1,408 +1,43 @@ -# LINUX Makefile made by A'rpi / Astral -# Some cleanup by LGB: * 'make -C dir' instead of 'cd dir;make;cd..' -# * for loops instead of linear sequence of make directories -# * some minor problems with make clean and distclean were corrected -# * DVD support - -include config.mak - -COMMON_LDFLAGS += $(EXTRA_LIB)\ - $(EXTRALIBS) \ - -LDFLAGS_MPLAYER = $(EXTRALIBS_MPLAYER) \ - $(COMMON_LDFLAGS) \ - -LDFLAGS_MENCODER = $(EXTRALIBS_MENCODER) \ - $(COMMON_LDFLAGS) \ - -SRCS_COMMON = asxparser.c \ - codec-cfg.c \ - cpudetect.c \ - edl.c \ - find_sub.c \ - get_path.c \ - m_config.c \ - m_option.c \ - m_struct.c \ - mpcommon.c \ - parser-cfg.c \ - playtree.c \ - playtreeparser.c \ - spudec.c \ - sub_cc.c \ - subreader.c \ - vobsub.c \ - -SRCS_COMMON-$(UNRARLIB) += unrarlib.c - -SRCS_MPLAYER = mplayer.c \ - m_property.c \ - mp_fifo.c \ - mp_msg.c \ - mixer.c \ - parser-mpcmd.c \ - subopt-helper.c \ - command.c \ - -SRCS_MENCODER = mencoder.c \ - mp_msg-mencoder.c \ - parser-mecmd.c \ - xvid_vbr.c \ - -COMMON_LIBS = libmpcodecs/libmpcodecs.a \ - libaf/libaf.a \ - libmpdemux/libmpdemux.a \ - stream/stream.a \ - libswscale/libswscale.a \ - libvo/libosd.a \ - -COMMON_LIBS-$(LIBAVFORMAT_A) += libavformat/libavformat.a -COMMON_LIBS-$(LIBAVCODEC_A) += libavcodec/libavcodec.a -COMMON_LIBS-$(LIBWMA) += libwma/libwma.a -COMMON_LIBS-$(LIBAVUTIL_A) += libavutil/libavutil.a -COMMON_LIBS-$(LIBPOSTPROC_A) += libpostproc/libpostproc.a -COMMON_LIBS-$(WIN32DLL) += loader/libloader.a -COMMON_LIBS-$(MP3LIB) += mp3lib/libmp3.a -COMMON_LIBS-$(LIBA52) += liba52/liba52.a -COMMON_LIBS-$(LIBMPEG2) += libmpeg2/libmpeg2.a -COMMON_LIBS-$(FAAD_INTERNAL) += libfaad2/libfaad2.a -COMMON_LIBS-$(TREMOR_INTERNAL) += tremor/libvorbisidec.a -COMMON_LIBS-$(DVDREAD_INTERNAL) += dvdread/libdvdread.a -COMMON_LIBS-$(DVDCSS_INTERNAL) += libdvdcss/libdvdcss.a -COMMON_LIBS-$(ASS) += libass/libass.a - -LIBS_MPLAYER = libvo/libvo.a \ - libao2/libao2.a \ - input/libinput.a \ - -LIBS_MPLAYER-$(VIDIX) += vidix/libvidix.a -LIBS_MPLAYER-$(GUI) += gui/libgui.a -LIBS_MPLAYER-$(LIBMENU) += libmenu/libmenu.a - -LIBS_MENCODER = libmpcodecs/libmpencoders.a \ - libmpdemux/libmpmux.a \ - -# Having this in libosdep.a is not enough. -OBJS_MPLAYER-$(TARGET_WIN32) += osdep/mplayer-rc.o - -ALL_PRG-$(MPLAYER) += mplayer$(EXESUF) -ALL_PRG-$(MENCODER) += mencoder$(EXESUF) - -COMMON_LIBS += $(COMMON_LIBS-yes) -LIBS_MPLAYER += $(LIBS_MPLAYER-yes) -OBJS_MPLAYER += $(OBJS_MPLAYER-yes) -PARTS += $(PARTS-yes) -ALL_PRG += $(ALL_PRG-yes) - -COMMON_LIBS += osdep/libosdep.a - -MPLAYER_DEPS = $(OBJS_MPLAYER) $(OBJS_COMMON) $(LIBS_MPLAYER) $(COMMON_LIBS) -MENCODER_DEPS = $(OBJS_MENCODER) $(OBJS_COMMON) $(LIBS_MENCODER) $(COMMON_LIBS) - -INSTALL_TARGETS-$(MPLAYER) += install-mplayer install-mplayer-man -INSTALL_TARGETS-$(MENCODER) += install-mencoder install-mplayer-man -INSTALL_TARGETS-$(GUI) += install-gui -INSTALL_TARGETS += $(INSTALL_TARGETS-yes) - -PARTS = dvdread \ - gui \ - input \ - liba52 \ - libaf \ - libao2 \ - libass \ - libavcodec \ - libavformat \ - libavutil \ - libdvdcss \ - libfaad2 \ - libmenu \ - libmpcodecs \ - libmpdemux \ - libmpeg2 \ - libpostproc \ - libswscale \ - libvo \ - libwma \ - loader \ - mp3lib \ - osdep \ - stream \ - tremor \ - vidix \ - - -all: $(ALL_PRG) - -dep depend:: help_mp.h version.h codecs.conf.h - @for a in $(PARTS); do $(MAKE) -C $$a dep; done - -include mpcommon.mak - -CFLAGS := $(subst -I..,-I.,$(CFLAGS)) - -libaf/libaf.a: - $(MAKE) -C libaf - -dvdread/libdvdread.a: - $(MAKE) -C dvdread - -libdvdcss/libdvdcss.a: - $(MAKE) -C libdvdcss - -loader/libloader.a: - $(MAKE) -C loader - -libass/libass.a: - $(MAKE) -C libass - -libmpdemux/libmpdemux.a: - $(MAKE) -C libmpdemux libmpdemux.a - -libmpdemux/libmpmux.a: - $(MAKE) -C libmpdemux libmpmux.a - -stream/stream.a: - $(MAKE) -C stream - -libmpcodecs/libmpcodecs.a: - $(MAKE) -C libmpcodecs - -libavutil/libavutil.a: - $(MAKE) -C libavutil - -libavcodec/libavcodec.a: - $(MAKE) -C libavcodec - -libwma/libwma.a: - $(MAKE) -C libwma - -libpostproc/libpostproc.a: - $(MAKE) -C libpostproc - -libavformat/libavformat.a: - $(MAKE) -C libavformat - -libswscale/libswscale.a: - $(MAKE) -C libswscale - -libmpeg2/libmpeg2.a: - $(MAKE) -C libmpeg2 - -libvo/libvo.a: - $(MAKE) -C libvo libvo.a - -libvo/libosd.a: - $(MAKE) -C libvo libosd.a - -libao2/libao2.a: - $(MAKE) -C libao2 - -liba52/liba52.a: - $(MAKE) -C liba52 - -libfaad2/libfaad2.a: - $(MAKE) -C libfaad2 - -mp3lib/libmp3.a: - $(MAKE) -C mp3lib - -tremor/libvorbisidec.a: - $(MAKE) -C tremor - -vidix/libvidix.a: - $(MAKE) -C vidix - -gui/libgui.a: - $(MAKE) -C gui - -osdep/libosdep.a: - $(MAKE) -C osdep - -osdep/mplayer-rc.o: version.h - $(MAKE) -C osdep mplayer-rc.o - -input/libinput.a: - $(MAKE) -C input - -libmenu/libmenu.a: - $(MAKE) -C libmenu - -mplayer$(EXESUF): $(MPLAYER_DEPS) - $(CC) -o $@ $^ $(LDFLAGS_MPLAYER) - -mencoder$(EXESUF): $(MENCODER_DEPS) - $(CC) -o $@ $^ $(LDFLAGS_MENCODER) - -codec-cfg$(EXESUF): codec-cfg.c codec-cfg.h help_mp.h - $(HOST_CC) -I. -DCODECS2HTML $< -o $@ - -codecs.conf.h: codec-cfg$(EXESUF) etc/codecs.conf - ./codec-cfg$(EXESUF) ./etc/codecs.conf > $@ - -codec-cfg.o: codecs.conf.h - -codecs2html$(EXESUF): mp_msg.o - $(CC) -DCODECS2HTML codec-cfg.c $^ -o $@ - -codec-cfg-test$(EXESUF): codecs.conf.h codec-cfg.h mp_msg.o osdep/getch2.o - $(CC) -I. -DTESTING codec-cfg.c mp_msg.o osdep/getch2.o -ltermcap -o $@ - -install: install-dirs $(INSTALL_TARGETS) - -install-dirs: - $(INSTALL) -d $(BINDIR) - $(INSTALL) -d $(DATADIR) - $(INSTALL) -d $(MANDIR)/man1 - $(INSTALL) -d $(CONFDIR) - if test -f $(CONFDIR)/codecs.conf ; then mv -f $(CONFDIR)/codecs.conf $(CONFDIR)/codecs.conf.old ; fi - -install-mplayer: mplayer$(EXESUF) - $(INSTALL) -m 755 $(INSTALLSTRIP) mplayer$(EXESUF) $(BINDIR) - -install-mplayer-man: - for i in $(MAN_LANG); do \ - if test "$$i" = en ; then \ - $(INSTALL) -c -m 644 DOCS/man/en/mplayer.1 $(MANDIR)/man1/ ; \ - else \ - $(INSTALL) -d $(MANDIR)/$$i/man1 ; \ - $(INSTALL) -c -m 644 DOCS/man/$$i/mplayer.1 $(MANDIR)/$$i/man1/ ; \ - fi ; \ - done - -install-mencoder: mencoder$(EXESUF) - $(INSTALL) -m 755 $(INSTALLSTRIP) mencoder$(EXESUF) $(BINDIR) - for i in $(MAN_LANG); do \ - if test "$$i" = en ; then \ - cd $(MANDIR)/man1 && ln -sf mplayer.1 mencoder.1 ; \ - else \ - cd $(MANDIR)/$$i/man1 && ln -sf mplayer.1 mencoder.1 ; \ - fi ; \ - done - -install-gui: - -ln -sf mplayer$(EXESUF) $(BINDIR)/gmplayer$(EXESUF) - $(INSTALL) -d $(DATADIR)/skins - @echo "*** Download skin(s) at http://www.mplayerhq.hu/design7/dload.html" - @echo "*** for GUI, and extract to $(DATADIR)/skins/" - $(INSTALL) -d $(prefix)/share/pixmaps - $(INSTALL) -m 644 etc/mplayer.xpm $(prefix)/share/pixmaps/ - $(INSTALL) -d $(prefix)/share/applications - $(INSTALL) -m 644 etc/mplayer.desktop $(prefix)/share/applications/ - -uninstall: - -rm -f $(BINDIR)/mplayer$(EXESUF) $(BINDIR)/gmplayer$(EXESUF) - -rm -f $(BINDIR)/mencoder$(EXESUF) - -rm -f $(MANDIR)/man1/mencoder.1 $(MANDIR)/man1/mplayer.1 - -rm -f $(prefix)/share/pixmaps/mplayer.xpm - -rm -f $(prefix)/share/applications/mplayer.desktop - for l in $(MAN_LANG); do \ - if test "$$l" != "en"; then \ - rm -f $(MANDIR)/$$l/man1/mplayer.1 \ - $(MANDIR)/$$l/man1/mencoder.1 \ - $(MANDIR)/$$l/man1/gmplayer.1 ; \ - fi ; \ - done - -clean:: - -rm -f mplayer$(EXESUF) mencoder$(EXESUF) codec-cfg$(EXESUF) \ - codecs2html$(EXESUF) codec-cfg-test$(EXESUF) cpuinfo$(EXESUF) \ - codecs.conf.h help_mp.h version.h - @for a in $(PARTS); do $(MAKE) -C $$a clean; done - -distclean:: doxygen_clean - @for a in $(PARTS); do $(MAKE) -C $$a distclean; done - $(MAKE) -C TOOLS distclean - -rm -f configure.log config.mak config.h - -strip: - strip -s $(ALL_PRG) - -# ./configure must be rerun if it changed -#config.mak: configure - @echo "############################################################" - @echo "####### Please run ./configure again - it's changed! #######" - @echo "############################################################" - -# rebuild at every config.h/config.mak/Makefile change: -version.h: config.h config.mak Makefile - ./version.sh `$(CC) -dumpversion` - -doxygen: - doxygen DOCS/tech/Doxyfile - -doxygen_clean: - -rm -rf DOCS/tech/doxygen - -help_mp.h: help/help_mp-en.h $(HELP_FILE) - @echo '// WARNING! This is a generated file. Do NOT edit.' > help_mp.h - @echo '// See the help/ subdir for the editable files.' >> help_mp.h -ifeq ($(CHARSET),) - @echo '#include "$(HELP_FILE)"' >> help_mp.h -else - iconv -f UTF-8 -t $(CHARSET) "$(HELP_FILE)" >> help_mp.h -endif - -ifneq ($(HELP_FILE),help/help_mp-en.h) - @echo "Adding untranslated messages to help_mp.h" - @echo '// untranslated messages from the English master file:' >> help_mp.h - @help/help_diff.sh $(HELP_FILE) < help/help_mp-en.h >> help_mp.h -endif - -# explicit dependencies to force version.h to be built even if .depend is missing -mplayer.o mencoder.o vobsub.o: version.h - -# temporary measure to make sure help_mp.h is built. we desperately need correct deps! -$(MPLAYER_DEPS) $(MENCODER_DEPS): help_mp.h - -# -# the following lines provide _partial_ dependency information -# for the 'library' directories under main dir, in order to cause -# the build process to recursively descend into them if something -# has changed. ideally this will be replaced with a single -# nonrecursive makefile for the whole project. -# -# Now all directories are recursed by default because these rules do not -# consider dependencies on files in other directories, while the recursively -# invoked Makefiles do. Conditional recursion only to the directories with -# changed files can be enabled by creating a file named ".norecurse" and -# optionally giving it a timestamp in the past. Directories whose .a files -# are newer than the timestamp and newer than other files in the directory -# will not be recursed. -.norecurse: - -libvo/libvo.a: .norecurse $(wildcard libvo/*.[ch]) -libvo/libosd.a: .norecurse $(wildcard libvo/*.[ch]) -libao2/libao2.a: .norecurse $(wildcard libao2/*.[ch]) -osdep/libosdep.a: .norecurse $(wildcard osdep/*.[ch]) -input/libinput.a: .norecurse $(wildcard input/*.[ch]) - -libmenu/libmenu.a: .norecurse $(wildcard libmenu/*.[ch]) -libaf/libaf.a: .norecurse $(wildcard libaf/*.[ch]) -dvdread/libdvdread.a: .norecurse $(wildcard dvdread/*.[ch]) -libdvdcss/libdvdcss.a: .norecurse $(wildcard libdvdcss/*.[ch]) - -libmpdemux/libmpdemux.a: .norecurse $(wildcard libmpdemux/*.[ch]) -libmpdemux/libmpmux.a: .norecurse $(wildcard libmpdemux/*.[ch]) -stream/stream.a: .norecurse $(wildcard stream/*.[ch] stream/*/*.[ch]) -libmpcodecs/libmpcodecs.a: .norecurse $(wildcard libmpcodecs/*.[ch]) $(wildcard libmpcodecs/native/*.[ch]) -libmpcodecs/libmpencoders.a: .norecurse $(wildcard libmpcodecs/*.[ch]) - -libavutil/libavutil.a: .norecurse $(wildcard libavutil/*.[ch]) -libavcodec/libavcodec.a: .norecurse $(wildcard libavcodec/*.[ch] libavcodec/*/*.[chS]) -libwma/libwma.a: .norecurse $(wildcard libwma/*.[ch]) -libavformat/libavformat.a: .norecurse $(wildcard libavformat/*.[ch]) -libswscale/libswscale.a: .norecurse $(wildcard libswscale/*.[ch]) - -libmpeg2/libmpeg2.a: .norecurse $(wildcard libmpeg2/*.[ch]) -liba52/liba52.a: .norecurse $(wildcard liba52/*.[ch]) -mp3lib/libmp3.a: .norecurse $(wildcard mp3lib/*.[ch]) -libfaad2/libfaad2.a: .norecurse $(wildcard libfaad2/*.[ch] libfaad2/*/*.[ch]) - -loader/libloader.a: .norecurse $(wildcard loader/*.[chSs]) -vidix/libvidix.a: .norecurse $(wildcard vidix/*.[ch]) -gui/libgui.a: .norecurse $(wildcard gui/*.[ch] gui/*/*.[ch] gui/*/*/*.[ch]) - -libass/libass.a: .norecurse $(wildcard libass/*.[ch]) - -.PHONY: all install* uninstall strip doxygen doxygen_clean +###################################### +# +###################################### +#source file +#auto find all *.c and *.cpp files, and compile to *.o file +SOURCE := $(wildcard *.c) $(wildcard *.cpp) +OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE))) $(CXXFLAGS) + +#target change name to what you want +TARGET := main + +#compile and lib parameter +#编译参数 +CC := mipsel-openwrt-linux-gcc +LIBS := /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine +LDFLAGS := -L +DEFINES := -I +INCLUDE := /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include +CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE) +CXXFLAGS := $(CFLAGS) -DHAVE_CONFIG_H + + +#i think you should do anything here +#下面的基本上不需要做任何改动了 +.PHONY : everything objs clean veryclean rebuild + +everything : $(TARGET) + +all : $(TARGET) + +objs : $(OBJS) + +rebuild: veryclean everything + +clean : + rm -fr *.o + +veryclean : clean + rm -fr $(TARGET) + +$(TARGET) : $(OBJS) + $(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) + diff --git a/Makefile2 b/Makefile2 new file mode 100644 index 00000000..df645d14 --- /dev/null +++ b/Makefile2 @@ -0,0 +1,25 @@ +BIN_FILE = main +OBJECTS = main.o record.o key.o oled_iic.o mem_gpio.o +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine + +main.o : main.c + $(CC) -c main.c + +mem_gpio.o : mem_gpio.c + $(CC) -c mem_gpio.c + +key.o : key.c + $(CC) -c key.c + +oled_iic.o : oled_iic.c + $(CC) -c oled_iic.c + +record.o : record.c + $(CC) -c record.o record.c -I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -lasound -lm -lmp3lame -lshine + +clean : + rm main *.o diff --git a/a.out b/a.out index eb0c50ba..8461237d 100755 Binary files a/a.out and b/a.out differ diff --git a/alsa/Makefile b/alsa/Makefile new file mode 100755 index 00000000..1d1f72b5 --- /dev/null +++ b/alsa/Makefile @@ -0,0 +1,17 @@ +SOURCE = record_control.c +OBJECTS = record_control.o +OUTFILE = record_control +CC = mipsel-openwrt-linux-gcc +#LIBS = lasound +INC = /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/*.h +LIBS = /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib + +$(OUTFILE) : $(OBJECTS) + $(CC) -L/$(LIBS) -o $(OUTFILE) $(OBJECTS) + +$(OBJECTS) : $(SOURCE) $(INC) + $(CC) -c $(OBJECTS) $(SOURCE) + +.PHONY : clean +clean: + rm $(OBJECTS) $(OUTFILE) \ No newline at end of file diff --git a/alsa/Makefile2 b/alsa/Makefile2 new file mode 100644 index 00000000..d79c13c0 --- /dev/null +++ b/alsa/Makefile2 @@ -0,0 +1,25 @@ +BIN_FILE = main +OBJECTS = main.o mem_gpio.o key.o oled_iic.o record.o +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine + +main.o : main.c + $(CC) -c main.c + +mem_gpio.o : mem_gpio.c + $(CC) -c mem_gpio.c + +key.o : key.c + $(CC) -c key.c + +oled_iic.o : oled_iic.c + $(CC) -c oled_iic.c + +record.o : record.c + $(CC) -c record.o record.c -I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -lasound -lm -lmp3lame -lshine + +clean : + rm main *.o diff --git a/alsa/asoundlib.h b/alsa/asoundlib.h new file mode 100755 index 00000000..3c2766e3 --- /dev/null +++ b/alsa/asoundlib.h @@ -0,0 +1,65 @@ +/** + * \file include/asoundlib.h + * \brief Application interface library for the ALSA driver + * \author Jaroslav Kysela + * \author Abramo Bagnara + * \author Takashi Iwai + * \date 1998-2001 + * + * Application interface library for the ALSA driver + */ +/* + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef __ASOUNDLIB_H +#define __ASOUNDLIB_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef __GNUC__ +#define __inline__ inline +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* __ASOUNDLIB_H */ diff --git a/alsa/autorecord4 b/alsa/autorecord4 index 1d97e3c3..5755ce67 100755 Binary files a/alsa/autorecord4 and b/alsa/autorecord4 differ diff --git a/alsa/build.sh b/alsa/build.sh new file mode 100755 index 00000000..bbb92b06 --- /dev/null +++ b/alsa/build.sh @@ -0,0 +1,8 @@ +#!/bin/sh +BIN_FILE=record_control +STR_FILE=$BIN_FILE'.c' +mipsel-openwrt-linux-gcc -o $BIN_FILE $STR_FILE \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ +-L. \ +-lasound -lm -lmp3lame -lshine diff --git a/alsa/build.sh1 b/alsa/build.sh1 new file mode 100755 index 00000000..15e8ebb3 --- /dev/null +++ b/alsa/build.sh1 @@ -0,0 +1,8 @@ +#!/bin/sh +BIN_FILE=autorecord4 +STR_FILE=$BIN_FILE'.c' +/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc -o $BIN_FILE $STR_FILE \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ +-L. \ +-lasound -lm -lmp3lame -lshine diff --git a/alsa/filter.h b/alsa/filter.h old mode 100644 new mode 100755 diff --git a/alsa/filter_test.c b/alsa/filter_test.c old mode 100644 new mode 100755 diff --git a/alsa/layer3.h b/alsa/layer3.h old mode 100644 new mode 100755 diff --git a/alsa/libasound.so b/alsa/libasound.so new file mode 120000 index 00000000..42dfc99d --- /dev/null +++ b/alsa/libasound.so @@ -0,0 +1 @@ +libasound.so.2.0.0 \ No newline at end of file diff --git a/alsa/libasound.so.2 b/alsa/libasound.so.2 new file mode 120000 index 00000000..42dfc99d --- /dev/null +++ b/alsa/libasound.so.2 @@ -0,0 +1 @@ +libasound.so.2.0.0 \ No newline at end of file diff --git a/alsa/libasound.so.2.0.0 b/alsa/libasound.so.2.0.0 new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/alsa/libasound.so.2.0.0 differ diff --git a/alsa/makerecord3.sh b/alsa/makerecord3.sh index 55f7b737..70064b2f 100755 --- a/alsa/makerecord3.sh +++ b/alsa/makerecord3.sh @@ -2,7 +2,7 @@ BIN_FILE=autorecord3 STR_FILE=$BIN_FILE'.c' ../openwrt-gcc -o $BIN_FILE $STR_FILE \ --I /home/midas/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ --L /home/midas/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ -L. \ -lasound -lm -lmp3lame diff --git a/alsa/makerecord4.sh b/alsa/makerecord4.sh index 3787e25b..53d98c5a 100755 --- a/alsa/makerecord4.sh +++ b/alsa/makerecord4.sh @@ -1,7 +1,7 @@ #!/bin/sh BIN_FILE=autorecord4 STR_FILE=$BIN_FILE'.c' -../openwrt-gcc -o $BIN_FILE $STR_FILE \ +/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc -o $BIN_FILE $STR_FILE \ -I /home/midas/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ -L /home/midas/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ -L. \ diff --git a/alsa/pcm2wav.h.gch b/alsa/pcm2wav.h.gch old mode 100644 new mode 100755 diff --git a/alsa/record_control b/alsa/record_control new file mode 100755 index 00000000..19fd810f Binary files /dev/null and b/alsa/record_control differ diff --git a/alsa/record_control.c b/alsa/record_control.c new file mode 100755 index 00000000..1d99d5e0 --- /dev/null +++ b/alsa/record_control.c @@ -0,0 +1,474 @@ +/* --------------------------------------------------------------------------- +* ALSA record and play +!!! Sample rate=8k is OK, while sample rate=48k will make it too sensitive !!! +* +*Usage: ./record_control +1. It will monitor surrounding sound wave and trigger 60s recording if loud voice is sensed, + then it will playback. The sound will also be saved to a raw file. +2. Ensure there are no other active/pausing applications which may use ALSA simutaneously when you run the program, + sometimes it will make noise to the CAPUTRUE. + If PLAYBACK starts while Mplayer is playing, then sounds from Mplayer will totally disappear. + However if Mplayer starts later than PLAYBACK, two streams of sounds will be mixed. +3. use alsamixer to adjust Capture and ADC PCM value + ADC PCM 0-255 + Capture 0-63 +4. some explanation: + sample: usually 8bits or 16bits, one sample data width. + channel: 1-Mono. 2-Stereo + frame: sizeof(one sample)*channels + rate: frames per second + period: Max. frame numbers hard ware can be handled each time. (different value for PLAYBACK and CAPTURE!!) + chunk: frames receive from/send to hard ware each time. + buffer: N*periods + interleaved mode:record period data frame by frame, such as frame1(Left sample,Right sample),frame2(), ...... + uninterleaved mode: record period data channel by channel, such as period(Left sample,Left ,left...),period(right,right...),period()... +3. lib: lasound +* +*Make for Widora-neo +* +* IMIO Inc +* Author: zyc +* Date : 2017-04-12 +------------------------------------------------------------------------------*/ +#include +#include +#include "asoundlib.h" +#include + + +#define CHECK_FREQ 125 //-- use average energy in 1/CHECK_FREQ (s) to indicate noise level +#define SAMPLE_RATE 8000 //--4k also OK +#define CHECK_AVERG 2000 //--threshold value of wave amplitude to trigger record +#define KEEP_AVERG 1800 //--threshold value of wave amplitude for keeping recording +#define DELAY_TIME 5 //seconds -- recording time after one trigger +#define MAX_RECORD_TIME 20 //seconds --max. record time in seconds +#define MIN_SAVE_TIME 10 //seconds --min. recording time for saving, short time recording will be discarded. + + +//------------ gobal variable -------------------------------- +snd_pcm_t *pcm_handle; +snd_pcm_hw_params_t *params; +snd_pcm_format_t format_val; +char *wave_buf; //---pointer to wave buffer +int wave_buf_len; //---wave buffer length in bytes +int wave_buf_used = 0; //---used wave buf length in bytes +int bit_per_sample;//simple bit +snd_pcm_uframes_t frames; +snd_pcm_uframes_t period_size; //length of period (max. numbers of frames that hw can handle each time) +snd_pcm_uframes_t chunk_size = 32;//numbers of frames read/write to hard ware each time +int chunk_byte; //length of chunk (period) (in bytes) +unsigned int chanl_val,rate_val; +int dir; + +//------------ time struct --------------------------------------- +struct timeval t_start,t_end; +long cost_timeus=0; +long cost_times=0; +char str_time[20]={0}; +time_t timep; +struct tm *p_tm; + +//------------------- functions declaration ---------------------- +bool device_open(int mode); +bool device_setparams(); +bool device_capture(); +bool device_play(); +bool device_check_voice(); + + +/*========================= MAIN ====================================*/ +int main(int argc, char* argv[]) +{ + int fd; + int rc; + int ret = 0; + char str_file[50] = {0};//---directory of save_file + + //-------- set recording volume ------- + system("amixer set Capture 55"); + system("amixer set 'ADC PCM' 241"); // adjust sensitivity, or your can use alsamxier to adjust in realtime. + + while(1) + { + //--------sound recording beware of if...if...if...if...expressions + if (!device_open(SND_PCM_STREAM_CAPTURE )) + { + ret = 1; + goto OPEN_STREAM_CAPTURE_ERR; + } + //printf("---device_open()\n"); + if (!device_setparams(1,SAMPLE_RATE)){ + ret=2; + goto SET_CAPTURE_PARAMS_ERR; + } + //printf("---device_setparams()\n"); + + //---------- allocate mem. for buffering raw data + //---------- The values of rate_val,chanl_val and bit_per_sample are set in device_setparams() function + printf("rate_val = %d, chanl_val = %d, bit_per_sample = %d\n",rate_val,chanl_val,bit_per_sample); + wave_buf_len = MAX_RECORD_TIME*rate_val*bit_per_sample*chanl_val/8; + + //-----checking voice wave amplitude, and start to record if it exceeds preset threshold value,or it will loop checking ... + if(!device_check_voice()) + { //--device_check_voice() has a loop inside, it will jump out and return -1 only if there is an error. + goto LOOPEND; + } + + wave_buf = (char *)malloc(wave_buf_len ); //----allocate mem... + + //----------------recording + printf("start recording...\n"); + if (!device_capture()) + { + ret = 3; + goto DEVICE_CAPTURE_ERR; + } + //printf("-----device_capture()\n"); + snd_pcm_close( pcm_handle ); + printf("record finish!\n"); + + //------------save to file + timep = time(NULL);// get CUT time,seconds from Epoch, long type indeed + p_tm = localtime(&timep);// convert to local time in struct tm + strftime(str_time,sizeof(str_time),"%Y-%m-%d-%H:%M:%S",p_tm); + printf("record at: %s\n",str_time); + + if(wave_buf_used >= (MIN_SAVE_TIME*rate_val*bit_per_sample*chanl_val/8)) // save to file only if recording time is great than 20s. + { + sprintf(str_file,"/tmp/%s.raw",str_time); + fd = open(str_file,O_WRONLY|O_CREAT|O_TRUNC); + rc = write(fd,wave_buf,wave_buf_used); + printf("write to record.raw %d bytes\n",rc); + close(fd); //though kernel will close it automatically + } + + //-------- + if (!device_open(SND_PCM_STREAM_PLAYBACK)) + { + ret = 4; + goto OPEN_STREAM_PLAYBACK_ERR; + } + //printf("-----PLAY: device_open() finish\n"); + if (!device_setparams(1,SAMPLE_RATE)) + { + ret = 5; + goto SET_PLAYBACK_PARAMS_ERR; + } + //printf("-----PLAY: device_setarams() finish\n"); + printf("start playback...\n"); + if (!device_play()) + { + ret = 6; + goto DEVICE_PLAYBACK_ERR; //... contiue to loop + } + //if (!device_play()) goto LOOPEND; + + printf("finish playback.\n\n\n"); + //snd_pcm_drain( pcm_handle );//PALYBACK pcm_handle!! to allow any pending sound samples to be transferred. + + return 0; + +LOOPEND: + snd_pcm_close(pcm_handle);//CAPTURE or PLAYBACK pcm_handle!! + //printf("-----PLAY: snd_pcm_close() ----\n"); + wave_buf_used = 0; + free(wave_buf); //--wave_buf mem. to be allocated in device_capture() and played in device_play(); + continue; + +OPEN_STREAM_CAPTURE_ERR: + printf("Open PCM stream CAPTURE error!\n"); + return ret; + +SET_CAPTURE_PARAMS_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +DEVICE_CAPTURE_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +OPEN_STREAM_PLAYBACK_ERR: + printf("Open PCM stream PLAYBACK error!\n"); + return ret; + +SET_PLAYBACK_PARAMS_ERR: + printf("Set PLAYBACK parameters error!\n"); + return ret; + +DEVICE_PLAYBACK_ERR: + printf("device_play() error! start a new loop...\n"); + goto LOOPEND; + + }//while() + + return ret; +} + + +/*========================= FUNC ====================================*/ +//snd_pcm_t *pcm_handle; + +//use a func to open sound device +bool device_open(int mode) +{ + if (snd_pcm_open(&pcm_handle, "default", mode, 0) < 0) + { + printf("snd_pcm_open() fail!\n"); + return false; + } + printf("snd_pcm_open() succeed!\n"); + return true; +} + +/*-------------------- set and prepare parameters ------------------*/ +bool device_setparams(int nchanl,int rate) +{ + unsigned int val; + int dir; + int rc; + snd_pcm_hw_params_t *hw_params; + + //------ beware of following if..if...if..if...if...expressions ---------- + if(snd_pcm_hw_params_malloc (&hw_params ) < 0) + return false; //Ϊռ + // printf("---- snd_pcm_hw_params_malloc(&hw_params) ----\n"); + if(snd_pcm_hw_params_malloc (¶ms) < 0) + return false; + // printf("----snd_pcm_hw_params_malloc(¶ms) ----\n"); + if(snd_pcm_hw_params_any (pcm_handle, hw_params) < 0) + return false; //ʼ + // printf("----snd_pcm_hw_params_any(pcm_handle,hw_params)----\n"); + if(snd_pcm_hw_params_set_access (pcm_handle, hw_params,SND_PCM_ACCESS_RW_INTERLEAVED) < 0) + return false; //Ϊģʽ + // printf("----snd_pcm_hw_params_set_access()----\n"); + if(snd_pcm_hw_params_set_format( pcm_handle, hw_params, SND_PCM_FORMAT_S16_LE) < 0) + return false; //ʹ16λ + // printf("----snd_pmc_hw_params_set_format()-----\n"); + + val = rate;//8000; + if(snd_pcm_hw_params_set_rate_near(pcm_handle, hw_params,&val,0) < 0) + return false; //ò + // printf("----snd_pcm_hw_params_set_rate_near() val=%d----\n",val); + if(snd_pcm_hw_params_set_channels( pcm_handle, hw_params, nchanl) < 0) + return false; //Ϊor Mono. + // printf("----snd_pcm_hw_params_set_channels()-----\n"); + + frames = 32; + if(snd_pcm_hw_params_set_period_size_near(pcm_handle,hw_params,&chunk_size,&dir ) < 0 ) + return false; + // printf("----snd_pcm_hw_params_set_period_size_near() chunk_size=%d----\n",chunk_size); + if(snd_pcm_hw_params_get_period_size( hw_params, &period_size,0) < 0) + return false; //ȡڳ1536 + printf("----snd_pcm_hw_get_period_size(): %d frames----\n",(int) period_size ); + if(snd_pcm_hw_params_get_format(hw_params,&format_val ) < 0) + return false; + // printf("----snd_pcm_hw_params_get_format()----\n"); + + bit_per_sample = snd_pcm_format_width((snd_pcm_format_t) format_val ); + //printf("---bit_per_sample=%d snd_pcm_format_width()----\n",bit_per_sample); + //ȡ + snd_pcm_hw_params_get_channels(hw_params,&chanl_val ); + //printf("----snd_pcm_hw_params_get_channels %d---\n",chanl_val); + chunk_byte = period_size*bit_per_sample*chanl_val/8; //3072 this is the Max chunk byte size + //chunk_size = frames;//period_size; //frames + //ڳȣֽ(bytes) = ÿڵ * (bit) * ͨ / 8 + snd_pcm_hw_params_get_rate(hw_params,&rate_val,&dir); + snd_pcm_hw_params_get_channels(hw_params,&chanl_val); + + rc = snd_pcm_hw_params( pcm_handle, hw_params); //ò + if (rc < 0) + { + printf("unable to set hw parameters:%s\n",snd_strerror(rc)); + exit(1); + } + printf("finish setting sound hw parameters\n"); + params = hw_params; //Ժʹ + snd_pcm_hw_params_free( hw_params); //ͷŲռ + //printf("----snd_pcm_hw_params_free()----\n"); + + return true; +} +//ʹAlsaṩһϵ snd_pcm_hw_params_set_ Ϊֵ +//ͨ snd_pcm_hw_params ݸ豸 +//Ҫ˵ʽĿҪʧܵΪʾδǡ +//úòԿʼ¼ˡ¼ʵϾǴƵ豸жȡϢ档 + + +//------------------- record sound ------------------------------------// + bool device_capture() + { + int i; + int r = 0; + int total = 0; + int averg = 0; + char *data = wave_buf; // pointer to wave_buf position + int16_t *pv; //pointer to current data + //int CN = 7; //chunk_size = 2^CN + + //chunk_size = (2 << CN); //=frames + chunk_size = SAMPLE_RATE/CHECK_FREQ; //--how many frames to be checked for specified CHECK_FREQ,one channel + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + //printf("chunk_byte=%d\n",chunk_byte); + + //------------------ get start time ------------------ + gettimeofday(&t_start, NULL); + printf("Start Time: %lds + %ldus \n",t_start.tv_sec,t_start.tv_usec); + + while ((data-wave_buf) <= (wave_buf_len-chunk_byte)) + { //chunk_size*bit_per_sample*chanl_val)){ + r = snd_pcm_readi( pcm_handle,data,chunk_size); //chunk_size*bit_per_sample*read interleaved frames from a PCM + if(r == -EPIPE) + { + /* EPIPE means overrun */ + fprintf(stderr,"overrun occurred!\n"); + snd_pcm_prepare(pcm_handle);//try to recover. to put the stream in PREPARED state so it can start again next time. + } + else if (r < 0) + { + fprintf(stderr,"error from read:%s\n",snd_strerror(r)); + } + else if (r != chunk_size) + { + fprintf(stderr,"short read, read %d frames\n",r); + } + if (r > 0) + { + pv = (int16_t *)data; //--get pointer for chunk data + data += chunk_byte;//--move current buffer position pointer, short run is NOT considered!!! + //------------ checker timer, return when DELAY_TIME used up ---------------- + gettimeofday(&t_end,NULL); + cost_times = t_end.tv_sec-t_start.tv_sec; + if(cost_times >= DELAY_TIME) + { + wave_buf_used = data-wave_buf; + return true; + } + //----------- check sound wave amplitude ----------------- + averg = 0; + total = 0; + for (i = 0; i < r; i++) + { //r -- chunk_size,16bits each frame. + total += abs(*pv); // !!!!!! + pv += 1; + } + //printf("total = %d\n", total); + //averg = (total >> CN); + averg = (total/chunk_size); + //printf("averg = %d\n",averg); + if(averg >= KEEP_AVERG) + { + gettimeofday(&t_start,NULL); // reset timer, add one more DELAY_TIME for recording. + printf("averg = %d\n",averg); + printf("loud noise sensed!\n"); + } + } + /* + else //if(r<0) + { + wave_buf_used=data-wave_buf; + return false; + } + */ + } // end of while() + + wave_buf_used = data-wave_buf; //--short run is not considered!!! + + return true; +} + +//βdtimeȷ¼ʱ䣬¼ʱݿռ䣬ٵsnd_pcm_readiƵ豸ȡƵݣŵwave_bufС +//ͬԭһźƵ豸дݣ + +bool device_play() +{ + char *data = wave_buf; + int r = 0; + chunk_size = 32; + + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + while ((data-wave_buf) <= (wave_buf_used-chunk_byte)) + { + r = snd_pcm_writei(pcm_handle, data , chunk_size); //chunk_size = frames + if(r == -EAGAIN) + continue; + if(r < 0) + { + printf("write error: %s\n",snd_strerror(r)); + //exit(EXIT_FAILURE); //ocassionally, it will exit here! + return false; + } + //printf("----- writei() r=%d -----\n ",r); + if ( r > 0 ) + data += chunk_byte; + else + return false; + } + + return true; +} + +bool device_check_voice(void) +{ + int i; + int r = 0; + int count = 0; + int total = 0; + int averg = 0;//average of sample values in one chunk. + int CN = 5; + + chunk_size = SAMPLE_RATE/CHECK_FREQ; //64--how many frames to be checked for specified CHECK_FREQ,one channel + //chunk_size = (2 << CN); //--frames each time + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; //---128 bytes + int16_t *buf = (int16_t *)malloc(chunk_byte); //--sample width 16bits + int16_t *data = buf; + + printf("listening and checking any voice......\n"); + while(1) + { + r = snd_pcm_readi(pcm_handle, (char *) buf, chunk_size); //chunk_size*bit_per_sample*read interleaved rames from a PCM + + if(r == -EAGAIN) + continue; + if (r >= 0) + { + //printf(" r= %d \n ",r); + data = buf; + averg = 0; + total = 0; + for(i = 0; i < r; i++) + { + total += abs(*data); // !!!!!! + data += 1; + } + //printf("total=%d\n",total); + //averg=(total >> CN); + averg = (total/chunk_size); + //printf("averg=%d\n",averg); + if(averg >= CHECK_AVERG ) + { + printf("loud noise sensed! averg = %d chunk_size = %d\n", averg, chunk_size); + free(buf); + return true; + } + //usleep(20000); // + //snd_pcm_prepare(pcm_handle); + //usleep(10000); //---you cann't sleep here, + }//if + else + { + printf(" r = %d \n ",r); + free(buf); + return false; + } + } //while(1) + + free(buf); + + return true; +} + + + + + + diff --git a/alsa/shine_test.c b/alsa/shine_test.c old mode 100644 new mode 100755 diff --git a/codetab.h b/codetab.h new file mode 100755 index 00000000..2b6cc236 --- /dev/null +++ b/codetab.h @@ -0,0 +1,418 @@ +#ifndef _CODETAB_H_ +#define _CODETAB_H_ + +/***************************16*16*********/ +unsigned char F16x16[] = +{ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ + +0x00,0x02,0x02,0xFA,0xFA,0xAA,0xAA,0xFF,0xFF,0xAA,0xAA,0xFA,0xFA,0x02,0x02,0x00, +0x00,0x42,0x72,0x72,0x3A,0x7A,0x42,0x4B,0x5B,0x52,0x62,0x62,0x13,0x77,0x66,0x00,/*"",1*/ + +0x20,0x3C,0x1C,0xFF,0xFF,0xB0,0xB4,0x24,0x24,0x3F,0x3F,0xE4,0xE4,0x24,0x24,0x20, +0x02,0x02,0x03,0xFF,0xFF,0x00,0x01,0x05,0x1D,0x59,0xC1,0xFF,0x7F,0x01,0x01,0x01,/*"",2*/ + +0x00,0x00,0x00,0xF8,0xF8,0x48,0x4C,0x4F,0x4B,0x4A,0x48,0x48,0xF8,0xF8,0x00,0x00, +0x00,0x00,0x00,0xFF,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0xFF,0x00,0x00,/*"",3*/ + +0x20,0x24,0x24,0xE4,0xE4,0x24,0x24,0x24,0x30,0x10,0xFF,0xFF,0x10,0xF0,0xF0,0x00, +0x08,0x1C,0x1F,0x0B,0x0C,0x0D,0x4F,0x6E,0x34,0x1C,0x0F,0x23,0x60,0x7F,0x3F,0x00,/*"",4*/ + +0x80,0xC0,0x60,0xF8,0xFF,0x07,0x02,0x00,0xFF,0xFF,0xE0,0x70,0x3C,0x1C,0x08,0x00, +0x00,0x00,0x00,0x7F,0x7F,0x04,0x06,0x03,0x3F,0x7F,0x40,0x40,0x40,0x78,0x78,0x00,/*"",5*/ + +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ + + +0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, +0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,/*"",8*/ +0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, +0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,/*"",9*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",10*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",11*/ +0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00, +0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00,/*"",12*/ +0x00,0x04,0x74,0xD4,0xFF,0xD4,0x74,0x04,0x10,0x0C,0xB7,0x44,0xB4,0x0C,0x04,0x00, +0x00,0x42,0x43,0x7A,0x43,0x42,0x43,0x7E,0x4B,0x4B,0x4A,0x4A,0x42,0x43,0x01,0x00,/*"",13*/ +0x08,0x08,0x08,0x08,0x08,0x08,0xF9,0x4A,0x4C,0x48,0x48,0xC8,0x08,0x08,0x08,0x00, +0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,/*"",14*/ +0x00,0x20,0x2C,0x24,0x64,0x74,0xAD,0xA6,0xE4,0x34,0x24,0x24,0x2C,0x24,0x00,0x00, +0x00,0x24,0x24,0x25,0x15,0x15,0x0D,0xFE,0x04,0x0D,0x17,0x14,0x24,0x64,0x24,0x00,/*"",15*/ + + +0x00,0x00,0x00,0xF8,0x48,0x48,0x4C,0x4B,0x4A,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x00,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,/*"",16*/ +0x20,0x24,0x24,0xE4,0x24,0x24,0x24,0x20,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00, +0x08,0x1C,0x0B,0x08,0x0C,0x05,0x4E,0x24,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,/*"",17*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",18*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",19*/ +0x08,0x07,0xFA,0xAA,0xAE,0xAA,0xAA,0xA8,0xAC,0xAB,0xAA,0xFE,0x0A,0x02,0x02,0x00, +0x08,0x08,0x8B,0x6A,0x1E,0x0A,0x0A,0x0A,0x0A,0xFE,0x0A,0x0B,0x08,0x08,0x08,0x00,/*"",20*/ +0x10,0x60,0x01,0xC6,0x30,0x00,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x04,0x04,0xFE,0x01,0x00,0x41,0x61,0x51,0x4D,0x43,0x41,0x41,0x51,0xE1,0x01,0x00,/*"",21*/ +0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00, +0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,/*"",22*/ +0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00, +0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"",23*/ + + +0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,/*"",24*/ +0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00, +0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"",25*/ +0x00,0x20,0x20,0x22,0x22,0xE2,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x20,0x20,0x00, +0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,/*"Ԫ",26*/ +0x40,0x20,0xF8,0x0F,0x82,0x60,0x1E,0x14,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x00,0x00,0xFF,0x00,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x00,/*"",27*/ +0x00,0x00,0x00,0x00,0x7E,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0xCC,0x08,0x00, +0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x24,0x46,0x44,0x20,0x1F,0x00,0x00,/*"",28*/ +0x84,0x94,0x94,0xFF,0x94,0x94,0x80,0x24,0x24,0x24,0xFC,0x12,0x13,0x12,0x00,0x00, +0x20,0x18,0x06,0xFF,0x02,0x1C,0x0A,0x02,0x02,0x02,0x3F,0x41,0x41,0x41,0x71,0x00,/*"",29*/ +0x10,0x10,0xD0,0xFE,0x50,0x90,0x00,0x10,0x10,0x10,0xD0,0xFE,0x10,0x10,0x10,0x00, +0x08,0x06,0x01,0xFF,0x00,0x01,0x10,0x08,0x04,0x43,0x80,0x7F,0x00,0x00,0x00,0x00,/*"",30*/ +0x90,0x88,0xA7,0xA2,0xA6,0xBA,0xA2,0xF8,0xA7,0xA2,0xA6,0xBA,0xA2,0x82,0x80,0x00, +0x00,0x04,0x04,0x04,0x04,0x0C,0x34,0x04,0x44,0x84,0x7F,0x04,0x04,0x04,0x00,0x00,/*"",31*/ +}; + +/************************************6*8************************************/ +const unsigned char F6x8[][6] = +{ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp +0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! +0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " +0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # +0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ +0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % +0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & +0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' +0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( +0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) +0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * +0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + +0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , +0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - +0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . +0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / +0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 +0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 +0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 +0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 +0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 +0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 +0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 +0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 +0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 +0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 +0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : +0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; +0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < +0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = +0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > +0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? +0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ +0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A +0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B +0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C +0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D +0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E +0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F +0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G +0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H +0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I +0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J +0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K +0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L +0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M +0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N +0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O +0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P +0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q +0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R +0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S +0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T +0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U +0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V +0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W +0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X +0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y +0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z +0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ +0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 +0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] +0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ +0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ +0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' +0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a +0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b +0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c +0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d +0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e +0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f +0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g +0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h +0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i +0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j +0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k +0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l +0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m +0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n +0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o +0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p +0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q +0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r +0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s +0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t +0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u +0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v +0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w +0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x +0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y +0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z +0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +}; + +/****************************************8*16ĵ************************************/ +const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; + +unsigned char BMP1[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00, + 0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40, + 0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00, + 0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB, + 0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8, + 0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00, + 0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06, + 0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06, + 0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00, + 0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86, + 0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06, + 0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06, + 0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01, + 0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00, + 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA, + 0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80, + 0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0, + 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF, + 0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC, + 0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00,/*"D:\DreamSpark\OLED\MP3_UI.bmp",0*/ +}; + +unsigned char BMP2[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8, + 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0xF8,0x18,0x60,0x80,0x00,0x00,0x00,0x80, + 0x60,0x18,0xF8,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xE0, + 0x10,0x08,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x68, + 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F, + 0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06,0x01, + 0x00,0x00,0x7F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x00,0x1F, + 0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x06,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0xE0,0x20,0x20,0x20, + 0xE0,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x20,0xE0,0x00, + 0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20, + 0x20,0x20,0xC0,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x0F,0x08,0x08,0x08, + 0x0F,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,0x0C,0x08,0x09,0x09,0x0E,0x00, + 0x00,0x0C,0x00,0x00,0x0F,0x09,0x09,0x09,0x0F,0x00,0x00,0x0C,0x00,0x00,0x0C,0x0A, + 0x0A,0x09,0x0C,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00, + 0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA, + 0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F, + 0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00, +}; + +#endif diff --git a/gpio_control b/gpio_control new file mode 100755 index 00000000..8461237d Binary files /dev/null and b/gpio_control differ diff --git a/gpio_control.c b/gpio_control.c new file mode 100755 index 00000000..7348c96d --- /dev/null +++ b/gpio_control.c @@ -0,0 +1,206 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define MMAP_PATH "/dev/mem" + + +#define RALINK_GPIO_DIR_IN 0 +#define RALINK_GPIO_DIR_OUT 1 + +#define RALINK_REG_PIOINT 0x690 +#define RALINK_REG_PIOEDGE 0x6A0 +#define RALINK_REG_PIORENA 0x650 +#define RALINK_REG_PIOFENA 0x660 +#define RALINK_REG_PIODATA 0x620 +#define RALINK_REG_PIODIR 0x600 +#define RALINK_REG_PIOSET 0x630 +#define RALINK_REG_PIORESET 0x640 + +#define RALINK_REG_PIO6332INT 0x694 +#define RALINK_REG_PIO6332EDGE 0x6A4 +#define RALINK_REG_PIO6332RENA 0x654 +#define RALINK_REG_PIO6332FENA 0x664 +#define RALINK_REG_PIO6332DATA 0x624 +#define RALINK_REG_PIO6332DIR 0x604 +#define RALINK_REG_PIO6332SET 0x634 +#define RALINK_REG_PIO6332RESET 0x644 + +#define RALINK_REG_PIO9564INT 0x698 +#define RALINK_REG_PIO9564EDGE 0x6A8 +#define RALINK_REG_PIO9564RENA 0x658 +#define RALINK_REG_PIO9564FENA 0x668 +#define RALINK_REG_PIO9564DATA 0x628 +#define RALINK_REG_PIO9564DIR 0x608 +#define RALINK_REG_PIO9564SET 0x638 +#define RALINK_REG_PIO9564RESET 0x648 + + +static uint8_t* gpio_mmap_reg = NULL; +static int gpio_mmap_fd = 0; + +static int gpio_mmap(void) +{ + if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) + { + fprintf(stderr, "unable to open mmap file"); + return -1; + } + + gpio_mmap_reg = (uint8_t*) mmap(NULL, 1024, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, gpio_mmap_fd, 0x10000000); + if (gpio_mmap_reg == MAP_FAILED) + { + perror("foo"); + fprintf(stderr, "failed to mmap"); + gpio_mmap_reg = NULL; + close(gpio_mmap_fd); + return -1; + } + + return 0; +} + +int mt76x8_gpio_get_pin(int pin) +{ + uint32_t tmp = 0; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODATA); + tmp = (tmp >> pin) & 1u; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DATA); + tmp = (tmp >> (pin-32)) & 1u; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DATA); + tmp = (tmp >> (pin-64)) & 1u; + tmp = (tmp >> (pin-24)) & 1u; + } + return tmp; + +} + +void mt76x8_gpio_set_pin_direction(int pin, int is_output) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR); + if (is_output) + tmp |= (1u << pin); + else + tmp &= ~(1u << pin); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR) = tmp; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR); + if (is_output) + tmp |= (1u << (pin-32)); + else + tmp &= ~(1u << (pin-32)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR) = tmp; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR); + if (is_output) + tmp |= (1u << (pin-64)); + else + tmp &= ~(1u << (pin-64)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR) = tmp; + } +} + +void mt76x8_gpio_set_pin_value(int pin, int value) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = (1u << pin); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIOSET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIORESET) = tmp; + } + else if (pin <= 63) + { + tmp = (1u << (pin-32)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332RESET) = tmp; + } + else if (pin <= 95) + { + tmp = (1u << (pin-64)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564RESET) = tmp; + } +} + +int main(int argc, char **argv) +{ + int ret = -1; + + if (gpio_mmap()) + return -1; + + printf("get pin 39 input %d\n", mt76x8_gpio_get_pin(39)); + printf("get pin 40 input %d\n", mt76x8_gpio_get_pin(40)); + printf("get pin 41 input %d\n", mt76x8_gpio_get_pin(41)); + printf("get pin 42 input %d\n", mt76x8_gpio_get_pin(42)); + + + printf("set pin 39 output 1\n"); + mt76x8_gpio_set_pin_direction(39, 1); + mt76x8_gpio_set_pin_value(39, 1); + printf("set pin 40 output 0\n"); + mt76x8_gpio_set_pin_direction(40, 1); + mt76x8_gpio_set_pin_value(40, 0); + printf("set pin 41 output 1\n"); + mt76x8_gpio_set_pin_direction(41, 1); + mt76x8_gpio_set_pin_value(41, 1); + printf("set pin 42 output 0\n"); + mt76x8_gpio_set_pin_direction(42, 1); + mt76x8_gpio_set_pin_value(42, 0); + + while (1) + { + mt76x8_gpio_set_pin_value(42, 1); + printf("........ mt76x8_gpio_set_pin_value(1)"); + sleep(5); + mt76x8_gpio_set_pin_value(42, 0); + printf("........ mt76x8_gpio_set_pin_value(0)"); + sleep(5); + } + close(gpio_mmap_fd); + + return ret; +} + + diff --git a/gpio_iic b/gpio_iic new file mode 100755 index 00000000..d237dc67 Binary files /dev/null and b/gpio_iic differ diff --git a/gpio_iic.c b/gpio_iic.c new file mode 100755 index 00000000..b739432e --- /dev/null +++ b/gpio_iic.c @@ -0,0 +1,517 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "codetab.h" + +#define MMAP_PATH "/dev/mem" + + +#define RALINK_GPIO_DIR_IN 0 +#define RALINK_GPIO_DIR_OUT 1 + +#define RALINK_REG_PIOINT 0x690 +#define RALINK_REG_PIOEDGE 0x6A0 +#define RALINK_REG_PIORENA 0x650 +#define RALINK_REG_PIOFENA 0x660 +#define RALINK_REG_PIODATA 0x620 +#define RALINK_REG_PIODIR 0x600 +#define RALINK_REG_PIOSET 0x630 +#define RALINK_REG_PIORESET 0x640 + +#define RALINK_REG_PIO6332INT 0x694 +#define RALINK_REG_PIO6332EDGE 0x6A4 +#define RALINK_REG_PIO6332RENA 0x654 +#define RALINK_REG_PIO6332FENA 0x664 +#define RALINK_REG_PIO6332DATA 0x624 +#define RALINK_REG_PIO6332DIR 0x604 +#define RALINK_REG_PIO6332SET 0x634 +#define RALINK_REG_PIO6332RESET 0x644 + +#define RALINK_REG_PIO9564INT 0x698 +#define RALINK_REG_PIO9564EDGE 0x6A8 +#define RALINK_REG_PIO9564RENA 0x658 +#define RALINK_REG_PIO9564FENA 0x668 +#define RALINK_REG_PIO9564DATA 0x628 +#define RALINK_REG_PIO9564DIR 0x608 +#define RALINK_REG_PIO9564SET 0x638 +#define RALINK_REG_PIO9564RESET 0x648 + + +static uint8_t* gpio_mmap_reg = NULL; +static int gpio_mmap_fd = 0; + +static int gpio_mmap(void) +{ + if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) + { + fprintf(stderr, "unable to open mmap file"); + return -1; + } + + gpio_mmap_reg = (uint8_t*) mmap(NULL, 1024, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, gpio_mmap_fd, 0x10000000); + if (gpio_mmap_reg == MAP_FAILED) + { + perror("foo"); + fprintf(stderr, "failed to mmap"); + gpio_mmap_reg = NULL; + close(gpio_mmap_fd); + return -1; + } + + return 0; +} + +int mt76x8_gpio_get_pin(int pin) +{ + uint32_t tmp = 0; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODATA); + tmp = (tmp >> pin) & 1u; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DATA); + tmp = (tmp >> (pin-32)) & 1u; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DATA); + tmp = (tmp >> (pin-64)) & 1u; + tmp = (tmp >> (pin-24)) & 1u; + } + return tmp; + +} + +void mt76x8_gpio_set_pin_direction(int pin, int is_output) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR); + if (is_output) + tmp |= (1u << pin); + else + tmp &= ~(1u << pin); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR) = tmp; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR); + if (is_output) + tmp |= (1u << (pin-32)); + else + tmp &= ~(1u << (pin-32)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR) = tmp; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR); + if (is_output) + tmp |= (1u << (pin-64)); + else + tmp &= ~(1u << (pin-64)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR) = tmp; + } +} + +void mt76x8_gpio_set_pin_value(int pin, int value) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = (1u << pin); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIOSET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIORESET) = tmp; + } + else if (pin <= 63) + { + tmp = (1u << (pin-32)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332RESET) = tmp; + } + else if (pin <= 95) + { + tmp = (1u << (pin-64)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564RESET) = tmp; + } +} + + + +/********************************************* +*GPIO simulation IIC +**********************************************/ +#define SCL 41 +#define SDA 42 +#define high 1 +#define low 0 + +#define Brightness 0xCF +#define X_WIDTH 128 +#define Y_WIDTH 64 + +//init GPIO port +void init_gpio() +{ + if (gpio_mmap()) + printf("gpio_mmap() error!\n"); + + printf("get pin SCL input %d\n", mt76x8_gpio_get_pin(SCL)); + printf("get pin SDA input %d\n", mt76x8_gpio_get_pin(SDA)); + + printf("set pin SCL output 0\n"); + mt76x8_gpio_set_pin_direction(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); + printf("set pin SDA output 0\n"); + mt76x8_gpio_set_pin_direction(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); +} + +/********************************************** +//IIC Start +**********************************************/ +void IIC_Start() +{ + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +//IIC Stop +**********************************************/ +void IIC_Stop() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); +} + +void IIC_Ack() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +// iic bus write a byte +**********************************************/ +void Write_IIC_Byte(unsigned char IIC_Byte) +{ + unsigned char t; + mt76x8_gpio_set_pin_value(SCL, 0); + + for (t = 0; t < 8; t++) + { + mt76x8_gpio_set_pin_value(SDA, (IIC_Byte&0x80)>>7); + IIC_Byte<<=1; + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 1); + //usleep(1); + mt76x8_gpio_set_pin_value(SCL, 0); + } +} + +/*********************OLED write date************************************/ +void OLED_WrDat(unsigned char IIC_Data) +{ + IIC_Start(); + Write_IIC_Byte(0x78); + IIC_Ack(); + Write_IIC_Byte(0x40); //write data + IIC_Ack(); + Write_IIC_Byte(IIC_Data); + IIC_Ack(); + IIC_Stop(); +} +/*********************OLED write command*********************************/ +void OLED_WrCmd(unsigned char IIC_Command) +{ + IIC_Start(); + Write_IIC_Byte(0x78); //Slave address,SA0=0 + IIC_Ack(); + Write_IIC_Byte(0x00); //write command + IIC_Ack(); + Write_IIC_Byte(IIC_Command); + IIC_Ack(); + IIC_Stop(); +} + +/*********************OLED set postion************************************/ +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WrCmd(0xb0+y); + OLED_WrCmd(((x&0xf0)>>4)|0x10); + OLED_WrCmd((x&0x0f)|0x01); +} + +/*********************OLED fill screen************************************/ +void OLED_Fill(unsigned char bmp_dat) +{ + unsigned char y,x; + for(y=0;y<8;y++) + { + OLED_WrCmd(0xb0+y); + OLED_WrCmd(0x01); + OLED_WrCmd(0x10); + for(x=0;x 0xa1 normal + OLED_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0 0xc8 normal + OLED_WrCmd(0xa6);//--set normal display + OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64) + OLED_WrCmd(0x3f);//--1/64 duty + OLED_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) + OLED_WrCmd(0x00);//-not offset + OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency + OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec + OLED_WrCmd(0xd9);//--set pre-charge period + OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock + OLED_WrCmd(0xda);//--set com pins hardware configuration + OLED_WrCmd(0x12); + OLED_WrCmd(0xdb);//--set vcomh + OLED_WrCmd(0x40);//Set VCOM Deselect Level + OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02) + OLED_WrCmd(0x02);// + OLED_WrCmd(0x8d);//--set Charge Pump enable/disable + OLED_WrCmd(0x14);//--set(0x10) disable + OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5) + OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) + OLED_WrCmd(0xaf);//--turn on oled panel + OLED_Fill(0x00); //clear + OLED_Set_Pos(0,0); +} + +/***************display a 6*8 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P6x8Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>126) {x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<6;i++) + { + OLED_WrDat(F6x8[c][i]); + } + x+=6; + j++; + } +} + +/*******************display a 8*16 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P8x16Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>120){x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i]); + } + OLED_Set_Pos(x,y+1); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i+8]); + } + x+=8; + j++; + } +} +/*****************display a 16*16 ASCII charactertic postion x,y y 0-7****************************/ +void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char N) +{ + unsigned char wm=0; + unsigned int adder=32*N; + OLED_Set_Pos(x , y); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } + OLED_Set_Pos(x,y + 1); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } +} + +/***********display a BMP 128*64 (x,y), x 0-127 y 0-7*****************/ +void Draw_BMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1,unsigned char BMP[]) +{ + unsigned int j=0; + unsigned char x,y; + + if(y1%8==0) + y=y1/8; + else + y=y1/8+1; + for(y=y0;y +#include + +int main() +{ + //mraa_result rv; + mraa_gpio_context gpio; + mraa_result_t res; + + const char* board_name = mraa_get_platform_name(); + fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name); + + // rv = mraa_init(); + // if (rv != MRAA_SUCCESS) + // { + // printf("Error: mraa_init() error!\n"); + // //return 1; + // } + + gpio = mraa_gpio_init(40); + if (gpio == NULL) + { + printf("Error: mraa_gpio_init() error! \n"); + //return 1; + } + + res = mraa_gpio_dir(gpio, MRAA_GPIO_OUT); + if (res != MRAA_SUCCESS ) + { + printf("Error: mraa_gpio_dir() error! %d\n", res); + //return 1; + } + + while(1) + { + mraa_gpio_write(gpio, 1); + printf("write 1 \n"); + sleep(5); + mraa_gpio_write(gpio, 0); + printf("write 0 \n"); + sleep(5); + } + + mraa_gpio_close(gpio); + + return 0; +} + diff --git a/mt7688-alsa/Makefile b/mt7688-alsa/Makefile new file mode 100755 index 00000000..93c3a4ef --- /dev/null +++ b/mt7688-alsa/Makefile @@ -0,0 +1,32 @@ +BIN_FILE = main +OBJECTS = main.o record.o key.o oled_iic.o mem_gpio.o cJSON.o call_python.o +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine -lpthread \ +-I /home/zyc/Documents/Python-2.7.12/python-mips/include/python2.7 -L /home/zyc/Documents/Python-2.7.12/python-mips/lib -lpython2.7 + +mem_gpio.o : mem_gpio.c + $(CC) -c mem_gpio.c + +key.o : key.c + $(CC) -c key.c + +oled_iic.o : oled_iic.c + $(CC) -c oled_iic.c + +record.o : record.c + $(CC) -c record.c -I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine + +cJSON.o : cJSON.c + $(CC) -c cJSON.c + +call_python.o : call_python.c + $(CC) -c call_python.c -I /home/zyc/Documents/Python-2.7.12/python-mips/include/python2.7 -L /home/zyc/Documents/Python-2.7.12/python-mips/lib -lpython2.7 + +main.o : main.c + $(CC) -c main.c -lpthread + +clean : + rm main *.o diff --git a/mt7688-alsa/Makefile1 b/mt7688-alsa/Makefile1 new file mode 100755 index 00000000..93c3a4ef --- /dev/null +++ b/mt7688-alsa/Makefile1 @@ -0,0 +1,32 @@ +BIN_FILE = main +OBJECTS = main.o record.o key.o oled_iic.o mem_gpio.o cJSON.o call_python.o +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine -lpthread \ +-I /home/zyc/Documents/Python-2.7.12/python-mips/include/python2.7 -L /home/zyc/Documents/Python-2.7.12/python-mips/lib -lpython2.7 + +mem_gpio.o : mem_gpio.c + $(CC) -c mem_gpio.c + +key.o : key.c + $(CC) -c key.c + +oled_iic.o : oled_iic.c + $(CC) -c oled_iic.c + +record.o : record.c + $(CC) -c record.c -I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine + +cJSON.o : cJSON.c + $(CC) -c cJSON.c + +call_python.o : call_python.c + $(CC) -c call_python.c -I /home/zyc/Documents/Python-2.7.12/python-mips/include/python2.7 -L /home/zyc/Documents/Python-2.7.12/python-mips/lib -lpython2.7 + +main.o : main.c + $(CC) -c main.c -lpthread + +clean : + rm main *.o diff --git a/mt7688-alsa/Makefile3 b/mt7688-alsa/Makefile3 new file mode 100755 index 00000000..4cd17ccd --- /dev/null +++ b/mt7688-alsa/Makefile3 @@ -0,0 +1,43 @@ +###################################### +# +###################################### +#source file +#auto find all *.c and *.cpp files, and compile to *.o file +SOURCE := $(wildcard *.c) $(wildcard *.cpp) +OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE))) $(CXXFLAGS) + +#target change name to what you want +TARGET := main + +#compile and lib parameter +#编译参数 +CC := mipsel-openwrt-linux-gcc +LIBS := /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine +LDFLAGS := -L +DEFINES := -I +INCLUDE := /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include +CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE) +CXXFLAGS := $(CFLAGS) -DHAVE_CONFIG_H + + +#i think you should do anything here +#下面的基本上不需要做任何改动了 +.PHONY : everything objs clean veryclean rebuild + +everything : $(TARGET) + +all : $(TARGET) + +objs : $(OBJS) + +rebuild: veryclean everything + +clean : + rm -fr *.o + +veryclean : clean + rm -fr $(TARGET) + +$(TARGET) : $(OBJS) + $(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) + diff --git a/mt7688-alsa/build.sh b/mt7688-alsa/build.sh new file mode 100755 index 00000000..bbb92b06 --- /dev/null +++ b/mt7688-alsa/build.sh @@ -0,0 +1,8 @@ +#!/bin/sh +BIN_FILE=record_control +STR_FILE=$BIN_FILE'.c' +mipsel-openwrt-linux-gcc -o $BIN_FILE $STR_FILE \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include/ \ +-L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib \ +-L. \ +-lasound -lm -lmp3lame -lshine diff --git a/mt7688-alsa/cJSON.c b/mt7688-alsa/cJSON.c new file mode 100755 index 00000000..5cd2a24c --- /dev/null +++ b/mt7688-alsa/cJSON.c @@ -0,0 +1,2279 @@ +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* cJSON */ +/* JSON parser in C. */ + +#pragma GCC visibility push(default) +#include +#include +#include +#include +#include +#include +#include +#pragma GCC visibility pop + +#include "cJSON.h" + +/* define our own boolean type */ +#define true ((cJSON_bool)1) +#define false ((cJSON_bool)0) + +static const unsigned char *global_ep = NULL; + +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) global_ep; +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 4) || (CJSON_VERSION_PATCH != 0) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#endif + +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; +} + +/* case insensitive strcmp */ +static int cJSON_strcasecmp(const unsigned char *s1, const unsigned char *s2) +{ + if (!s1) + { + return (s1 == s2) ? 0 : 1; /* both NULL? */ + } + if (!s2) + { + return 1; + } + for(; tolower(*s1) == tolower(*s2); (void)++s1, ++s2) + { + if (*s1 == '\0') + { + return 0; + } + } + + return tolower(*s1) - tolower(*s2); +} + +typedef struct internal_hooks +{ + void *(*allocate)(size_t size); + void (*deallocate)(void *pointer); + void *(*reallocate)(void *pointer, size_t size); +} internal_hooks; + +static internal_hooks global_hooks = { malloc, free, realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* str, const internal_hooks * const hooks) +{ + size_t len = 0; + unsigned char *copy = NULL; + + if (str == NULL) + { + return NULL; + } + + len = strlen((const char*)str) + 1; + if (!(copy = (unsigned char*)hooks->allocate(len))) + { + return NULL; + } + memcpy(copy, str, len); + + return copy; +} + +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; +} + +/* Delete a cJSON structure. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *c) +{ + cJSON *next = NULL; + while (c) + { + next = c->next; + if (!(c->type & cJSON_IsReference) && c->child) + { + cJSON_Delete(c->child); + } + if (!(c->type & cJSON_IsReference) && c->valuestring) + { + global_hooks.deallocate(c->valuestring); + } + if (!(c->type & cJSON_StringIsConst) && c->string) + { + global_hooks.deallocate(c->string); + } + global_hooks.deallocate(c); + c = next; + } +} + +/* Parse the input text to generate a number, and populate the result into item. */ +static const unsigned char *parse_number(cJSON * const item, const unsigned char * const input) +{ + double number = 0; + unsigned char *after_end = NULL; + + if (input == NULL) + { + return NULL; + } + + number = strtod((const char*)input, (char**)&after_end); + if (input == after_end) + { + return NULL; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + return after_end; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = cJSON_Number; + } + + return object->valuedouble = number; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + cJSON_bool noalloc; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed, const internal_hooks * const hooks) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + newsize = needed * 2; + if (newsize > INT_MAX) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + + if (hooks->reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)hooks->reallocate(p->buffer, newsize); + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)hooks->allocate(newsize); + if (!newbuffer) + { + hooks->deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + if (newbuffer) + { + memcpy(newbuffer, p->buffer, p->offset + 1); + } + hooks->deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); +} + +/* Removes trailing zeroes from the end of a printed number */ +static cJSON_bool trim_trailing_zeroes(printbuffer * const buffer) +{ + size_t offset = 0; + unsigned char *content = NULL; + + if ((buffer == NULL) || (buffer->buffer == NULL) || (buffer->offset < 1)) + { + return false; + } + + offset = buffer->offset - 1; + content = buffer->buffer; + + while ((offset > 0) && (content[offset] == '0')) + { + offset--; + } + if ((offset > 0) && (content[offset] == '.')) + { + offset--; + } + + offset++; + content[offset] = '\0'; + + buffer->offset = offset; + + return true; +} + +/* Render the number nicely from the given item into a string. */ +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer, const internal_hooks * const hooks) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + cJSON_bool trim_zeroes = true; /* should at the end be removed? */ + + if (output_buffer == NULL) + { + return false; + } + + /* This is a nice tradeoff. */ + output_pointer = ensure(output_buffer, 64, hooks); + if (output_pointer != NULL) + { + /* This checks for NaN and Infinity */ + if ((d * 0) != 0) + { + length = sprintf((char*)output_pointer, "null"); + } + else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60)) + { + /* integer */ + length = sprintf((char*)output_pointer, "%.0f", d); + trim_zeroes = false; /* don't remove zeroes for "big integers" */ + } + else if ((fabs(d) < 1.0e-6) || (fabs(d) > 1.0e9)) + { + length = sprintf((char*)output_pointer, "%e", d); + trim_zeroes = false; /* don't remove zeroes in engineering notation */ + } + else + { + length = sprintf((char*)output_pointer, "%f", d); + } + } + + /* sprintf failed */ + if (length < 0) + { + return false; + } + + output_buffer->offset += (size_t)length; + + if (trim_zeroes) + { + return trim_trailing_zeroes(output_buffer); + } + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 + * A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer, const unsigned char **error_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + *error_pointer = first_sequence; + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF)) || (first_code == 0)) + { + *error_pointer = first_sequence; + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + *error_pointer = first_sequence; + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + *error_pointer = first_sequence; + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + *error_pointer = first_sequence; + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + *error_pointer = first_sequence; + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static const unsigned char *parse_string(cJSON * const item, const unsigned char * const input, const unsigned char ** const error_pointer, const internal_hooks * const hooks) +{ + const unsigned char *input_pointer = input + 1; + const unsigned char *input_end = input + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (*input != '\"') + { + *error_pointer = input; + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while ((*input_end != '\"') && (*input_end != '\0')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if (input_end[1] == '\0') + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (*input_end == '\0') + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - input) - skipped_bytes; + output = (unsigned char*)hooks->allocate(allocation_length + sizeof('\0')); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer, error_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + *error_pointer = input_pointer; + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + return input_end + 1; + +fail: + if (output != NULL) + { + hooks->deallocate(output); + } + + return NULL; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer, const internal_hooks * const hooks) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\""), hooks); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + if (strchr("\"\\\b\f\n\r\t", *input_pointer)) + { + /* one character escape sequence */ + escape_characters++; + } + else if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\""), hooks); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p, const internal_hooks * const hooks) +{ + return print_string_ptr((unsigned char*)item->valuestring, p, hooks); +} + +/* Predeclare these prototypes. */ +static const unsigned char *parse_value(cJSON * const item, const unsigned char * const input, const unsigned char ** const ep, const internal_hooks * const hooks); +static cJSON_bool print_value(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks); +static const unsigned char *parse_array(cJSON * const item, const unsigned char *input, const unsigned char ** const ep, const internal_hooks * const hooks); +static cJSON_bool print_array(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks); +static const unsigned char *parse_object(cJSON * const item, const unsigned char *input, const unsigned char ** const ep, const internal_hooks * const hooks); +static cJSON_bool print_object(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks); + +/* Utility to jump whitespace and cr/lf */ +static const unsigned char *skip_whitespace(const unsigned char *in) +{ + while (in && *in && (*in <= 32)) + { + in++; + } + + return in; +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + const unsigned char *end = NULL; + /* use global error pointer if no specific one was given */ + const unsigned char **ep = return_parse_end ? (const unsigned char**)return_parse_end : &global_ep; + cJSON *c = cJSON_New_Item(&global_hooks); + *ep = NULL; + if (!c) /* memory fail */ + { + return NULL; + } + + end = parse_value(c, skip_whitespace((const unsigned char*)value), ep, &global_hooks); + if (!end) + { + /* parse failure. ep is set. */ + cJSON_Delete(c); + return NULL; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + end = skip_whitespace(end); + if (*end) + { + cJSON_Delete(c); + *ep = end; + return NULL; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)end; + } + + return c; +} + +/* Default options for cJSON_Parse */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); +} + +#define min(a, b) ((a < b) ? a : b) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(256); + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, 0, format, buffer, hooks)) + { + goto fail; + } + update_offset(buffer); + + /* copy the buffer over to a new one */ + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + strncpy((char*)printed, (char*)buffer->buffer, min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; +} + +/* Render a cJSON item/entity/structure to text. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + + if (!print_value(item, 0, fmt, &p, &global_hooks)) + { + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt) +{ + printbuffer p; + + if (len < 0) + { + return false; + } + + p.buffer = (unsigned char*)buf; + p.length = (size_t)len; + p.offset = 0; + p.noalloc = true; + return print_value(item, 0, fmt, &p, &global_hooks); +} + +/* Parser core - when encountering text, process appropriately. */ +static const unsigned char *parse_value(cJSON * const item, const unsigned char * const input, const unsigned char ** const error_pointer, const internal_hooks * const hooks) +{ + if (input == NULL) + { + return NULL; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (!strncmp((const char*)input, "null", 4)) + { + item->type = cJSON_NULL; + return input + 4; + } + /* false */ + if (!strncmp((const char*)input, "false", 5)) + { + item->type = cJSON_False; + return input + 5; + } + /* true */ + if (!strncmp((const char*)input, "true", 4)) + { + item->type = cJSON_True; + item->valueint = 1; + return input + 4; + } + /* string */ + if (*input == '\"') + { + return parse_string(item, input, error_pointer, hooks); + } + /* number */ + if ((*input == '-') || ((*input >= '0') && (*input <= '9'))) + { + return parse_number(item, input); + } + /* array */ + if (*input == '[') + { + return parse_array(item, input, error_pointer, hooks); + } + /* object */ + if (*input == '{') + { + return parse_object(item, input, error_pointer, hooks); + } + + /* failure. */ + *error_pointer = input; + return NULL; +} + +/* Render a value to text. */ +static cJSON_bool print_value(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks) +{ + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5, hooks); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6, hooks); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5, hooks); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer, hooks); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + if (!output_buffer->noalloc) + { + hooks->deallocate(output_buffer->buffer); + } + return false; + } + + raw_length = strlen(item->valuestring) + sizeof('\0'); + output = ensure(output_buffer, raw_length, hooks); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer, hooks); + + case cJSON_Array: + return print_array(item, depth, format, output_buffer, hooks); + + case cJSON_Object: + return print_object(item, depth, format, output_buffer, hooks); + + default: + return false; + } +} + +/* Build an array from input text. */ +static const unsigned char *parse_array(cJSON * const item, const unsigned char *input, const unsigned char ** const error_pointer, const internal_hooks * const hooks) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (*input != '[') + { + /* not an array */ + *error_pointer = input; + goto fail; + } + + input = skip_whitespace(input + 1); + if (*input == ']') + { + /* empty array */ + goto success; + } + + /* step back to character in front of the first element */ + input--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(hooks); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input = skip_whitespace(input + 1); + input = parse_value(current_item, input, error_pointer, hooks); + input = skip_whitespace(input); + if (input == NULL) + { + goto fail; /* failed to parse value */ + } + } + while (*input == ','); + + if (*input != ']') + { + *error_pointer = input; + goto fail; /* expected end of array */ + } + +success: + item->type = cJSON_Array; + item->child = head; + + return input + 1; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return NULL; +} + +/* Render an array to text */ +static cJSON_bool print_array(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1, hooks); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + + while (current_element != NULL) + { + if (!print_value(current_element, depth + 1, format, output_buffer, hooks)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = format ? 2 : 1; + output_pointer = ensure(output_buffer, length + 1, hooks); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2, hooks); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + + return true; +} + +/* Build an object from the text. */ +static const unsigned char *parse_object(cJSON * const item, const unsigned char *input, const unsigned char ** const error_pointer, const internal_hooks * const hooks) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (*input != '{') + { + *error_pointer = input; + goto fail; /* not an object */ + } + + input = skip_whitespace(input + 1); + if (*input == '}') + { + goto success; /* empty object */ + } + + /* step back to character in front of the first element */ + input--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(hooks); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input = skip_whitespace(input + 1); + input = parse_string(current_item, input, error_pointer, hooks); + input = skip_whitespace(input); + if (input == NULL) + { + goto fail; /* faile to parse name */ + } + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (*input != ':') + { + *error_pointer = input; + goto fail; /* invalid object */ + } + + /* parse the value */ + input = skip_whitespace(input + 1); + input = parse_value(current_item, input, error_pointer, hooks); + input = skip_whitespace(input); + if (input == NULL) + { + goto fail; /* failed to parse value */ + } + } + while (*input == ','); + + if (*input != '}') + { + *error_pointer = input; + goto fail; /* expected end of object */ + } + +success: + item->type = cJSON_Object; + item->child = head; + + return input + 1; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return NULL; +} + +/* Render an object to text. */ +static cJSON_bool print_object(const cJSON * const item, const size_t depth, const cJSON_bool format, printbuffer * const output_buffer, const internal_hooks * const hooks) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output: */ + length = format ? 2 : 1; /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1, hooks); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + if (format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (format) + { + size_t i; + output_pointer = ensure(output_buffer, depth + 1, hooks); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < depth + 1; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += depth + 1; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer, hooks)) + { + return false; + } + update_offset(output_buffer); + + length = format ? 2 : 1; + output_pointer = ensure(output_buffer, length, hooks); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, depth + 1, format, output_buffer, hooks)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = (size_t) (format ? 1 : 0) + (current_item->next ? 1 : 0); + output_pointer = ensure(output_buffer, length + 1, hooks); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, format ? (depth + 2) : 2, hooks); + if (output_pointer == NULL) + { + return false; + } + if (format) + { + size_t i; + for (i = 0; i < (depth); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + + return true; +} + +/* Get Array size/item / object item. */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *c = array->child; + size_t i = 0; + while(c) + { + i++; + c = c->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)i; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int item) +{ + cJSON *c = array ? array->child : NULL; + while (c && item > 0) + { + item--; + c = c->next; + } + + return c; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *object, const char *string) +{ + cJSON *c = object ? object->child : NULL; + while (c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string)) + { + c = c->next; + } + return c; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (string == NULL)) + { + return NULL; + } + + current_element = object->child; + while ((current_element != NULL) && (strcmp(string, current_element->string) != 0)) + { + current_element = current_element->next; + } + + return current_element; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + +/* Utility for handling references. */ +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *ref = cJSON_New_Item(hooks); + if (!ref) + { + return NULL; + } + memcpy(ref, item, sizeof(cJSON)); + ref->string = NULL; + ref->type |= cJSON_IsReference; + ref->next = ref->prev = NULL; + return ref; +} + +/* Add item to array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; + + if ((item == NULL) || (array == NULL)) + { + return; + } + + child = array->child; + + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + } + else + { + /* append to the end */ + while (child->next) + { + child = child->next; + } + suffix_object(child, item); + } +} + +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + /* call cJSON_AddItemToObjectCS for code reuse */ + cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item); + /* remove cJSON_StringIsConst flag */ + item->type &= ~cJSON_StringIsConst; +} + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + if (!item) + { + return; + } + if (!(item->type & cJSON_StringIsConst) && item->string) + { + global_hooks.deallocate(item->string); + } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" + item->string = (char*)string; +#pragma GCC diagnostic pop + item->type |= cJSON_StringIsConst; + cJSON_AddItemToArray(object, item); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + cJSON_AddItemToArray(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + cJSON_AddItemToObject(object, string, create_reference(item, &global_hooks)); +} + +static cJSON *DetachItemFromArray(cJSON *array, size_t which) +{ + cJSON *c = array->child; + while (c && (which > 0)) + { + c = c->next; + which--; + } + if (!c) + { + /* item doesn't exist */ + return NULL; + } + if (c->prev) + { + /* not the first element */ + c->prev->next = c->next; + } + if (c->next) + { + c->next->prev = c->prev; + } + if (c==array->child) + { + array->child = c->next; + } + /* make sure the detached item doesn't point anywhere anymore */ + c->prev = c->next = NULL; + + return c; +} +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return DetachItemFromArray(array, (size_t)which); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + size_t i = 0; + cJSON *c = object->child; + while (c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string)) + { + i++; + c = c->next; + } + if (c) + { + return DetachItemFromArray(object, i); + } + + return NULL; +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +/* Replace array/object items with new ones. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *c = array->child; + while (c && (which > 0)) + { + c = c->next; + which--; + } + if (!c) + { + cJSON_AddItemToArray(array, newitem); + return; + } + newitem->next = c; + newitem->prev = c->prev; + c->prev = newitem; + if (c == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } +} + +static void ReplaceItemInArray(cJSON *array, size_t which, cJSON *newitem) +{ + cJSON *c = array->child; + while (c && (which > 0)) + { + c = c->next; + which--; + } + if (!c) + { + return; + } + newitem->next = c->next; + newitem->prev = c->prev; + if (newitem->next) + { + newitem->next->prev = newitem; + } + if (c == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } + c->next = c->prev = NULL; + cJSON_Delete(c); +} +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return; + } + + ReplaceItemInArray(array, (size_t)which, newitem); +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + size_t i = 0; + cJSON *c = object->child; + while(c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string)) + { + i++; + c = c->next; + } + if(c) + { + /* free the old string if not const */ + if (!(newitem->type & cJSON_StringIsConst) && newitem->string) + { + global_hooks.deallocate(newitem->string); + } + + newitem->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + ReplaceItemInArray(object, i, newitem); + } +} + +/* Create basic types: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = b ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; +} + +/* Create Arrays: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if (count < 0) + { + return NULL; + } + + a = cJSON_CreateArray(); + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if (count < 0) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if (count < 0) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0;a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if (count < 0) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; + } + + return a; +} + +/* Duplication */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; + + /* Bail on bad ptr */ + if (!item) + { + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + unsigned char *into = (unsigned char*)json; + while (*json) + { + if (*json == ' ') + { + json++; + } + else if (*json == '\t') + { + /* Whitespace characters. */ + json++; + } + else if (*json == '\r') + { + json++; + } + else if (*json=='\n') + { + json++; + } + else if ((*json == '/') && (json[1] == '/')) + { + /* double-slash comments, to end of line. */ + while (*json && (*json != '\n')) + { + json++; + } + } + else if ((*json == '/') && (json[1] == '*')) + { + /* multiline comments. */ + while (*json && !((*json == '*') && (json[1] == '/'))) + { + json++; + } + json += 2; + } + else if (*json == '\"') + { + /* string literals, which are \" sensitive. */ + *into++ = (unsigned char)*json++; + while (*json && (*json != '\"')) + { + if (*json == '\\') + { + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + else + { + /* All other characters. */ + *into++ = (unsigned char)*json++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Invalid; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} diff --git a/mt7688-alsa/cJSON.h b/mt7688-alsa/cJSON.h new file mode 100755 index 00000000..407e403d --- /dev/null +++ b/mt7688-alsa/cJSON.h @@ -0,0 +1,237 @@ +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 4 +#define CJSON_VERSION_PATCH 0 + +#include + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; + + /* The type of the item, as above. */ + int type; + + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* The item's number, if type==cJSON_Number */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type __stdcall +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall +#else +#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall +#endif +#else /* !WIN32 */ +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + + +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with length buf_len. Returns 1 on success and 0 on failure. */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int item); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *object, const char *string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* These utilities create an Array of count items. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detatch items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will +need to be released. With recurse!=0, it will duplicate any children connected to the item. +The item->next and ->prev pointers are always zero on return from Duplicate. */ + +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error. If not, then cJSON_GetErrorPtr() does the job. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); + +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) +#define cJSON_AddRawToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateRaw(s)) + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + +/* Macro for iterating over an array */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mt7688-alsa/cJSON.o b/mt7688-alsa/cJSON.o new file mode 100755 index 00000000..2a606e4e Binary files /dev/null and b/mt7688-alsa/cJSON.o differ diff --git a/mt7688-alsa/call_python.c b/mt7688-alsa/call_python.c new file mode 100755 index 00000000..6e14d62a --- /dev/null +++ b/mt7688-alsa/call_python.c @@ -0,0 +1,74 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include "call_python.h" +#include "/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/include/python2.7/Python.h" + +void printDict(PyObject* obj) +{ + if (!PyDict_Check(obj)) + return; + + int i; + PyObject *k, *keys; + keys = PyDict_Keys(obj); + + for (i = 0; i < PyList_GET_SIZE(keys); i++) + { + k = PyList_GET_ITEM(keys, i); + char* c_name = PyString_AsString(k); + printf("%s\n", c_name); + } +} + +int call_main(char* filename, char* funcname, char* name, char* language) +{ + Py_Initialize(); + if (!Py_IsInitialized()) + return -1; + + PyRun_SimpleString("import sys"); + PyRun_SimpleString("sys.path.append('./')"); + + //import model + PyObject* pModule = NULL; + pModule = PyImport_ImportModule(filename); + if (!pModule) + { + printf("Cant open python file!\n"); + return -1; + } + + //model dic list + // PyObject* pDict = PyModule_GetDict(pModule); + // if (!pDict) + // { + // printf("Cant find dictionary.\n"); + // return -1; + // } + //printDict(pDict); + + PyObject * pFunc = NULL; + pFunc = PyObject_GetAttrString(pModule, funcname); + + PyObject *pArgs = PyTuple_New(2); + PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", name)); + PyTuple_SetItem(pArgs, 1, Py_BuildValue("s", language)); + PyObject *pReturn = NULL; + pReturn = PyEval_CallObject(pFunc, pArgs); + //char* result; + //PyArg_Parse(pReturn, "s", &result); + //printf("%s\n", result); + + Py_DECREF(pFunc); + Py_DECREF(pArgs); + //Py_DECREF(pDict); + Py_DECREF(pModule); + Py_Finalize(); + + return 0; +} diff --git a/mt7688-alsa/call_python.h b/mt7688-alsa/call_python.h new file mode 100755 index 00000000..ef396946 --- /dev/null +++ b/mt7688-alsa/call_python.h @@ -0,0 +1,14 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _CALL_PYTHON_H_ +#define _CALL_PYTHON_H_ + + +//------------------- functions declaration ---------------------- +int call_main(char* filename, char* funcname, char* name, char* language); + + +#endif diff --git a/mt7688-alsa/call_python.o b/mt7688-alsa/call_python.o new file mode 100755 index 00000000..8e99a331 Binary files /dev/null and b/mt7688-alsa/call_python.o differ diff --git a/mt7688-alsa/codetab.h b/mt7688-alsa/codetab.h new file mode 100755 index 00000000..297e9f01 --- /dev/null +++ b/mt7688-alsa/codetab.h @@ -0,0 +1,490 @@ +#ifndef _CODETAB_H_ +#define _CODETAB_H_ + +/***************************16*16*********/ +unsigned char F16x16[] = +{ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ + +0x00,0x02,0x02,0xFA,0xFA,0xAA,0xAA,0xFF,0xFF,0xAA,0xAA,0xFA,0xFA,0x02,0x02,0x00, +0x00,0x42,0x72,0x72,0x3A,0x7A,0x42,0x4B,0x5B,0x52,0x62,0x62,0x13,0x77,0x66,0x00,/*"",1*/ + +0x20,0x3C,0x1C,0xFF,0xFF,0xB0,0xB4,0x24,0x24,0x3F,0x3F,0xE4,0xE4,0x24,0x24,0x20, +0x02,0x02,0x03,0xFF,0xFF,0x00,0x01,0x05,0x1D,0x59,0xC1,0xFF,0x7F,0x01,0x01,0x01,/*"",2*/ + +0x00,0x00,0x00,0xF8,0xF8,0x48,0x4C,0x4F,0x4B,0x4A,0x48,0x48,0xF8,0xF8,0x00,0x00, +0x00,0x00,0x00,0xFF,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0xFF,0x00,0x00,/*"",3*/ + +0x20,0x24,0x24,0xE4,0xE4,0x24,0x24,0x24,0x30,0x10,0xFF,0xFF,0x10,0xF0,0xF0,0x00, +0x08,0x1C,0x1F,0x0B,0x0C,0x0D,0x4F,0x6E,0x34,0x1C,0x0F,0x23,0x60,0x7F,0x3F,0x00,/*"",4*/ + +0x80,0xC0,0x60,0xF8,0xFF,0x07,0x02,0x00,0xFF,0xFF,0xE0,0x70,0x3C,0x1C,0x08,0x00, +0x00,0x00,0x00,0x7F,0x7F,0x04,0x06,0x03,0x3F,0x7F,0x40,0x40,0x40,0x78,0x78,0x00,/*"",5*/ + +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ + + +0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, +0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,/*"",8*/ +0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, +0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,/*"",9*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",10*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",11*/ +0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00, +0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00,/*"",12*/ +0x00,0x04,0x74,0xD4,0xFF,0xD4,0x74,0x04,0x10,0x0C,0xB7,0x44,0xB4,0x0C,0x04,0x00, +0x00,0x42,0x43,0x7A,0x43,0x42,0x43,0x7E,0x4B,0x4B,0x4A,0x4A,0x42,0x43,0x01,0x00,/*"",13*/ +0x08,0x08,0x08,0x08,0x08,0x08,0xF9,0x4A,0x4C,0x48,0x48,0xC8,0x08,0x08,0x08,0x00, +0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,/*"",14*/ +0x00,0x20,0x2C,0x24,0x64,0x74,0xAD,0xA6,0xE4,0x34,0x24,0x24,0x2C,0x24,0x00,0x00, +0x00,0x24,0x24,0x25,0x15,0x15,0x0D,0xFE,0x04,0x0D,0x17,0x14,0x24,0x64,0x24,0x00,/*"",15*/ + + +0x00,0x00,0x00,0xF8,0x48,0x48,0x4C,0x4B,0x4A,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x00,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,/*"",16*/ +0x20,0x24,0x24,0xE4,0x24,0x24,0x24,0x20,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00, +0x08,0x1C,0x0B,0x08,0x0C,0x05,0x4E,0x24,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,/*"",17*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",18*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",19*/ +0x08,0x07,0xFA,0xAA,0xAE,0xAA,0xAA,0xA8,0xAC,0xAB,0xAA,0xFE,0x0A,0x02,0x02,0x00, +0x08,0x08,0x8B,0x6A,0x1E,0x0A,0x0A,0x0A,0x0A,0xFE,0x0A,0x0B,0x08,0x08,0x08,0x00,/*"",20*/ +0x10,0x60,0x01,0xC6,0x30,0x00,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x04,0x04,0xFE,0x01,0x00,0x41,0x61,0x51,0x4D,0x43,0x41,0x41,0x51,0xE1,0x01,0x00,/*"",21*/ +0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00, +0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,/*"",22*/ +0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00, +0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"",23*/ + + +0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,/*"",24*/ +0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00, +0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"",25*/ +0x00,0x20,0x20,0x22,0x22,0xE2,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x20,0x20,0x00, +0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,/*"Ԫ",26*/ +0x40,0x20,0xF8,0x0F,0x82,0x60,0x1E,0x14,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x00,0x00,0xFF,0x00,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x00,/*"",27*/ +0x00,0x00,0x00,0x00,0x7E,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0xCC,0x08,0x00, +0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x24,0x46,0x44,0x20,0x1F,0x00,0x00,/*"",28*/ +0x84,0x94,0x94,0xFF,0x94,0x94,0x80,0x24,0x24,0x24,0xFC,0x12,0x13,0x12,0x00,0x00, +0x20,0x18,0x06,0xFF,0x02,0x1C,0x0A,0x02,0x02,0x02,0x3F,0x41,0x41,0x41,0x71,0x00,/*"",29*/ +0x10,0x10,0xD0,0xFE,0x50,0x90,0x00,0x10,0x10,0x10,0xD0,0xFE,0x10,0x10,0x10,0x00, +0x08,0x06,0x01,0xFF,0x00,0x01,0x10,0x08,0x04,0x43,0x80,0x7F,0x00,0x00,0x00,0x00,/*"",30*/ +0x90,0x88,0xA7,0xA2,0xA6,0xBA,0xA2,0xF8,0xA7,0xA2,0xA6,0xBA,0xA2,0x82,0x80,0x00, +0x00,0x04,0x04,0x04,0x04,0x0C,0x34,0x04,0x44,0x84,0x7F,0x04,0x04,0x04,0x00,0x00,/*"",31*/ +}; + +/************************************6*8************************************/ +const unsigned char F6x8[][6] = +{ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp +0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! +0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " +0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # +0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ +0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % +0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & +0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' +0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( +0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) +0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * +0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + +0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , +0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - +0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . +0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / +0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 +0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 +0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 +0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 +0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 +0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 +0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 +0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 +0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 +0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 +0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : +0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; +0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < +0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = +0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > +0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? +0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ +0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A +0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B +0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C +0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D +0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E +0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F +0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G +0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H +0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I +0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J +0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K +0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L +0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M +0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N +0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O +0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P +0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q +0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R +0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S +0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T +0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U +0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V +0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W +0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X +0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y +0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z +0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ +0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 +0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] +0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ +0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ +0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' +0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a +0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b +0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c +0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d +0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e +0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f +0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g +0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h +0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i +0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j +0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k +0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l +0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m +0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n +0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o +0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p +0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q +0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r +0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s +0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t +0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u +0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v +0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w +0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x +0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y +0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z +0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +}; + +/****************************************8*16ĵ************************************/ +const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; + +unsigned char BMP1[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00, + 0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40, + 0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00, + 0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB, + 0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8, + 0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00, + 0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06, + 0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06, + 0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00, + 0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86, + 0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06, + 0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06, + 0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01, + 0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00, + 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA, + 0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80, + 0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0, + 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF, + 0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC, + 0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00,/*"D:\DreamSpark\OLED\MP3_UI.bmp",0*/ +}; + +unsigned char BMP2[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8, + 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0xF8,0x18,0x60,0x80,0x00,0x00,0x00,0x80, + 0x60,0x18,0xF8,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xE0, + 0x10,0x08,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x68, + 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F, + 0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06,0x01, + 0x00,0x00,0x7F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x00,0x1F, + 0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x06,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0xE0,0x20,0x20,0x20, + 0xE0,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x20,0xE0,0x00, + 0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20, + 0x20,0x20,0xC0,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x0F,0x08,0x08,0x08, + 0x0F,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,0x0C,0x08,0x09,0x09,0x0E,0x00, + 0x00,0x0C,0x00,0x00,0x0F,0x09,0x09,0x09,0x0F,0x00,0x00,0x0C,0x00,0x00,0x0C,0x0A, + 0x0A,0x09,0x0C,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00, + 0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA, + 0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F, + 0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00, +}; + +unsigned char BMP3[] = { + 0x08,0x08,0x08,0x08,0x1C,0x1C,0x1C,0x1C,0x3E,0x3E,0x3E,0x3E,0x7F,0x7F,0x3E,0x3E, + 0x3E,0x3E,0x1C,0x1C,0x1C,0x1C,0x08,0x08,0x08,0x08,/*"C:\Users\zyc\Documents\flash.BMP",0*/ +}; + +unsigned char BMP4[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xE0,0xE0 , + 0xE0,0xE0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x03,0x03,0x03,0x03,0x07,0x07,0x03,0x03 , + 0x03,0x03,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,/*"C:\Users\zyc\Documents\flash.BMP",0*/ +}; + +#endif diff --git a/mt7688-alsa/demo/SpeechHelper.py b/mt7688-alsa/demo/SpeechHelper.py new file mode 100755 index 00000000..61f02317 --- /dev/null +++ b/mt7688-alsa/demo/SpeechHelper.py @@ -0,0 +1,215 @@ +import sys +import json +import wave +import uuid +from time import time +from os import environ as env +from xml.etree import ElementTree + +if sys.version.startswith('3'): + import http.client as httpclient + import urllib.parse as urllibparse +else: + import httplib as httpclient + import urllib as urllibparse +''' +IMIO_HOME = env.get('IMIO_HOME') +if IMIO_HOME is not None: + sys.path.append(IMIO_HOME) +''' +import constants as const + + +class SpeechHelper(object): + def __init__(self, lang='zh-CN', gender='female'): + self.__lang = lang + self.__gender = gender + self.__apiKey = const.COG_STT_TTS_KEY + self.__req_body = ElementTree.Element('speak', version='1.0') + self.__req_body.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice = ElementTree.SubElement(self.__req_body, 'voice') + self.__voice.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice.set('{http://www.w3.org/XML/1998/namespace}gender', gender) + self.__voice.set('name', 'Microsoft Server Speech Text to Speech Voice ' + self.__init_voice_font()) + #for e in self.__voice: + # print(type(e)) + # print(e) + self.__accesstoken = self.__init_access_token() + + def __init_access_token(self): + params = "" + get_token_headers = {"Ocp-Apim-Subscription-Key": self.__apiKey} + # AccessTokenUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; + AccessTokenHost = "api.cognitive.microsoft.com" + path = "/sts/v1.0/issueToken" + # Connect to server to get the Access Token + conn = httpclient.HTTPConnection(AccessTokenHost) + conn.request("POST", path, params, get_token_headers) + response = conn.getresponse() + # print(response.status, response.reason) + data = response.read() + conn.close() + return data.decode("UTF-8") + + def __init_voice_font(self): + if self.__lang == 'zh-CN': + if self.__gender == 'female': + voicefont = '(zh-CN, Yaoyao, Apollo)' + else: + voicefont = '(zh-CN, Kangkang, Apollo)' + elif self.__lang == 'en-GB': + if self.__gender == 'female': + voicefont = '(en-GB, Susan, Apollo)' + else: + voicefont = '(en-GB, George, Apollo)' + elif self.__lang == 'es-ES': + if self.__gender == 'female': + voicefont = '(es-ES, Laura, Apollo)' + else: + voicefont = '(es-ES, Pablo, Apollo)' + elif self.__lang == 'en-IN': + voicefont = '(en-IN, Ravi, Apollo)' + else: + # default as US english + if self.__gender == 'female': + voicefont = '(en-US, ZiraRUS)' + else: + voicefont = '(en-US, BenjaminRUS)' + #voicefont = '(en-US, Eminem)' + return voicefont + + def text_to_speech(self, text_in, play=False): + """ + Convert input text to speech audio and play on microphone + :param text_in: + :return: + """ + if text_in is None: + return None + if sys.version.startswith('2'): + if not isinstance(text_in, unicode): + self.__voice.text = unicode(text_in, 'utf-8') + else: + self.__voice.text = text_in + else: + self.__voice.text = text_in + headers = {"Content-type": "application/ssml+xml", + "X-Microsoft-OutputFormat": "riff-16khz-16bit-mono-pcm", + "Authorization": "Bearer " + self.__accesstoken, + "X-Search-AppId": "07D3234E49CE426DAA29772419F436CA", + "X-Search-ClientID": "1ECFAE91408841A480F00935DC390960", + "User-Agent": "TTSForPython"} + # Connect to server to synthesize the wave + conn = httpclient.HTTPConnection("speech.platform.bing.com") + conn.request("POST", "/synthesize", ElementTree.tostring(self.__req_body), headers) + response = conn.getresponse() + data = response.read() + conn.close() + #print('stream is:') + #print(data) + + if play: + import pyaudio + #print('Playing speech') + p = pyaudio.PyAudio() + stream = p.open(format=pyaudio.paInt16, + channels=1, + rate=16000, + output=True, + frames_per_buffer=1024) + stream.write(data) + wfname = "test.wav" + wf = wave.open(wfname, 'wb') + wf.setnchannels(1) + wf.setsampwidth(p.get_sample_size(pyaudio.paInt16)) + wf.setframerate(16000) + wf.writeframes(stream) + wf.close() + stream.close() + #os.system('aplay /root/test.wav') + os.system('ls') + + return data + + def speech_to_text(self, wf): + """ + Convert the speech audio data to text + :param wf: wave file name, or the actual stream data from a wave file + :return: False if MS Cognitive serice returns error, otherwise the resulted texts will be returned + """ + texts = [] + my_uuid = uuid.uuid4() + headers = { + 'Content-type': 'audio/wav', + # 'Content-type': 'application/octet-stream', + 'samplerate': 16000, + 'Authorization': self.__accesstoken, + # 'codec': "audio/pcm", + } + params = urllibparse.urlencode({ + 'version': '3.0', + 'requestid': my_uuid, + 'appid': const.APP_ID, + 'format': 'json', + 'locale': self.__lang, + 'device.os': 'ubuntu', + 'scenarios': 'smd', + 'instanceid': my_uuid + }) + print(type(wf)) + if isinstance(wf, str): + body = open(wf, 'rb').read() + elif isinstance(wf, bytes): + body = wf + else: + return ''.join(texts) + conn = httpclient.HTTPConnection('speech.platform.bing.com') + conn.request('POST', '/recognize?%s' % params, body, headers) + response = conn.getresponse() + print(response) + data = json.loads(response.read().decode('utf-8')) + result = data['header']['status'] + if result != 'success': + print('INSIDE: STT failed') + return None + else: + outputs = data['results'] + for opt in outputs: + if float(opt['confidence']) > 0.65: + texts.append(opt['name']) + return ''.join(texts) + + +def main(): + #wf_name = 'temp.wav' + spch = SpeechHelper(lang='en-US', gender='male') + + text = 'Look, if you had one shot, one opportunity' + spch.text_to_speech(text, True) + text = 'To seize everything you ever wanted…One moment' + spch.text_to_speech(text, True) + text = 'Would you capture it or just let it slip?' + spch.text_to_speech(text, True) + text = 'His palms are sweaty, knees weak, arms are heavy' + spch.text_to_speech(text, True) + text = 'There\'s vomit on his sweater already, mom\'s spaghetti' + spch.text_to_speech(text, True) + text = 'He\'s nervous, but on the surface he looks calm and ready' + spch.text_to_speech(text, True) + #res_text = spch.speech_to_text(wf_name) + #print(res_text) + #os.remove(wf_name) + + + ''' + stream.start_stream() + while stream.is_active(): + sleep(0.1) + stream.stop_stream() + stream.close() + p.terminate() + ''' + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/demo/TrioAIHelper.py b/mt7688-alsa/demo/TrioAIHelper.py new file mode 100755 index 00000000..beb11e99 --- /dev/null +++ b/mt7688-alsa/demo/TrioAIHelper.py @@ -0,0 +1,185 @@ +import sys +import json +import traceback +import paho.mqtt.client as mqtt +from time import sleep + +try: + import http.client as httplib + import urllib.parse as urlparse +except: + import httplib + import urllib as urlparse + +from SpeechHelper import SpeechHelper + + +class TrioAIAgent(object): + def __init__(self, profile, lang='en-US', rob_gender='female'): + self.__profile = profile + self.__lang = lang + self.__gender = rob_gender + self.__uid = profile['UserId'] + self.__vid = profile['VisitorId'] + self.__ownership = profile['VisitorType'] + self.__chat_host = 'sandbox.sanjiaoshou.net' + self.__chat_url = 'http://sandbox.sanjiaoshou.net/Api/chat?who=demo&userID=imio_111&%s' + self.__cmd_lock_url = 'http://service.sanjiaoshou.net/Locker/index.php?f=locker' + self.__cmd_host = 'service.sanjiaoshou.net' + self.__headers = {'Content-Type': 'application/json',} + self.__session_start = False + return + + def set_userid(self, uid): + self.__uid = uid + + def set_visitor_id(self, vid): + self.__vid = vid + + def set_ownership(self, ownership): + self.__ownership = ownership + + def welcome(self): + entry_msg = self.front_door_text_conv(play=True) + if entry_msg is None: + return None + lock_state = entry_msg[0] + welcome_msg = entry_msg[1] + #print('lock state: ' + lock_state) + #print(welcome_msg) + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + stream = spch.text_to_speech(welcome_msg) + return stream + + def chat(self, query): + params = urlparse.urlencode({'sentence': query.encode('utf-8')}) + try: + url = self.__chat_url % params + conn = httplib.HTTPConnection(self.__chat_host) + conn.request("GET", url) + response = conn.getresponse().read() + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + print(data) + conn.close() + return data['reply'] + except Exception as e: + print(e) + return None + + def front_door_text_conv(self, query=None, play=False): + params = self.__profile + if query is not None: + params.update(query) + body = json.dumps(params) + try: + url = self.__cmd_lock_url + conn = httplib.HTTPConnection(self.__cmd_host) + conn.request(method="POST", url=url, body=body, headers=self.__headers) + response = conn.getresponse().read() + print(response) + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + conn.close() + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + spch.text_to_speech(text_in=data['reply'], play=play) + return data['lockStatus'], data['reply'] + except Exception as e: + traceback.print_exc() + print(e) + return None + + +class FrontDoorScene(object): + def __init__(self, lang='en-US', rob_gender='female'): + self.__QoS = 2 + self.__lang = lang + self.__gender = rob_gender + self.__TOPIC = 'visitor_profile' + self.__cli = mqtt.Client() + self.__cli.on_connect = self.__connect_cb + self.__cli.on_message = self.__message_cb + self.__session_start = False + + def __connect_cb(self, client, userdata, flags, rc): + self.__cli.subscribe(self.__TOPIC, self.__QoS) + return + + def __message_cb(self, client, data, msg): + if msg.topic == self.__TOPIC: + print('Incoming message!') + payload = msg.payload + print(type(payload)) + raw_msg = payload.decode('utf-8') + print(type(raw_msg)) + print(raw_msg) + profile = json.loads(raw_msg) + print(profile) + if not self.__session_start: + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + return + + def is_session_started(self): + return self.__session_start + + def session_end(self): + self.__session_start = False + + def start(self, blocking=False, profile=None): + ''' + self.__cli.connect(host='mq.imio.io', port=1883) + if blocking: + self.__cli.loop_forever() + else: + self.__cli.loop_start() + ''' + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + + + def stt(self, wf): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.speech_to_text(wf) + + def tts(self, text, play=False): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.text_to_speech(text_in=text, play=play) + + def ask_and_answer(self, query): + ans = self.__trio_ai.front_door_text_conv(query=query) + if ans is not None: + reply = ans[1] + print(reply) + return reply + else: + return None + + +def main(): + my_profile = {"UserId":"10003","VisitorId":"Jim","VisitorType":"host"} + visit = FrontDoorScene(lang='en-GB', rob_gender='male') + visit.start() + sleep(0.5) + while True: + if visit.is_session_started(): + ring_bell = {'BellRingFlag': True} + visit.tts(visit.ask_and_answer(ring_bell), True) + sleep(0.5) + #wf = open('temp.wav', 'rb') + #spt = visit.stt('temp.wav') + #open_door = {'Text': spt} + open_door = {'Text': 'Yes, I forgot my password'} + visit.tts(visit.ask_and_answer(open_door), True) + sleep(0.5) + unclocked = {"PasswdValidFlag": True} + visit.tts(visit.ask_and_answer(unclocked), True) + visit.session_end() + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/demo/__pycache__/SpeechHelper.cpython-35.pyc b/mt7688-alsa/demo/__pycache__/SpeechHelper.cpython-35.pyc new file mode 100644 index 00000000..fad3653c Binary files /dev/null and b/mt7688-alsa/demo/__pycache__/SpeechHelper.cpython-35.pyc differ diff --git a/mt7688-alsa/demo/__pycache__/constants.cpython-35.pyc b/mt7688-alsa/demo/__pycache__/constants.cpython-35.pyc new file mode 100644 index 00000000..b4def10e Binary files /dev/null and b/mt7688-alsa/demo/__pycache__/constants.cpython-35.pyc differ diff --git a/mt7688-alsa/demo/constants.py b/mt7688-alsa/demo/constants.py new file mode 100755 index 00000000..c8ed8527 --- /dev/null +++ b/mt7688-alsa/demo/constants.py @@ -0,0 +1,8 @@ +APP_ID = '950f8ca2-1b6e-41b3-a90c-c7775997603e' +APP_PWD = 'EWwjGB3hU47BfrqcGfYEKfC' + +MS_COG_HOST = 'westus.api.cognitive.microsoft.com' +COG_FACE_KEY = '0b1e119d7493471fa878f61214c31676' +COG_FACE_KEY_SEC = '5296e25a60b847239404c13e5b905a0a' +COG_SPEEKER_KEY = 'f4573d5f3a69422c828ac6f05bb1b687' +COG_STT_TTS_KEY = '50a64ed5fc0e4e4a999887c43fae9428' diff --git a/mt7688-alsa/demo/getContext.py b/mt7688-alsa/demo/getContext.py new file mode 100755 index 00000000..66681c72 --- /dev/null +++ b/mt7688-alsa/demo/getContext.py @@ -0,0 +1,72 @@ + +import requests +import json +import urllib + + +def getSentence(name,language): + print ("Python to connect imio.ai ") + print (name + language) + + if language: + reg_str = "http://www.imio.ai/ai-bot/stt?lang=zh-CN" #port + else: + reg_str = "http://www.imio.ai/ai-bot/stt?lang=en-US" #port + + body = open(name, 'r').read() + #print(body) + #params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN + headers ={'Content-type': 'audio/wav','samplerate': '16000'} + add_res = requests.post(reg_str, data = body, headers = headers) + #print(add_res.url) + print (add_res.text) + + res_str = json.loads(add_res.text)['data']['msg'][0] + print (res_str.encode('utf-8')) + #return str(res_str) + +''' +import requests +import json +import urllib + +print ("Python to connect imio.ai ") +reg_str = "http://www.imio.ai/ai-bot/stt?lang=zh-CN" #port +body = open("test.wav", 'r').read() +#print(body) +#params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN +headers ={'Content-type': 'audio/wav','samplerate': '16000'} +add_res = requests.post(reg_str, data = body, headers = headers) +#print(add_res.url) +print (add_res.text) +res_str = json.loads(add_res.text)['data']['msg'][0] +print(res_str.encode('utf-8')) +''' +''' +import requests +import json +import urllib + +def getSentence(name, language): + print ("Python to connect imio.ai ") + #params = urllibparse.urlencode({"lang":"zh-CN", "uid":"10001", "visitorid":"Tom", "ownership":"host", "ring":False}) + if language: + reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=zh-CN&uid=10001&visitorid=Tom&ownership=host&ring=False" #port + else: + reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=en-US&uid=10001&visitorid=Tom&ownership=host&ring=False" #port + + body = open(name, 'r').read() + #print(body) + #params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN + headers = {'Content-type': 'audio/wav','samplerate': '16000'} + add_res = requests.post(reg_str, data = body, headers = headers) + #print(add_res.url) + print (add_res.text) + + res_str = json.loads(add_res.text)['data']['msg'][0] + print(res_str.encode('utf-8')) + return res_str.encode('utf-8') +''' + + + diff --git a/mt7688-alsa/demo/getContext.pyc b/mt7688-alsa/demo/getContext.pyc new file mode 100755 index 00000000..59529772 Binary files /dev/null and b/mt7688-alsa/demo/getContext.pyc differ diff --git a/mt7688-alsa/demo/mips-python.txt b/mt7688-alsa/demo/mips-python.txt new file mode 100755 index 00000000..00dd6ed2 --- /dev/null +++ b/mt7688-alsa/demo/mips-python.txt @@ -0,0 +1,30 @@ +CC=mipsel-openwrt-linux-gcc CXX=mipsel-openwrt-linux-g++ AR=mipsel-openwrt-linux-ar RANLIB=mipsel-openwrt-linux-ranlib ./configure --host=mips-mt7688-linux-gnueabi --build=x86_64 --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=yes --enable-shared --prefix=/home/zyc/Documents/Python-2.7.12/python-mips/ +CC=mipsel-openwrt-linux-gcc CXX=mipsel-openwrt-linux-g++ AR=mipsel-openwrt-linux-ar RANLIB=mipsel-openwrt-linux-ranlib ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/python make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="mipsel-openwrt-linux-gcc -shared" CROSS_COMPILE=mipsel-openwrt-linux- CROSS_COMPILE_TARGET=yes + +make HOSTPYTHON=./python_for_build HOSTPGEN=./Parser/pgen_for_build BLDSHARED="mipsel-openwrt-linux-gcc -shared" CROSS_COMPILE=mipsel-openwrt-linux- CROSS_COMPILE_TARGET=yes HOSTARCH=mips-mt7688-linux-gnueabi BUILDARCH=x86_64 + +PYTHON_CONFIGURE_OPTS="--enable-shared" + +make install HOSTPYTHON=./python_for_build BLDSHARED="mipsel-openwrt-linux-gcc -shared" CROSS_COMPILE=mipsel-openwrt-linux- CROSS_COMPILE_TARGET=yes prefix=/home/zyc/Documents/Python-2.7.12/python-mips/ +make install HOSTPYTHON=./hostpython BLDSHARED="mipsel-openwrt-linux-gcc -shared" CROSS_COMPILE=mipsel-openwrt-linux- CROSS_COMPILE_TARGET=yes prefix=/home/zyc/Documents/Python-2.7.3/install + + +mipsel-openwrt-linux-gcc -o test-mips test.c -L /home/zyc/Documents/Python-2.7.3/python-mips/lib -lpython2.7 -I /home/zyc/Documents/Python-2.7.3/python-mips/include/python2.7 + + +./configure --prefix=/home/zyc/Documents/Python-2.7.3/python-mips --host=mips-Linux-gnu "CC=mipsel-openwrt-linux-gcc -EL" "CFLAGS=-EL" "LDFLAGS=-EL" --enable-shared --disable-ipv6 --with-libc="-L/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib -lc" "LIBS=-L/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/lib" + + + +./configure --prefix=/home/zyc/Documents/Python-2.7.12/python_install --host=mipsel-openwrt-linux "CC=mipsel-openwrt-linux-gcc -EL" "CFLAGS=-EL" "LDFLAGS=-EL" --enable-shared --disable-readline --disable-dynamic-extensions +./configure --prefix=/home/zyc/Documents/Python-2.7.12/python_install --host=mipsel-openwrt-linux --build=x86_64 --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=yes + +./configure \ +CC=/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc \ +CXX=/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-g++ \ +STRIP=/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-strip \ +AR=/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-ar \ +RANLIB=/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-ranlib \ +ac_cv_file__dev_ptmx=yes \ +ac_cv_file__dev_ptc=no \ +./configure --build=x86_64 --host=mips --prefix=/home/zyc/Documents/Python-2.7.12/python_install \ No newline at end of file diff --git a/mt7688-alsa/demo/test b/mt7688-alsa/demo/test new file mode 100755 index 00000000..93479535 Binary files /dev/null and b/mt7688-alsa/demo/test differ diff --git a/mt7688-alsa/demo/test-c.c b/mt7688-alsa/demo/test-c.c new file mode 100755 index 00000000..0ff07358 --- /dev/null +++ b/mt7688-alsa/demo/test-c.c @@ -0,0 +1,69 @@ +/* + * test.cpp + * Created on: 2010-8-12 + * Author: lihaibo + */ +#include "/usr/include/python2.7/Python.h" +//#include "/home/zyc/Documents/Python-2.7.3/python-mips/include/python2.7/Python.h" +#include +#include + +void printDict(PyObject* obj) { + if (!PyDict_Check(obj)) + return; + PyObject *k, *keys; + keys = PyDict_Keys(obj); + int i; + for (i = 0; i < PyList_GET_SIZE(keys); i++) { + k = PyList_GET_ITEM(keys, i); + char* c_name = PyString_AsString(k); + printf("%s\n", c_name); + } +} + +int main() +{ + Py_Initialize(); + if (!Py_IsInitialized()) + return -1; + PyRun_SimpleString("import sys"); + PyRun_SimpleString("print 'Enter python: '"); + PyRun_SimpleString("sys.path.append('./')"); + //ģ + PyObject* pModule = NULL; + pModule = PyImport_ImportModule("getContext"); + if (!pModule) { + printf("Cant open python file!\n"); + return -1; + } + PyObject * pFunc = NULL; + pFunc = PyObject_GetAttrString(pModule,"getSentence"); + PyObject *pArgs = PyTuple_New(2); + PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", "test.wav")); + PyTuple_SetItem(pArgs, 1, Py_BuildValue("s", "1")); + PyObject *pReturn = NULL; + pReturn = PyEval_CallObject(pFunc, pArgs); + //char* result; + //PyArg_Parse(pReturn, "s", &result); + //printf("%s\n", result); +/* + //ģֵб + PyObject* pDict = PyModule_GetDict(pModule); + if (!pDict) { + printf("Cant find dictionary.\n"); + return -1; + } + //ӡһ + printDict(pDict); + //ʾ + + + PyObject* pFunHi = PyDict_GetItemString(pDict, "getSentence"); + PyObject_CallFunction(pFunHi, "test.wav"); + Py_DECREF(pFunHi); +*/ + Py_DECREF(pModule); + Py_Finalize(); + + return 0; +} diff --git a/mt7688-alsa/demo/test-gnu-c.c b/mt7688-alsa/demo/test-gnu-c.c new file mode 100755 index 00000000..2b77f948 --- /dev/null +++ b/mt7688-alsa/demo/test-gnu-c.c @@ -0,0 +1,82 @@ +/* + * test.cpp + * Created on: 2010-8-12 + * Author: lihaibo + */ +#include "/usr/include/python2.7/Python.h" +//#include "/home/zyc/Documents/Python-2.7.3/python-mips/include/python2.7/Python.h" +#include +#include + +void printDict(PyObject* obj) { + if (!PyDict_Check(obj)) + return; + PyObject *k, *keys; + keys = PyDict_Keys(obj); + int i; + for (i = 0; i < PyList_GET_SIZE(keys); i++) { + k = PyList_GET_ITEM(keys, i); + char* c_name = PyString_AsString(k); + printf("%s\n", c_name); + } +} +int main() { + Py_Initialize(); + if (!Py_IsInitialized()) + return -1; + PyRun_SimpleString("import sys"); + PyRun_SimpleString("sys.path.append('./')"); + //ģ + PyObject* pModule = PyImport_ImportModule("testpy"); + if (!pModule) { + printf("Cant open python file!\n"); + return -1; + } + //ģֵб + PyObject* pDict = PyModule_GetDict(pModule); + if (!pDict) { + printf("Cant find dictionary.\n"); + return -1; + } + //ӡһ + printDict(pDict); + //ʾ + PyObject* pFunHi = PyDict_GetItemString(pDict, "sayhi"); + PyObject_CallFunction(pFunHi, "lhb"); + Py_DECREF(pFunHi); + //ʾһPython󣬲Classķ + //ȡSecond + PyObject* pClassSecond = PyDict_GetItemString(pDict, "Second"); + if (!pClassSecond) { + printf("Cant find second class.\n"); + return -1; + } + //ȡPerson + PyObject* pClassPerson = PyDict_GetItemString(pDict, "Person"); + if (!pClassPerson) { + printf("Cant find person class.\n"); + return -1; + } + //Secondʵ + PyObject* pInstanceSecond = PyInstance_New(pClassSecond, NULL, NULL); + if (!pInstanceSecond) { + printf("Cant create second instance.\n"); + return -1; + } + //Personʵ + PyObject* pInstancePerson = PyInstance_New(pClassPerson, NULL, NULL); + if (!pInstancePerson) { + printf("Cant find person instance.\n"); + return -1; + } + //personʵsecondinvoke + PyObject_CallMethod(pInstanceSecond, "invoke", "O", pInstancePerson); + //ͷ + Py_DECREF(pInstanceSecond); + Py_DECREF(pInstancePerson); + Py_DECREF(pClassSecond); + Py_DECREF(pClassPerson); + Py_DECREF(pModule); + Py_Finalize(); + return 0; +} diff --git a/mt7688-alsa/demo/test-mips-c.c b/mt7688-alsa/demo/test-mips-c.c new file mode 100755 index 00000000..4cd20a22 --- /dev/null +++ b/mt7688-alsa/demo/test-mips-c.c @@ -0,0 +1,82 @@ +/* + * test.cpp + * Created on: 2010-8-12 + * Author: lihaibo + */ +//#include "/usr/include/python2.7/Python.h" +#include "/home/zyc/Documents/Python-2.7.12/python-mips/include/python2.7/Python.h" +#include +#include + +void printDict(PyObject* obj) { + if (!PyDict_Check(obj)) + return; + PyObject *k, *keys; + keys = PyDict_Keys(obj); + int i; + for (i = 0; i < PyList_GET_SIZE(keys); i++) { + k = PyList_GET_ITEM(keys, i); + char* c_name = PyString_AsString(k); + printf("%s\n", c_name); + } +} +int main() { + Py_Initialize(); + if (!Py_IsInitialized()) + return -1; + PyRun_SimpleString("import sys"); + PyRun_SimpleString("sys.path.append('./')"); + //ģ + PyObject* pModule = PyImport_ImportModule("testpy"); + if (!pModule) { + printf("Cant open python file!\n"); + return -1; + } + //ģֵб + PyObject* pDict = PyModule_GetDict(pModule); + if (!pDict) { + printf("Cant find dictionary.\n"); + return -1; + } + //ӡһ + printDict(pDict); + //ʾ + PyObject* pFunHi = PyDict_GetItemString(pDict, "sayhi"); + PyObject_CallFunction(pFunHi, "s", "lhb"); + Py_DECREF(pFunHi); + //ʾһPython󣬲Classķ + //ȡSecond + PyObject* pClassSecond = PyDict_GetItemString(pDict, "Second"); + if (!pClassSecond) { + printf("Cant find second class.\n"); + return -1; + } + //ȡPerson + PyObject* pClassPerson = PyDict_GetItemString(pDict, "Person"); + if (!pClassPerson) { + printf("Cant find person class.\n"); + return -1; + } + //Secondʵ + PyObject* pInstanceSecond = PyInstance_New(pClassSecond, NULL, NULL); + if (!pInstanceSecond) { + printf("Cant create second instance.\n"); + return -1; + } + //Personʵ + PyObject* pInstancePerson = PyInstance_New(pClassPerson, NULL, NULL); + if (!pInstancePerson) { + printf("Cant find person instance.\n"); + return -1; + } + //personʵsecondinvoke + PyObject_CallMethod(pInstanceSecond, "invoke", "O", pInstancePerson); + //ͷ + Py_DECREF(pInstanceSecond); + Py_DECREF(pInstancePerson); + Py_DECREF(pClassSecond); + Py_DECREF(pClassPerson); + Py_DECREF(pModule); + Py_Finalize(); + return 0; +} diff --git a/mt7688-alsa/demo/test-tcp.py b/mt7688-alsa/demo/test-tcp.py new file mode 100755 index 00000000..f743d023 --- /dev/null +++ b/mt7688-alsa/demo/test-tcp.py @@ -0,0 +1,67 @@ +''' +import requests +import json +import urllib + +reg_str = "http://www.imio.ai/ai-bot/stt?lang=zh-CN" #port + +#signup_req +body = open("test.wav", 'r').read() +#print(body) +#params = urllibparse.urlencode({'lang':'en-US'}) +#params = urllibparse.urlencode({'lang':'zh-CN'}) +headers ={'Content-type': 'audio/wav','samplerate': '16000'} +add_res = requests.post(reg_str, data = body, headers = headers) + +print(add_res.url) +print (add_res.text) + +res_str = json.loads(add_res.text)['data']['msg'][0] +print(res_str.encode('utf-8')) +''' + +#import requests +import json +import urllib +import pyaudio + +headers = {'Content-type': 'audio/wav','samplerate': '16000'} +params = urllibparse.urlencode({"lang":"zh-CN", "uid":"10001", "visitorid":"Tom", "ownership":"host", "ring":True}) +body = open("test.wav", 'r').read() +conn = httpclient.HTTPConnection('www.imio.ai') +conn.request('POST', '/ai-bot/audio_chat?%s' % params, body, headers) + +data = json.load(conn.getresponse().read())['data']['msg'] + +p = pyaudio.PyAudio() +stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, output=True, frames_per_buffer=1024) +stream.write(data) +stream.close() + +''' +print ("Python to connect imio.ai ") +#params = urllibparse.urlencode({"lang":"zh-CN", "uid":"10001", "visitorid":"Tom", "ownership":"host", "ring":False}) +reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=zh-CN&uid=10001&visitorid=Tom&ownership=host&ring=True" #port True +#reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=en-US&uid=10001&visitorid=Tom&ownership=host&ring=False" #port + +body = open("test.wav", 'r').read() +#print(body) +#params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN +headers = {'Content-type': 'audio/wav','samplerate': '16000'} +add_res = requests.post(reg_str, data = body, headers = headers) +print (type(add_res)) +print(add_res.url) +print (add_res.text) + +# data = json.loads(add_res)['data']['msg'] +# p = pyaudio.PyAudio() +# stream = p.open(format=pyaudio.paInt16, + # channels=1, + # rate=16000, + # output=True, + # frames_per_buffer=1024) +# stream.write(data) +# stream.close() +''' + + diff --git a/mt7688-alsa/demo/test.wav b/mt7688-alsa/demo/test.wav new file mode 100755 index 00000000..557f7951 Binary files /dev/null and b/mt7688-alsa/demo/test.wav differ diff --git a/mt7688-alsa/demo/testC_Python.c b/mt7688-alsa/demo/testC_Python.c new file mode 100755 index 00000000..90b85ea8 --- /dev/null +++ b/mt7688-alsa/demo/testC_Python.c @@ -0,0 +1,66 @@ +#include +#include +//#include +#include + +int main(int argc, char *argv[]) +{ + //In order to use Python in C file, must to use Py_Initalize to initalize it. + char *string; + PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pRetVal; + + Py_Initialize(); + if (!Py_IsInitialized()) + { + return -1; + printf("Py_Initialize() failed\n"); + } + + // load the name by getContext scripts(Note: not use getContext.py) + pName = PyString_FromString("getContext"); + pModule = PyImport_Import(pName); + if (!pModule) + { + printf("can't find getContext.py"); + getchar(); + return -1; + } + pDict = PyModule_GetDict(pModule); + if (!pDict) + { + return -1; + } + + // find the function named getSentence() + pFunc = PyDict_GetItemString(pDict, "getSentence"); + if (!pFunc || !PyCallable_Check(pFunc)) + { + printf("can't find function [getSentence]"); + getchar(); + return -1; + } + + // ջ + pArgs = PyTuple_New(2); + // PyObject* Py_BuildValue(char *format, ...) + // s string + // i int + // f float + // O Python object b=f(a) 0.1-0.01=0.09 + PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", "test.wav")); + PyTuple_SetItem(pArgs, 1, Py_BuildValue("i",1)); + + // Python + pRetVal = PyObject_CallObject(pFunc, pArgs); + printf("function return value : %ld\r\n", PyInt_AsLong(pRetVal)); + + Py_DECREF(pName); + Py_DECREF(pArgs); + Py_DECREF(pModule); + Py_DECREF(pRetVal); + + // close Python + Py_Finalize(); + + return 0; +} diff --git a/mt7688-alsa/demo/testpy.py b/mt7688-alsa/demo/testpy.py new file mode 100755 index 00000000..5305e507 --- /dev/null +++ b/mt7688-alsa/demo/testpy.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +# Filename: test.py +class Person: + def sayHi(self): + print 'hi' +class Second: + def invoke(self,obj): + obj.sayHi() +def sayhi(name): + print 'hi'+name; + diff --git a/mt7688-alsa/demo/testpy.pyc b/mt7688-alsa/demo/testpy.pyc new file mode 100755 index 00000000..4bcac65f Binary files /dev/null and b/mt7688-alsa/demo/testpy.pyc differ diff --git a/mt7688-alsa/getContext.py b/mt7688-alsa/getContext.py new file mode 100755 index 00000000..31a4afe8 --- /dev/null +++ b/mt7688-alsa/getContext.py @@ -0,0 +1,71 @@ + +import requests +import json +import urllib + +def getSentences(name, language): + print ("Python to connect imio.ai ") + + if language: + reg_str = "http://www.imio.ai/ai-bot/stt?lang=zh-CN" #port + else: + reg_str = "http://www.imio.ai/ai-bot/stt?lang=en-US" #port + + body = open(name, 'r').read() + #print(body) + #params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN + headers ={'Content-type': 'audio/wav','samplerate': '16000'} + add_res = requests.post(reg_str, data = body, headers = headers) + #print(add_res.url) + print (add_res.text) + + res_str = json.loads(add_res.text)['data']['msg'][0] + print(res_str) + #print(res_str.encode('utf-8')) + #return res_str.encode('utf-8') + +''' +import requests +import json +import urllib + +print ("Python to connect imio.ai ") +reg_str = "http://www.imio.ai/ai-bot/stt?lang=zh-CN" #port +body = open("test.wav", 'r').read() +#print(body) +#params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN +headers ={'Content-type': 'audio/wav','samplerate': '16000'} +add_res = requests.post(reg_str, data = body, headers = headers) +#print(add_res.url) +print (add_res.text) +res_str = json.loads(add_res.text)['data']['msg'][0] +print(res_str.encode('utf-8')) +''' +''' +import requests +import json +import urllib + +def getSentence(name, language): + print ("Python to connect imio.ai ") + #params = urllibparse.urlencode({"lang":"zh-CN", "uid":"10001", "visitorid":"Tom", "ownership":"host", "ring":False}) + if language: + reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=zh-CN&uid=10001&visitorid=Tom&ownership=host&ring=False" #port + else: + reg_str = "http://www.imio.ai/ai-bot/audio_chat?lang=en-US&uid=10001&visitorid=Tom&ownership=host&ring=False" #port + + body = open(name, 'r').read() + #print(body) + #params = urllibparse.urlencode({'lang':'en-US'}) #zh-CN + headers = {'Content-type': 'audio/wav','samplerate': '16000'} + add_res = requests.post(reg_str, data = body, headers = headers) + #print(add_res.url) + print (add_res.text) + + res_str = json.loads(add_res.text)['data']['msg'][0] + print(res_str.encode('utf-8')) + return res_str.encode('utf-8') +''' + + + diff --git a/mt7688-alsa/key.c b/mt7688-alsa/key.c new file mode 100755 index 00000000..80e46ea0 --- /dev/null +++ b/mt7688-alsa/key.c @@ -0,0 +1,39 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include "mem_gpio.h" +#include "key.h" + + +//init GPIO port +void init_button_gpio() +{ + if (gpio_mmap()) + printf("gpio_mmap() error!\n"); + + //printf("set pin BUTTON input 0\n"); + //mt76x8_gpio_set_pin_direction(BUTTON, 1); + //mt76x8_gpio_set_pin_value(BUTTON, 0); + + mt76x8_gpio_set_pin_direction(BUTTON, 0); + printf("get pin BUTTON input %d\n", mt76x8_gpio_get_pin(BUTTON)); +} + +int read_button() +{ + if (0 == mt76x8_gpio_get_pin(BUTTON)) + { + return 0; + } + else if (1 == mt76x8_gpio_get_pin(BUTTON)) + { + return 1; + } + //close(gpio_mmap_fd); + + return 0; +} + diff --git a/mt7688-alsa/key.h b/mt7688-alsa/key.h new file mode 100755 index 00000000..d35d7e7c --- /dev/null +++ b/mt7688-alsa/key.h @@ -0,0 +1,16 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _KEY_H_ +#define _KEY_H_ + + +#define BUTTON 40 + + +void init_button_gpio(); +int read_button(); + +#endif diff --git a/mt7688-alsa/key.o b/mt7688-alsa/key.o new file mode 100755 index 00000000..0d664034 Binary files /dev/null and b/mt7688-alsa/key.o differ diff --git a/mt7688-alsa/libasound.so b/mt7688-alsa/libasound.so new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/libasound.so differ diff --git a/mt7688-alsa/libasound.so.2 b/mt7688-alsa/libasound.so.2 new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/libasound.so.2 differ diff --git a/mt7688-alsa/libasound.so.2.0.0 b/mt7688-alsa/libasound.so.2.0.0 new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/libasound.so.2.0.0 differ diff --git a/mt7688-alsa/libmp3lame.so b/mt7688-alsa/libmp3lame.so new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/libmp3lame.so differ diff --git a/mt7688-alsa/libmp3lame.so.0 b/mt7688-alsa/libmp3lame.so.0 new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/libmp3lame.so.0 differ diff --git a/mt7688-alsa/libmp3lame.so.0.0.0 b/mt7688-alsa/libmp3lame.so.0.0.0 new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/libmp3lame.so.0.0.0 differ diff --git a/mt7688-alsa/libshine.so b/mt7688-alsa/libshine.so new file mode 100755 index 00000000..8715ac8d Binary files /dev/null and b/mt7688-alsa/libshine.so differ diff --git a/mt7688-alsa/libshine.so.3 b/mt7688-alsa/libshine.so.3 new file mode 100755 index 00000000..8715ac8d Binary files /dev/null and b/mt7688-alsa/libshine.so.3 differ diff --git a/mt7688-alsa/libshine.so.3.0.1 b/mt7688-alsa/libshine.so.3.0.1 new file mode 100755 index 00000000..8715ac8d Binary files /dev/null and b/mt7688-alsa/libshine.so.3.0.1 differ diff --git a/mt7688-alsa/main b/mt7688-alsa/main new file mode 100755 index 00000000..bd821a8a Binary files /dev/null and b/mt7688-alsa/main differ diff --git a/mt7688-alsa/main.c b/mt7688-alsa/main.c new file mode 100755 index 00000000..f9413973 --- /dev/null +++ b/mt7688-alsa/main.c @@ -0,0 +1,249 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include +#include +#include "mem_gpio.h" +#include "key.h" +#include "oled_iic.h" +#include "record.h" +#include "cJSON.h" +#include "call_python.h" + + +//extern oled_iic.c variable +extern unsigned char BMP1[]; +extern unsigned char BMP2[]; +extern unsigned char BMP3[]; +extern unsigned char BMP4[]; + +int scan_button = 1; +int key_num = 1; + +/*************************************************************** +* test c +***************************************************************/ +void test_button() +{ + init_button_gpio(); + + while (1) + { + if (0 == read_button()) + { + printf("Button not push ! \n"); + } + if (1 == read_button()) + { + printf("Button push! \n"); + } + sleep(2); + } + + close_gpio(); +} + +void test_oled() +{ + unsigned char i; + + init_gpio(); + OLED_Init(); //OLED init + + // OLED_Fill(0xff); // + // sleep(5); + // OLED_Fill(0x00); // + // sleep(5); + + while (1) + { + printf("Begin! \n"); + OLED_P16x16Ch(24,0,1); + OLED_P16x16Ch(40,0,2); + OLED_P16x16Ch(57,0,3); + OLED_P16x16Ch(74,0,4); + OLED_P16x16Ch(91,0,5); + for(i=0; i<8; i++)// + { +// OLED_P16x16Ch(i*16,0,i); + OLED_P16x16Ch(i*16,2,i+8); + OLED_P16x16Ch(i*16,4,i+16); + OLED_P16x16Ch(i*16,6,i+24); + } + sleep(4); + OLED_CLS();// + + OLED_P8x16Str(0,0,"HelTec");//delay + OLED_P8x16Str(0,2,"OLED Display"); + OLED_P8x16Str(0,4,"www.heltec.cn"); + OLED_P6x8Str(0,6,"cn.heltec@gmail.com"); + OLED_P6x8Str(0,7,"heltec.taobao.com"); + sleep(4); + OLED_CLS(); + + Draw_BMP(0,0,128,8,BMP1); // + sleep(8); + Draw_BMP(0,0,128,8,BMP2); + sleep(8); + OLED_CLS(); + } + + close_gpio(); +} + +void test_cjson() +{ + char *product_id = "mt7687_a"; + char *dev_id = "zhuyunchun-1a"; + char *dev_key = "b23c34bacedd3548435d92d405a88afb"; + char *out; + + cJSON *root_reg; + cJSON *signup_req; + root_reg = cJSON_CreateObject(); + cJSON_AddItemToObject(root_reg, "signin_req", signup_req = cJSON_CreateObject()); + cJSON_AddStringToObject(signup_req, "product_id", product_id); + cJSON_AddStringToObject(signup_req, "dev_id", dev_id); + cJSON_AddStringToObject(signup_req, "dev_key", dev_key); + out = cJSON_Print(root_reg); /* Print to text */ + cJSON_Delete(root_reg); /* Delete the cJSON object */ + printf("The json date out = %s\n", out); +} + +void display_oled() +{ + unsigned char i; + + OLED_P8x16Str(0,0,"Processing...");//delay + + while (key_num) + { + //printf("Begin! \n"); + for (i = 0; i < 102; i += 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + //OLED_CLS(); + } + for (i = 102; i > 0; i -= 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + //OLED_CLS(); + } + //key_num--; + } + + OLED_CLS(); + key_num = 1; + scan_button = 1; + pthread_exit(0); + //close_gpio(); +} + +void thread_rec() +{ + record_main(); + //sleep(4); //rec + key_num = 0; + printf("thread_rec() finish ! \n"); + + pthread_exit(0); +} + +void thread_key() +{ + pthread_t id_dis, id_rec; + int ret_dis, ret_rec; + + while (1) + { + if(scan_button) + { + if (0 == read_button()) + { + //printf("Button not push ! \n"); + OLED_CLS(); + //sleep(2); + } + else if (1 == read_button()) + { + printf("Button push ! \n"); + scan_button = 0; + ret_dis = pthread_create(&id_dis, NULL, (void *)display_oled, NULL); + if (ret_dis != 0) + { + printf("Create the pthread_dis error!\n"); + } + ret_rec = pthread_create(&id_rec, NULL, (void *)thread_rec, NULL); + if (ret_rec != 0) + { + printf("Create the pthread_rec error!\n"); + } + } + } + //printf("thread_key()\n"); + usleep(20000);//sleep 20ms + } + + pthread_exit(0); +} + +void thread_ai() +{ + int call_ret; + sleep(3); + + //while (1) + //{ + printf("thread_ai()\n"); + call_ret = call_main("getContext", "getSentences", "test.wav", "10"); + printf("call_ret = %d\n", call_ret); + if (call_ret < 0) + { + printf("call python error!\n"); + } + //sleep(30);//sleep 30s + //} + + pthread_exit(0); +} + +/*========================= MAIN ====================================*/ +int main(int argc, char* argv[]) +{ + pthread_t id_key, id_ai; + int ret_key, ret_ai; + + //init func + init_gpio(); + init_button_gpio(); + OLED_Init(); //OLED init + OLED_CLS();// + + ret_ai = pthread_create(&id_ai, NULL, (void *)thread_ai, NULL); + if (ret_ai != 0) + { + printf("Create the pthread_ai error!\n"); + } + + ret_key = pthread_create(&id_key, NULL, (void *)thread_key, NULL); + if (ret_key != 0) + { + printf("Create the pthread_key error!\n"); + } + + while(1) + { + sleep(2); + printf("I am main thread!\n"); + } + + + + return 0; +} diff --git a/mt7688-alsa/main.o b/mt7688-alsa/main.o new file mode 100755 index 00000000..ad9558f7 Binary files /dev/null and b/mt7688-alsa/main.o differ diff --git a/mt7688-alsa/mem_gpio.c b/mt7688-alsa/mem_gpio.c new file mode 100755 index 00000000..a3f4ae62 --- /dev/null +++ b/mt7688-alsa/mem_gpio.c @@ -0,0 +1,157 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include "mem_gpio.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +uint8_t* gpio_mmap_reg = NULL; +int gpio_mmap_fd = 0; + + +/** + * mem remap + * @return + */ +int gpio_mmap(void) +{ + if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) + { + fprintf(stderr, "unable to open mmap file"); + return -1; + } + + gpio_mmap_reg = (uint8_t *) mmap(NULL, 1024, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, gpio_mmap_fd, 0x10000000); + if (gpio_mmap_reg == MAP_FAILED) + { + perror("foo"); + fprintf(stderr, "failed to mmap"); + gpio_mmap_reg = NULL; + close(gpio_mmap_fd); + return -1; + } + + return 0; +} + +/** + * read pin input value + * @param pin + * @return + */ +int mt76x8_gpio_get_pin(int pin) +{ + uint32_t tmp = 0; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODATA); + tmp = (tmp >> pin) & 1u; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DATA); + tmp = (tmp >> (pin-32)) & 1u; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DATA); + tmp = (tmp >> (pin-64)) & 1u; + tmp = (tmp >> (pin-24)) & 1u; + } + return tmp; +} + +/** + * set gpio pin direction + * @param pin number + * @param is_output 1 == output, 0 == input + */ +void mt76x8_gpio_set_pin_direction(int pin, int is_output) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR); + if (is_output) + tmp |= (1u << pin); + else + tmp &= ~(1u << pin); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR) = tmp; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR); + if (is_output) + tmp |= (1u << (pin-32)); + else + tmp &= ~(1u << (pin-32)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR) = tmp; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR); + if (is_output) + tmp |= (1u << (pin-64)); + else + tmp &= ~(1u << (pin-64)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR) = tmp; + } +} + + +/** + * set gpio value + * @param pin gpio number + * @param value value, 1 == high, 0 == low + */ +void mt76x8_gpio_set_pin_value(int pin, int value) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = (1u << pin); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIOSET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIORESET) = tmp; + } + else if (pin <= 63) + { + tmp = (1u << (pin-32)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332RESET) = tmp; + } + else if (pin <= 95) + { + tmp = (1u << (pin-64)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564RESET) = tmp; + } +} + +void close_gpio() +{ + close(gpio_mmap_fd); +} + diff --git a/mt7688-alsa/mem_gpio.h b/mt7688-alsa/mem_gpio.h new file mode 100755 index 00000000..6647345f --- /dev/null +++ b/mt7688-alsa/mem_gpio.h @@ -0,0 +1,57 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _MEM_GPIO_H_ +#define _MEM_GPIO_H_ + + +#define MMAP_PATH "/dev/mem" + +#define RALINK_GPIO_DIR_IN 0 +#define RALINK_GPIO_DIR_OUT 1 + +#define RALINK_REG_PIOINT 0x690 +#define RALINK_REG_PIOEDGE 0x6A0 +#define RALINK_REG_PIORENA 0x650 +#define RALINK_REG_PIOFENA 0x660 +#define RALINK_REG_PIODATA 0x620 +#define RALINK_REG_PIODIR 0x600 +#define RALINK_REG_PIOSET 0x630 +#define RALINK_REG_PIORESET 0x640 + +#define RALINK_REG_PIO6332INT 0x694 +#define RALINK_REG_PIO6332EDGE 0x6A4 +#define RALINK_REG_PIO6332RENA 0x654 +#define RALINK_REG_PIO6332FENA 0x664 +#define RALINK_REG_PIO6332DATA 0x624 +#define RALINK_REG_PIO6332DIR 0x604 +#define RALINK_REG_PIO6332SET 0x634 +#define RALINK_REG_PIO6332RESET 0x644 + +#define RALINK_REG_PIO9564INT 0x698 +#define RALINK_REG_PIO9564EDGE 0x6A8 +#define RALINK_REG_PIO9564RENA 0x658 +#define RALINK_REG_PIO9564FENA 0x668 +#define RALINK_REG_PIO9564DATA 0x628 +#define RALINK_REG_PIO9564DIR 0x608 +#define RALINK_REG_PIO9564SET 0x638 +#define RALINK_REG_PIO9564RESET 0x648 + + +#define GPIO1_MODE 0x60 + + +// extern uint8_t* gpio_mmap_reg = NULL; +// extern int gpio_mmap_fd = 0; + + +int gpio_mmap(void); +int mt76x8_gpio_get_pin(int); +void mt76x8_gpio_set_pin_direction(int, int); +void mt76x8_gpio_set_pin_value(int, int); +void close_gpio(); + + +#endif diff --git a/mt7688-alsa/mem_gpio.o b/mt7688-alsa/mem_gpio.o new file mode 100755 index 00000000..d688177f Binary files /dev/null and b/mt7688-alsa/mem_gpio.o differ diff --git a/mt7688-alsa/oled_iic.c b/mt7688-alsa/oled_iic.c new file mode 100755 index 00000000..819f9924 --- /dev/null +++ b/mt7688-alsa/oled_iic.c @@ -0,0 +1,261 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include "oled_iic.h" +#include "mem_gpio.h" +#include "codetab.h" + + +//init GPIO port +void init_gpio() +{ + if (gpio_mmap()) + printf("gpio_mmap() error!\n"); + + printf("get pin SCL input %d\n", mt76x8_gpio_get_pin(SCL)); + printf("get pin SDA input %d\n", mt76x8_gpio_get_pin(SDA)); + + printf("set pin SCL output 0\n"); + mt76x8_gpio_set_pin_direction(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); + printf("set pin SDA output 0\n"); + mt76x8_gpio_set_pin_direction(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); +} + + +/********************************************** +//IIC Start +**********************************************/ +void IIC_Start() +{ + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +//IIC Stop +**********************************************/ +void IIC_Stop() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); +} + +void IIC_Ack() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +// iic bus write a byte +**********************************************/ +void Write_IIC_Byte(unsigned char IIC_Byte) +{ + unsigned char t; + mt76x8_gpio_set_pin_value(SCL, 0); + + for (t = 0; t < 8; t++) + { + mt76x8_gpio_set_pin_value(SDA, (IIC_Byte&0x80)>>7); + IIC_Byte<<=1; + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 1);//!!! Import Here + //usleep(1); + mt76x8_gpio_set_pin_value(SCL, 0); + } +} + +/*********************OLED write date************************************/ +void OLED_WrDat(unsigned char IIC_Data) +{ + IIC_Start(); + Write_IIC_Byte(0x78); + IIC_Ack(); + Write_IIC_Byte(0x40); //write data + IIC_Ack(); + Write_IIC_Byte(IIC_Data); + IIC_Ack(); + IIC_Stop(); +} +/*********************OLED write command*********************************/ +void OLED_WrCmd(unsigned char IIC_Command) +{ + IIC_Start(); + Write_IIC_Byte(0x78); //Slave address,SA0=0 + IIC_Ack(); + Write_IIC_Byte(0x00); //write command + IIC_Ack(); + Write_IIC_Byte(IIC_Command); + IIC_Ack(); + IIC_Stop(); +} + +/*********************OLED set postion************************************/ +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WrCmd(0xb0+y); + OLED_WrCmd(((x&0xf0)>>4)|0x10); + OLED_WrCmd((x&0x0f)|0x02); //!!! Note Here 01 cannot dispaly perfact !!! +} + +/*********************OLED fill screen************************************/ +void OLED_Fill(unsigned char bmp_dat) +{ + unsigned char y,x; + for(y=0;y<8;y++) + { + OLED_WrCmd(0xb0+y); + OLED_WrCmd(0x02);//low column start address //!!! Note Here 01 cannot dispaly perfact !!! + OLED_WrCmd(0x10);//high column start address + for(x=0;x 0xa1 normal + OLED_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0 0xc8 normal + OLED_WrCmd(0xa6);//--set normal display + OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64) + OLED_WrCmd(0x3f);//--1/64 duty + OLED_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) + OLED_WrCmd(0x00);//-not offset + OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency + OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec + OLED_WrCmd(0xd9);//--set pre-charge period + OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock + OLED_WrCmd(0xda);//--set com pins hardware configuration + OLED_WrCmd(0x12); + OLED_WrCmd(0xdb);//--set vcomh + OLED_WrCmd(0x40);//Set VCOM Deselect Level + OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02) + OLED_WrCmd(0x02);// + OLED_WrCmd(0x8d);//--set Charge Pump enable/disable + OLED_WrCmd(0x14);//--set(0x10) disable + OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5) + OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) + OLED_WrCmd(0xaf);//--turn on oled panel + OLED_Fill(0x00); //clear + OLED_Set_Pos(0,0); +} + +/***************display a 6*8 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P6x8Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>126) {x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<6;i++) + { + OLED_WrDat(F6x8[c][i]); + } + x+=6; + j++; + } +} + +/*******************display a 8*16 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P8x16Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>120){x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i]); + } + OLED_Set_Pos(x,y+1); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i+8]); + } + x+=8; + j++; + } +} +/*****************display a 16*16 ASCII charactertic postion x,y y 0-7****************************/ +void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char N) +{ + unsigned char wm=0; + unsigned int adder=32*N; + OLED_Set_Pos(x , y); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } + OLED_Set_Pos(x,y + 1); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } +} + +/***********display a BMP 128*64 (x,y), x 0-127 y 0-7*****************/ +void Draw_BMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1,unsigned char BMP[]) +{ + unsigned int j=0; + unsigned char x,y; + + if(y1%8==0) + y=y1/8; + else + y=y1/8+1; + for(y=y0;y + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/.idea/misc.xml b/mt7688-alsa/python-s/.idea/misc.xml new file mode 100755 index 00000000..5bbe586f --- /dev/null +++ b/mt7688-alsa/python-s/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/.idea/modules.xml b/mt7688-alsa/python-s/.idea/modules.xml new file mode 100755 index 00000000..b0a1fa22 --- /dev/null +++ b/mt7688-alsa/python-s/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/.idea/s.iml b/mt7688-alsa/python-s/.idea/s.iml new file mode 100755 index 00000000..09ae862d --- /dev/null +++ b/mt7688-alsa/python-s/.idea/s.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/.idea/workspace.xml b/mt7688-alsa/python-s/.idea/workspace.xml new file mode 100755 index 00000000..683f16ba --- /dev/null +++ b/mt7688-alsa/python-s/.idea/workspace.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + 1492759513909 + + + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/CommandsFunc.py b/mt7688-alsa/python-s/CommandsFunc.py new file mode 100755 index 00000000..759c92a5 --- /dev/null +++ b/mt7688-alsa/python-s/CommandsFunc.py @@ -0,0 +1,215 @@ +# -*- coding: utf-8 -*- +import os +from time import sleep +from ctypes import * +#from dingdingApi import * +from SpeechHelper import SpeechHelper + +ALL_FUNCS_NAME = ["host_scene1", "host_scene2", "host_scene3", "host_scene4", "host_scene5", + "test_1", "test_2", "test_3", "test_4"] +ALL_FUNCS = {} + + + +#------------------interface +def command(scene_name, vistor_type="host"): + def deco_(func): + def wraps(*args, **kwargs): + print(func.__name__) + ALL_FUNCS[vistor_type + scene_name] = func + return wraps + return deco_ + + + +def cmd(visit, is_play=True, key="", value=True): + tmp_cmd = {key: value} + print(tmp_cmd) + visit.tts(visit.ask_and_answer(tmp_cmd), is_play) + sleep(0.5) + + + +def play_media(visit, is_play=True, text=None, filename="test.wav"): + if text: + print({"Text": text}) + visit.tts(visit.ask_and_answer({"Text": text}), is_play) + return + spt = visit.stt(filename) + visit.tts(visit.ask_and_answer({"Text": spt}), is_play) + + +def bell_ring(visit, is_play=True, flag=True, cmd="BellRingFlag"):#libsc is not in this environment.so ignore it + ring_bell = {cmd: is_play} + print(ring_bell) + # waiting for push the ring button + print ("Waiting the button push!") + if flag: + from TrioAIHelper import libsc + while (0 == libsc.get_button()): + sleep(0.1) + print ("The button push!") + visit.tts(visit.ask_and_answer(ring_bell), is_play) + sleep(0.5) + +def recog_postman(visit, is_play=True, cmd="LockRecogDeliveryFlag"): + recog = {cmd: is_play} + visit.tts(visit.ask_and_answer(recog), is_play) + sleep(0.5) + +def passwd_valid(visit, is_play=True, cmd="PasswdValidFlag"): + unclocked = {cmd: is_play} + print(unclocked) + visit.tts(visit.ask_and_answer(unclocked), is_play) + + +def host_at_home(visit, is_play=True, cmd="HostAtHomeFlag"): + host_at_home = {cmd: is_play} + print(host_at_home) + visit.tts(visit.ask_and_answer(host_at_home), is_play) + +def host_say(visit, is_play=True, cmd="SAY_NO_HOME"): + host_say = {cmd: is_play} + print(host_say) + visit.tts(visit.ask_and_answer(host_say), is_play) + +def host_recog_delivery(visit, is_play=True, cmd="HostRecogDeliveryFlag"): + print("---------------------1") + host_recog = {cmd: is_play} + print(host_recog) + visit.tts(visit.ask_and_answer(host_recog), is_play) + + + + + + +@command("scene1", "host") +def host_scene1(visit, is_play=True): + passwd_valid(visit, is_play=is_play) + + +@command("scene2", "host") +def host_scene2(visit, is_play=True): + bell_ring(visit, is_play=is_play) + play_media(visit) + +@command("scene3", "host") +def host_scene3(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "Yes, I forgot my password" + print (spt) + play_media(visit, text=tmp_text) + passwd_valid(visit, is_play=is_play) + +@command("scene4", "host") +def host_scene4(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "Yes, I forgot my password" + play_media(visit, text=tmp_text) + tmp_text = "I forgot my phone" + play_media(visit, text=tmp_text) + +@command("scene5", "host") +def host_scene5(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "i just try the bell" + play_media(visit, text=tmp_text) + +@command("test", "host") +def test_1(visit, is_play=True): + #tmp_text = "Welcome back home! " + from TrioAIHelper import libsc + libsc.display_oled_string() + bell_ring(visit, is_play=is_play) + print ("record and play: ") + libsc.thread_rec() + # os.system("chmod +x ./test.wav") + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # print ("spt = " + spt) + # tmp_text = spt + tmp_text = "Yes, I forgot my password" + play_media(visit, text=tmp_text,is_play=False) + SpeechHelper(lang='en-GB', gender='male').text_to_speech("The password is 1 2 3 4 5 6", True) + passwd_valid(visit, is_play=is_play) + +@command("test", "family") +def test_2(visit, is_play=True): + print ("record and play: ") + from TrioAIHelper import libsc, SinglePub + topic = "incoming_visiting" + msg = "Sheldon is here" + SinglePub.single_publish(topic, message=msg) + libsc.thread_rec() + # os.system("chmod +x ./test.wav") + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # print ("spt = " + spt) + # tmp_text = spt + tmp_text = "i come to send something" + play_media(visit, text=tmp_text) + cmd(visit, is_play=is_play, key="HostAtHomeFlag", value=True) + cmd(visit, is_play=is_play, key="HostSay", value="OPEN_MYSELF") + +@command("test", "stranger") +def test_3(visit, is_play=True, topic="mt7687expressbox", msg="open the expressbox"): + SpeechHelper(lang='en-GB', gender='male').text_to_speech("Hi postman, nice to see you, pickup or delivery?", True) + # recog_postman(visit, is_play=is_play) + #cmd(visit, is_play=is_play, key="LockRecogDeliveryFlag", value=True) + #print ("record and play: ") #I am here to send a package + from TrioAIHelper import libsc, SinglePub + topic = "incoming_visiting" + msg = "Delivery boy is here" + SinglePub.single_publish(topic, message=msg) + libsc.thread_rec() + # os.system("chmod +x ./test.wav") + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # print ("spt = " + spt) + # tmp_text = spt + #tmp_text = "i am a postman" + #play_media(visit, text=tmp_text) + #SpeechHelper(lang='en-GB', gender='male').text_to_speech("pickup or delivery?", True) + #todo + #from TrioAIHelper import libsc + #libsc.thread_rec() + # os.system("chmod +x ./test.wav") + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # print ("spt = " + spt) + # tmp_text = spt + tmp_text = "im here to send a package" + #play_media(visit, text=tmp_text) + SpeechHelper(lang='en-GB', gender='male').text_to_speech("mailbox will be opened soon", True) + #for test + test = True + from TrioAIHelper import SinglePub + while True: + SinglePub.single_publish(topic, message=msg) + if test: + break + +@command("test", "stranger_new") +def test_4(visit, is_play=True, topic="mt7687expressbox", msg="open the expressbox"): + cmd(visit, is_play=is_play, key="NoResponseFlag", value=True) + from TrioAIHelper import libsc, SinglePub + topic = "incoming_visiting" + msg = "stranger is here" + SinglePub.single_publish(topic, message=msg) + libsc.thread_rec() + # os.system("chmod +x ./test.wav") + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # print ("spt = " + spt) + # tmp_text = spt + tmp_text = "My name is Tom." + play_media(visit, text=tmp_text) + +def init_all_funcs(): + for func_name in ALL_FUNCS_NAME: + print(func_name) + exec(func_name + "()") + + +init_all_funcs() diff --git a/mt7688-alsa/python-s/SpeechHelper.py b/mt7688-alsa/python-s/SpeechHelper.py new file mode 100755 index 00000000..4989a61a --- /dev/null +++ b/mt7688-alsa/python-s/SpeechHelper.py @@ -0,0 +1,226 @@ +import sys +import json +import wave +import uuid +import os +# from time import time +from time import * +from os import environ as env +from xml.etree import ElementTree +from ctypes import * +import ssl +ssl._create_default_https_context = ssl._create_unverified_context + +import pdb + +if sys.version.startswith('3'): + import http.client as httpclient + import urllib.parse as urllibparse +else: + import httplib as httpclient + import urllib as urllibparse +''' +IMIO_HOME = env.get('IMIO_HOME') +if IMIO_HOME is not None: + sys.path.append(IMIO_HOME) +''' +import constants as const + + +class SpeechHelper(object): + def __init__(self, lang='zh-CN', gender='female'): + self.__lang = lang + self.__gender = gender + self.__apiKey = const.COG_STT_TTS_KEY + self.__req_body = ElementTree.Element('speak', version='1.0') + self.__req_body.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice = ElementTree.SubElement(self.__req_body, 'voice') + self.__voice.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice.set('{http://www.w3.org/XML/1998/namespace}gender', gender) + self.__voice.set('name', 'Microsoft Server Speech Text to Speech Voice ' + self.__init_voice_font()) + #for e in self.__voice: + # print(type(e)) + # print(e) + self.__accesstoken = self.__init_access_token() + + def __init_access_token(self): + params = "" + get_token_headers = {"Ocp-Apim-Subscription-Key": self.__apiKey} + # AccessTokenUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; + AccessTokenHost = "api.cognitive.microsoft.com" + path = "/sts/v1.0/issueToken" + # Connect to server to get the Access Token + #conn = httpclient.HTTPConnection(AccessTokenHost) + conn = httpclient.HTTPSConnection(AccessTokenHost) + conn.request("POST", path, params, get_token_headers) + response = conn.getresponse() + # print(response.status, response.reason) + data = response.read() + conn.close() + return data.decode("UTF-8") + + def __init_voice_font(self): + if self.__lang == 'zh-CN': + if self.__gender == 'female': + voicefont = '(zh-CN, Yaoyao, Apollo)' + else: + voicefont = '(zh-CN, Kangkang, Apollo)' + elif self.__lang == 'en-GB': + if self.__gender == 'female': + voicefont = '(en-GB, Susan, Apollo)' + else: + voicefont = '(en-GB, George, Apollo)' + elif self.__lang == 'es-ES': + if self.__gender == 'female': + voicefont = '(es-ES, Laura, Apollo)' + else: + voicefont = '(es-ES, Pablo, Apollo)' + elif self.__lang == 'en-IN': + voicefont = '(en-IN, Ravi, Apollo)' + else: + # default as US english + if self.__gender == 'female': + voicefont = '(en-US, ZiraRUS)' + else: + voicefont = '(en-US, BenjaminRUS)' + #voicefont = '(en-US, Eminem)' + return voicefont + + def text_to_speech(self, text_in, play=False): + libsc = cdll.LoadLibrary(os.getcwd() + '/libmain.so') + libsc.display_oled_string() + """ + Convert input text to speech audio and play on microphone + :param text_in: + :return: + """ + if text_in is None: + return None + if sys.version.startswith('2'): + if not isinstance(text_in, unicode): + self.__voice.text = unicode(text_in, 'utf-8') + else: + self.__voice.text = text_in + else: + self.__voice.text = text_in + headers = {"Content-type": "application/ssml+xml", + "X-Microsoft-OutputFormat": "riff-16khz-16bit-mono-pcm", + "Authorization": "Bearer " + self.__accesstoken, + "X-Search-AppId": "07D3234E49CE426DAA29772419F436CA", + "X-Search-ClientID": "1ECFAE91408841A480F00935DC390960", + "User-Agent": "TTSForPython"} + # Connect to server to synthesize the wave + #conn = httpclient.HTTPConnection("speech.platform.bing.com") + conn = httpclient.HTTPSConnection("speech.platform.bing.com") + conn.request("POST", "/synthesize", ElementTree.tostring(self.__req_body), headers) + response = conn.getresponse() + data = response.read() + conn.close() + print('stream is:') + print(data) + + if play: + ''' + import pyaudio + #print('Playing speech') + p = pyaudio.PyAudio() + stream = p.open(format=pyaudio.paInt16, + channels=1, + rate=16000, + output=True, + frames_per_buffer=1024) + stream.write(data) + stream.close() + ''' + # pdb.set_trace() + # os.system('rm ./test.wav') + wfname = "test.wav" + wf = wave.open(wfname, 'wb') + wf.setnchannels(1) + wf.setsampwidth(2) + wf.setframerate(16000) + wf.writeframesraw(data) + wf.close() + # pdb.set_trace() + sleep(0.5) + os.system('chmod +x ./test.wav') + os.system('aplay ./test.wav') + #os.system('aplay /root/what.wav') + #os.system('ls') + + libsc.clear_display() + + return data + + def speech_to_text(self, wf): + """ + Convert the speech audio data to text + :param wf: wave file name, or the actual stream data from a wave file + :return: False if MS Cognitive serice returns error, otherwise the resulted texts will be returned + """ + texts = [] + my_uuid = uuid.uuid4() + headers = { + 'Content-type': 'audio/wav', + # 'Content-type': 'application/octet-stream', + 'samplerate': 16000, + 'Authorization': self.__accesstoken, + # 'codec': "audio/pcm", + } + params = urllibparse.urlencode({ + 'version': '3.0', + 'requestid': my_uuid, + 'appid': const.APP_ID, + 'format': 'json', + 'locale': self.__lang, + 'device.os': 'ubuntu', + 'scenarios': 'smd', + 'instanceid': my_uuid + }) + print(type(wf)) + if isinstance(wf, str): + body = open(wf, 'rb').read() + elif isinstance(wf, bytes): + body = wf + else: + return ''.join(texts) + #conn = httpclient.HTTPConnection('speech.platform.bing.com') + conn = httpclient.HTTPSConnection('speech.platform.bing.com') + conn.request('POST', '/recognize?%s' % params, body, headers) + response = conn.getresponse() + print(response) + data = json.loads(response.read().decode('utf-8')) + result = data['header']['status'] + if result != 'success': + print('INSIDE: STT failed') + return None + else: + outputs = data['results'] + for opt in outputs: + if float(opt['confidence']) > 0.65: + texts.append(opt['name']) + return ''.join(texts) + + +def main(): + wf_name = 'temp.wav' + ''' + spch = SpeechHelper(lang='en-US', gender='male') + + #res_text = spch.speech_to_text(wf_name) + #print(res_text) + #os.remove(wf_name) + ''' + + ''' + stream.start_stream() + while stream.is_active(): + sleep(0.1) + stream.stop_stream() + stream.close() + p.terminate() + ''' + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python-s/TrioAIHelper.py b/mt7688-alsa/python-s/TrioAIHelper.py new file mode 100755 index 00000000..590060b6 --- /dev/null +++ b/mt7688-alsa/python-s/TrioAIHelper.py @@ -0,0 +1,265 @@ +import sys +import json +import traceback +import paho.mqtt.client as mqtt +import paho.mqtt.publish as mqttpub +from time import sleep +from ctypes import * +import os +import time + +try: + import http.client as httplib + import urllib.parse as urlparse +except: + import httplib + import urllib as urlparse + +from SpeechHelper import SpeechHelper +#tmp for test +from CommandsFunc import * + + + +# Constants +DEFAULT_QOS = 2 +DEFAULT_KEEP_ALIVE = 60 +MQTT_BROKER_HOST = 'mq.imio.io' +MQTT_BROKER_PORT = 1883 +libsc = cdll.LoadLibrary(os.getcwd() + '/libmain.so') + +class SinglePub(object): + + @staticmethod + def single_publish(topic, message, timeout=DEFAULT_KEEP_ALIVE): + mqttpub.single(topic, message, qos=DEFAULT_QOS, hostname=MQTT_BROKER_HOST, + port=MQTT_BROKER_PORT, keepalive=timeout) + print("-----------------already send") + +class TrioAIAgent(object): + def __init__(self, profile, lang='en-US', rob_gender='female'): + self.__profile = profile + self.__lang = lang + self.__gender = rob_gender + self.__uid = profile['UserId'] + self.__vid = profile['VisitorId'] + self.__ownership = profile['VisitorType'] + self.__chat_host = 'sandbox.sanjiaoshou.net' + self.__chat_url = 'http://sandbox.sanjiaoshou.net/Api/chat?who=demo&userID=imio_111&%s' + self.__cmd_lock_url = 'http://service.sanjiaoshou.net/Locker/index.php?f=locker' + self.__cmd_host = 'service.sanjiaoshou.net' + self.__headers = {'Content-Type': 'application/json',} + self.__session_start = False + return + + def set_userid(self, uid): + self.__uid = uid + + def set_visitor_id(self, vid): + self.__vid = vid + + def set_ownership(self, ownership): + self.__ownership = ownership + + def welcome(self): + entry_msg = self.front_door_text_conv() + if entry_msg is None: + return None + lock_state = entry_msg[0] + welcome_msg = entry_msg[1] + #print('lock state: ' + lock_state) + #print(welcome_msg) + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + stream = spch.text_to_speech(welcome_msg, False) + return stream + + def chat(self, query): + params = urlparse.urlencode({'sentence': query.encode('utf-8')}) + try: + url = self.__chat_url % params + conn = httplib.HTTPConnection(self.__chat_host) + #conn = httplib.HTTPSConnection(self.__chat_host) + conn.request("GET", url) + response = conn.getresponse().read() + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + print(data) + conn.close() + return data['reply'] + except Exception as e: + print(e) + return None + + def front_door_text_conv(self, query=None, play=False): + params = self.__profile + if query is not None: + params.update(query) + body = json.dumps(params) + try: + url = self.__cmd_lock_url + conn = httplib.HTTPConnection(self.__cmd_host) + #conn = httplib.HTTPSConnection(self.__cmd_host) + conn.request(method="POST", url=url, body=body, headers=self.__headers) + response = conn.getresponse().read() + print(response) + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + conn.close() + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + spch.text_to_speech(text_in=data['reply'], play=play) + return data['lockStatus'], data['reply'] + except Exception as e: + traceback.print_exc() + print(e) + return None + + +class FrontDoorScene(object): + def __init__(self, lang='en-US', rob_gender='female'): + self.__QoS = 2 + self.__lang = lang + self.__gender = rob_gender + self.__TOPIC = 'visitor_profile' + self.__cli = mqtt.Client() + self.__cli.on_connect = self.__connect_cb + self.__cli.on_message = self.__message_cb + self.__session_start = False + self.__visit_type = "stranger" + self.is_postman = False + + def __connect_cb(self, client, userdata, flags, rc): + self.__cli.subscribe(self.__TOPIC, self.__QoS) + return + + def __message_cb(self, client, data, msg): + if msg.topic == self.__TOPIC: + print('Incoming message!') + payload = msg.payload + print(type(payload)) + raw_msg = payload.decode('utf-8') + print(type(raw_msg)) + print(raw_msg) + if sys.version.startswith('2'): + try: + profile = json.loads(raw_msg).encode("utf-8") + except: + profile = json.loads(raw_msg) + print(profile) + self.__last_vid = profile["VisitorId".decode("utf-8")] + self.__visit_type = profile["VisitorType".decode("utf-8")] + if profile.get("LockRecogDeliveryFlag", None): + self.is_postman = True + #self.__visit_type = "host" + if not self.__session_start: + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + return + + def visit_id(self): + return self.__last_vid + + def visit_type(self): + return self.__visit_type + + def is_session_started(self): + return self.__session_start + + def session_end(self): + self.__session_start = False + + def start(self, blocking=False, profile=None): + + self.__cli.connect(host='mq.imio.io', port=1883) + if blocking: + self.__cli.loop_forever() + else: + self.__cli.loop_start() + ''' + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + ''' + + + def stt(self, wf): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.speech_to_text(wf) + + def tts(self, text, play=False): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.text_to_speech(text_in=text, play=play) + + def ask_and_answer(self, query): + ans = self.__trio_ai.front_door_text_conv(query=query) + if ans is not None: + reply = ans[1] + print(reply) + return reply + else: + return None + + +def main(): + os.system('chmod +x *.wav') + print ("Start!") + # tmp_profile = {"UserId": "10001"} + #my_profile = {"UserId":"10003","VisitorId":"Jim","VisitorType":"host"} + #my_profile = {"UserId":"10004","VisitorId":"Bob","VisitorType":"family"} + #postman_profile = {"UserId":"10001","VisitorId":"unknown","VisitorType":"stranger", + #"LockRecogDeliveryFlag": True} + visit = FrontDoorScene(lang='en-GB', rob_gender='male') + visit.start() + #visit.start(profile=my_profile) + #visit.start(profile=postman_profile) + #print("---------------------1") + while True: + if visit.is_session_started(): + ''' + #waiting for push the ring button + print ("Waiting the button push!") + #while (0 == libsc.get_button()): + #sleep(0.1) + print ("The button push!") + ring_bell = {'BellRingFlag': True} + visit.tts(visit.ask_and_answer(ring_bell), True) + sleep(0.5) + os.system('chmod +x *.wav') + #wf = open('temp.wav', 'rb') + #spt = visit.stt('temp.wav') + #open_door = {'Text': spt} + #print (spt) + # libsc.thread_rec() + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # open_door = {'Text': spt} + open_door = {'Text': 'Yes, I forgot my password'} + visit.tts(visit.ask_and_answer(open_door), True) + sleep(0.5) + unclocked = {"PasswdValidFlag": True} + visit.tts(visit.ask_and_answer(unclocked), True) + ''' + print (visit.visit_type()) + if visit.visit_type() == "host": + tmp_ = "hosttest" + print("-----------------------") + elif visit.visit_type() == "family": + tmp_ = "familytest" + else: + pass#if visit.is_postman: + tmp_ = "strangertest" + #else: + #tmp_ = "stranger_newtest" + #tmp_ = "strangertest" + func = ALL_FUNCS.get(tmp_, None) + if func: + print(func.__name__) + func(visit, True) + visit.session_end() + print("session end------------------------") + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python-s/__init__.py b/mt7688-alsa/python-s/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/mt7688-alsa/python-s/__pycache__/constants.cpython-35.pyc b/mt7688-alsa/python-s/__pycache__/constants.cpython-35.pyc new file mode 100755 index 00000000..aed0aa10 Binary files /dev/null and b/mt7688-alsa/python-s/__pycache__/constants.cpython-35.pyc differ diff --git a/mt7688-alsa/python-s/constants.py b/mt7688-alsa/python-s/constants.py new file mode 100755 index 00000000..c8ed8527 --- /dev/null +++ b/mt7688-alsa/python-s/constants.py @@ -0,0 +1,8 @@ +APP_ID = '950f8ca2-1b6e-41b3-a90c-c7775997603e' +APP_PWD = 'EWwjGB3hU47BfrqcGfYEKfC' + +MS_COG_HOST = 'westus.api.cognitive.microsoft.com' +COG_FACE_KEY = '0b1e119d7493471fa878f61214c31676' +COG_FACE_KEY_SEC = '5296e25a60b847239404c13e5b905a0a' +COG_SPEEKER_KEY = 'f4573d5f3a69422c828ac6f05bb1b687' +COG_STT_TTS_KEY = '50a64ed5fc0e4e4a999887c43fae9428' diff --git a/mt7688-alsa/python-s/dingdingApi.py b/mt7688-alsa/python-s/dingdingApi.py new file mode 100755 index 00000000..1bef6d32 --- /dev/null +++ b/mt7688-alsa/python-s/dingdingApi.py @@ -0,0 +1,216 @@ +#-*- coding:utf-8 -*- +import requests +import random +import time +import json +import time + +#public string +access_token = '08dcdb662c3b0f8d540a31a0c32234ea311f60f164b307e138b3521e16cf70da6f6254c05d6857f28fe7ee04740f67b1' +sign = '12345' #string sign and timestamp Not use +uuid = 'ed1a71c1eb1aad4f77ef85cf3cd031cd' + +def generate_code(): + #Random password + code_list = [] + for i in range(10): + code_list.append(str(i)) + myslice = random.sample(code_list, 6) + verification_code = ''.join(myslice) + #print (verification_code) + return verification_code + + +def func(x): + # return the x is interger or not + try: + x = int(x) + return isinstance(x, int) + except ValueError: + return False + + +def add_password(status, number=None): + ''' + add a password func + json object {status begin end} status = 1 permanent + 2 temp + status=2 begin and end must exist side by side + ''' + # 5 minute ago , But no effect + begin = int(time.time()) - 300 + ''' + time_local = time.localtime(begin) + dt = time.strftime("%Y-%m-%d %H:%M:%S",time_local) + time_locals = time.localtime(begin + 300) + dts = time.strftime("%Y-%m-%d %H:%M:%S",time_locals) + print (dt) + print (dts) + ''' + end = begin + 3600 + permission = {'status':str(status), 'begin':str(begin), 'end': str(end)} + is_default = 0 #is_default = 1 admin other number or no value is temp + notify = 2 + phone = 'x' + country_code = '+86' + name = str(int(time.time())) + password = number + + if status == 1: + if len(number) == 6: + password = number + '''is_int = func(int(number)) + if is_int: + print ("isInt") + else: + print ("isNot Int")''' + else: + retmsg = "Password is not available!" + return retmsg + if status == 2: + password = str(generate_code()) + + add_param = {'access_token': access_token, + 'sign': sign, + 'uuid': uuid, + 'password': password, + 'permission': json.dumps(permission), + #'is_default': is_default, + #'notify': notify, + #'phone': phone, + #'country_code': country_code, + 'name': name} + + add_url = "http://118.190.15.108:4085/api/lock/v1/pwd/operations/add"; + add_res = requests.post(add_url, data = add_param) + #print(add_res.url) + #print(add_res.text) + + res_str = json.loads(add_res.text) + error_str = res_str["ErrNo"] + if int(error_str) == 0: + if status == 1: + return True + if status == 2: + return password + else: + retmsg = "Error : " + str(error_str) + print(retmsg) + return retmsg + +def list_password(): + #Get the password + list_url = "http://118.190.15.108:4085/api/lock/v1/pwd/"; + param = {'access_token': access_token, + 'sign': sign, + 'uuid': uuid } + list = requests.get(list_url, params = param) + #print(list.url) + #print(list.text) + list_str = json.loads(list.text) + list_json_str = list_str["passwords"] + #print (list_json_str) + passwords = sorted(list_json_str.keys()) #Note + #print (passwords) + #Parse json date + list_num = [] + for i in range(len(passwords)): + list_num.append(str(passwords[i])) + #print str(i + 1) + " : " + str(passwords[i]) + #print (list_num) + #Whether operating correctly + list_string = json.loads(list.text) + error_string = list_string["ErrNo"] + if int(error_string) == 0: + return list_num + else: + print (str(error_string)) + return False + + #Get the passwordid + '''isTrue = True + while isTrue: + print 'Please input a number: ' + input_num = raw_input() + input = func(input_num) + if input: + isTrue = False + else: + print "Input Error! Please input an interger: " + #print list_num[int(input_num) - 1] + passwordid = list_num[int(input_num) - 1] + ''' + + +def delete_password(num): + #Delete the password + list_password_str = list_password() + passwordid = list_password_str[num - 1] + #print passwordid + param_del_data = {'access_token': access_token, + 'sign': sign, + 'uuid': uuid, + 'passwordid': passwordid, + #'userid': userid + } + delete_url = "http://118.190.15.108:4085/api/lock/v1/pwd/operations/delete" + del_list = requests.post(delete_url, data = param_del_data) + + #print(del_list.url) + #print(del_list.text) + #Update the password + del_str = json.loads(del_list.text) + error_string = del_str["ErrNo"] + if int(error_string) == 5021: + return True + else: + print(str(error_string)) + return False + + +def update_password(num_id, new_password): + #Update the password + list_password_str = list_password() + passwordid = list_password_str[num_id - 1] + password = new_password + param_update_data = {'access_token': access_token, + 'sign': sign, + 'uuid': uuid, + 'passwordid': passwordid, + 'password': password, + #'permission': permission + } + update_url = "http://118.190.15.108:4085/api/lock/v1/pwd/operations/update" + update_res = requests.post(update_url, data = param_update_data) + + #print(update_res.url) + #print(update_res.text) + #Whether operating correctly + update_str = json.loads(update_res.text) + error_string = update_str["ErrNo"] + if int(error_string) == 0: + return True + else: + print(str(error_string)) + return False + +#Test Part +# print (list_password(1, "472235")) +print (add_password(1, "472235")) +#print (list_password()) +#print (add_password(2, "201987")) +#print (list_password()) +#print (delete_password(4)) +#print (list_password()) +#print (update_password(4, '704982')) + + + + + + + + + + + diff --git a/mt7688-alsa/python-s/libmain.so b/mt7688-alsa/python-s/libmain.so new file mode 100755 index 00000000..e697951e Binary files /dev/null and b/mt7688-alsa/python-s/libmain.so differ diff --git a/mt7688-alsa/python-s/s/.idea/inspectionProfiles/profiles_settings.xml b/mt7688-alsa/python-s/s/.idea/inspectionProfiles/profiles_settings.xml new file mode 100755 index 00000000..c23ecacb --- /dev/null +++ b/mt7688-alsa/python-s/s/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/s/.idea/misc.xml b/mt7688-alsa/python-s/s/.idea/misc.xml new file mode 100755 index 00000000..5bbe586f --- /dev/null +++ b/mt7688-alsa/python-s/s/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/s/.idea/modules.xml b/mt7688-alsa/python-s/s/.idea/modules.xml new file mode 100755 index 00000000..b0a1fa22 --- /dev/null +++ b/mt7688-alsa/python-s/s/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/s/.idea/s.iml b/mt7688-alsa/python-s/s/.idea/s.iml new file mode 100755 index 00000000..09ae862d --- /dev/null +++ b/mt7688-alsa/python-s/s/.idea/s.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/s/.idea/workspace.xml b/mt7688-alsa/python-s/s/.idea/workspace.xml new file mode 100755 index 00000000..683f16ba --- /dev/null +++ b/mt7688-alsa/python-s/s/.idea/workspace.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + 1492759513909 + + + + + + + + + + \ No newline at end of file diff --git a/mt7688-alsa/python-s/s/CommandsFunc.py b/mt7688-alsa/python-s/s/CommandsFunc.py new file mode 100755 index 00000000..40ac6a01 --- /dev/null +++ b/mt7688-alsa/python-s/s/CommandsFunc.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +import os +from time import sleep + +ALL_FUNCS_NAME = ["host_scene1", "host_scene2", "host_scene3", "host_scene4", "host_scene5", + "test_1", "test_2", "test_3"] +ALL_FUNCS = {} + + + +#------------------interface +def command(scene_name, vistor_type="host"): + def deco_(func): + def wraps(*args, **kwargs): + print(func.__name__) + ALL_FUNCS[vistor_type + scene_name] = func + return wraps + return deco_ + +def play_media(visit, is_play=True, text=None, filename="test.wav"): + if text: + print({"Text": text}) + visit.tts(visit.ask_and_answer({"Text": text}), is_play) + return + spt = visit.stt(filename) + visit.tts(visit.ask_and_answer({"Text": spt}), is_play) + + +def bell_ring(visit, is_play=True, libsc=None, cmd="BellRingFlag"):#libsc is not in this environment.so ignore it + ring_bell = {cmd: is_play} + print(ring_bell) + # waiting for push the ring button + print ("Waiting the button push!") + if libsc: + while (0 == libsc.get_button()): + sleep(0.1) + print ("The button push!") + visit.tts(visit.ask_and_answer(ring_bell), is_play) + sleep(0.5) + +def open_expressbox(visit, is_play=True, topic="", msg="", cmd="LockRecogDeliveryFlag"): + test = True + from TrioAIHelper import SinglePub + while True: + SinglePub.single_publish(topic, message=msg) + sleep(5) + if test: + break + + recog = {cmd: is_play} + visit.tts(visit.ask_and_answer(recog), is_play) + sleep(0.5) + +def passwd_valid(visit, is_play=True, cmd="PasswdValidFlag"): + unclocked = {cmd: is_play} + print(unclocked) + visit.tts(visit.ask_and_answer(unclocked), is_play) + + +@command("scene1", "host") +def host_scene1(visit, is_play=True): + passwd_valid(visit, is_play=is_play) + + +@command("scene2", "host") +def host_scene2(visit, is_play=True): + bell_ring(visit, is_play=is_play) + play_media(visit) + +@command("scene3", "host") +def host_scene3(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "Yes, I forgot my password" + play_media(visit, text=tmp_text) + passwd_valid(visit, is_play=is_play) + +@command("scene4", "host") +def host_scene4(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "Yes, I forgot my password" + play_media(visit, text=tmp_text) + tmp_text = "I forgot my phone" + play_media(visit, text=tmp_text) + +@command("scene5", "host") +def host_scene5(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "i just try the bell" + play_media(visit, text=tmp_text) + +@command("test", "host") +def test_1(visit, is_play=True): + bell_ring(visit, is_play=is_play) + tmp_text = "Yes, I forgot my password" + play_media(visit, text=tmp_text) + passwd_valid(visit, is_play=is_play) + +@command("test", "family") +def test_2(visit, is_play=True): + pass + +@command("test", "stranger") +def test_3(visit, is_play=True, topic="mt7687expressbox", msg="open the expressbox"): + open_expressbox(visit, is_play=is_play, topic=topic, msg=msg) + tmp_text = "I am a post man" + play_media(visit, text=tmp_text) + tmp_text = "I am here to send a package" + play_media(visit, text=tmp_text) + + + +def init_all_funcs(): + for func_name in ALL_FUNCS_NAME: + print(func_name) + exec(func_name + "()") + + +init_all_funcs() diff --git a/mt7688-alsa/python-s/s/CommandsFunc.pyc b/mt7688-alsa/python-s/s/CommandsFunc.pyc new file mode 100755 index 00000000..da26716d Binary files /dev/null and b/mt7688-alsa/python-s/s/CommandsFunc.pyc differ diff --git a/mt7688-alsa/python-s/s/SpeechHelper.py b/mt7688-alsa/python-s/s/SpeechHelper.py new file mode 100755 index 00000000..ea220a0b --- /dev/null +++ b/mt7688-alsa/python-s/s/SpeechHelper.py @@ -0,0 +1,211 @@ +import sys +import json +import wave +import uuid +import os +from time import time +from os import environ as env +from xml.etree import ElementTree + +if sys.version.startswith('3'): + import http.client as httpclient + import urllib.parse as urllibparse +else: + import httplib as httpclient + import urllib as urllibparse +''' +IMIO_HOME = env.get('IMIO_HOME') +if IMIO_HOME is not None: + sys.path.append(IMIO_HOME) +''' +import constants as const + + +class SpeechHelper(object): + def __init__(self, lang='zh-CN', gender='female'): + self.__lang = lang + self.__gender = gender + self.__apiKey = const.COG_STT_TTS_KEY + self.__req_body = ElementTree.Element('speak', version='1.0') + self.__req_body.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice = ElementTree.SubElement(self.__req_body, 'voice') + self.__voice.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice.set('{http://www.w3.org/XML/1998/namespace}gender', gender) + self.__voice.set('name', 'Microsoft Server Speech Text to Speech Voice ' + self.__init_voice_font()) + #for e in self.__voice: + # print(type(e)) + # print(e) + self.__accesstoken = self.__init_access_token() + + def __init_access_token(self): + params = "" + get_token_headers = {"Ocp-Apim-Subscription-Key": self.__apiKey} + # AccessTokenUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; + AccessTokenHost = "api.cognitive.microsoft.com" + path = "/sts/v1.0/issueToken" + # Connect to server to get the Access Token + #conn = httpclient.HTTPConnection(AccessTokenHost) + conn = httpclient.HTTPSConnection(AccessTokenHost) + conn.request("POST", path, params, get_token_headers) + response = conn.getresponse() + # print(response.status, response.reason) + data = response.read() + conn.close() + return data.decode("UTF-8") + + def __init_voice_font(self): + if self.__lang == 'zh-CN': + if self.__gender == 'female': + voicefont = '(zh-CN, Yaoyao, Apollo)' + else: + voicefont = '(zh-CN, Kangkang, Apollo)' + elif self.__lang == 'en-GB': + if self.__gender == 'female': + voicefont = '(en-GB, Susan, Apollo)' + else: + voicefont = '(en-GB, George, Apollo)' + elif self.__lang == 'es-ES': + if self.__gender == 'female': + voicefont = '(es-ES, Laura, Apollo)' + else: + voicefont = '(es-ES, Pablo, Apollo)' + elif self.__lang == 'en-IN': + voicefont = '(en-IN, Ravi, Apollo)' + else: + # default as US english + if self.__gender == 'female': + voicefont = '(en-US, ZiraRUS)' + else: + voicefont = '(en-US, BenjaminRUS)' + #voicefont = '(en-US, Eminem)' + return voicefont + + def text_to_speech(self, text_in, play=False): + """ + Convert input text to speech audio and play on microphone + :param text_in: + :return: + """ + if text_in is None: + return None + if sys.version.startswith('2'): + if not isinstance(text_in, unicode): + self.__voice.text = unicode(text_in, 'utf-8') + else: + self.__voice.text = text_in + else: + self.__voice.text = text_in + headers = {"Content-type": "application/ssml+xml", + "X-Microsoft-OutputFormat": "riff-16khz-16bit-mono-pcm", + "Authorization": "Bearer " + self.__accesstoken, + "X-Search-AppId": "07D3234E49CE426DAA29772419F436CA", + "X-Search-ClientID": "1ECFAE91408841A480F00935DC390960", + "User-Agent": "TTSForPython"} + # Connect to server to synthesize the wave + #conn = httpclient.HTTPConnection("speech.platform.bing.com") + conn = httpclient.HTTPSConnection("speech.platform.bing.com") + conn.request("POST", "/synthesize", ElementTree.tostring(self.__req_body), headers) + response = conn.getresponse() + data = response.read() + conn.close() + #print('stream is:') + #print(data) + + if play: + ''' + import pyaudio + #print('Playing speech') + p = pyaudio.PyAudio() + stream = p.open(format=pyaudio.paInt16, + channels=1, + rate=16000, + output=True, + frames_per_buffer=1024) + stream.write(data) + stream.close() + ''' + wfname = "test.wav" + wf = wave.open(wfname, 'wb') + wf.setnchannels(1) + wf.setsampwidth(2) + wf.setframerate(16000) + wf.writeframesraw(data) + wf.close() + os.system('aplay ./test.wav') + #os.system('aplay /root/what.wav') + #os.system('ls') + + return data + + def speech_to_text(self, wf): + """ + Convert the speech audio data to text + :param wf: wave file name, or the actual stream data from a wave file + :return: False if MS Cognitive serice returns error, otherwise the resulted texts will be returned + """ + texts = [] + my_uuid = uuid.uuid4() + headers = { + 'Content-type': 'audio/wav', + # 'Content-type': 'application/octet-stream', + 'samplerate': 16000, + 'Authorization': self.__accesstoken, + # 'codec': "audio/pcm", + } + params = urllibparse.urlencode({ + 'version': '3.0', + 'requestid': my_uuid, + 'appid': const.APP_ID, + 'format': 'json', + 'locale': self.__lang, + 'device.os': 'ubuntu', + 'scenarios': 'smd', + 'instanceid': my_uuid + }) + print(type(wf)) + if isinstance(wf, str): + body = open(wf, 'rb').read() + elif isinstance(wf, bytes): + body = wf + else: + return ''.join(texts) + #conn = httpclient.HTTPConnection('speech.platform.bing.com') + conn = httpclient.HTTPSConnection('speech.platform.bing.com') + conn.request('POST', '/recognize?%s' % params, body, headers) + response = conn.getresponse() + print(response) + data = json.loads(response.read().decode('utf-8')) + result = data['header']['status'] + if result != 'success': + print('INSIDE: STT failed') + return None + else: + outputs = data['results'] + for opt in outputs: + if float(opt['confidence']) > 0.65: + texts.append(opt['name']) + return ''.join(texts) + + +def main(): + wf_name = 'temp.wav' + ''' + spch = SpeechHelper(lang='en-US', gender='male') + + #res_text = spch.speech_to_text(wf_name) + #print(res_text) + #os.remove(wf_name) + ''' + + ''' + stream.start_stream() + while stream.is_active(): + sleep(0.1) + stream.stop_stream() + stream.close() + p.terminate() + ''' + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python-s/s/SpeechHelper.pyc b/mt7688-alsa/python-s/s/SpeechHelper.pyc new file mode 100755 index 00000000..f9e55939 Binary files /dev/null and b/mt7688-alsa/python-s/s/SpeechHelper.pyc differ diff --git a/mt7688-alsa/python-s/s/TrioAIHelper.py b/mt7688-alsa/python-s/s/TrioAIHelper.py new file mode 100755 index 00000000..18cd60a8 --- /dev/null +++ b/mt7688-alsa/python-s/s/TrioAIHelper.py @@ -0,0 +1,251 @@ +import sys +import json +import traceback +import paho.mqtt.client as mqtt +import paho.mqtt.publish as mqttpub +from time import sleep +from ctypes import * +import os +import time + +try: + import http.client as httplib + import urllib.parse as urlparse +except: + import httplib + import urllib as urlparse + +from SpeechHelper import SpeechHelper +#tmp for test +from CommandsFunc import * + + + +# Constants +DEFAULT_QOS = 2 +DEFAULT_KEEP_ALIVE = 60 +MQTT_BROKER_HOST = 'mq.imio.io' +MQTT_BROKER_PORT = 1883 + +class SinglePub(object): + + @staticmethod + def single_publish(topic, message, timeout=DEFAULT_KEEP_ALIVE): + mqttpub.single(topic, message, qos=DEFAULT_QOS, hostname=MQTT_BROKER_HOST, + port=MQTT_BROKER_PORT, keepalive=timeout) + print("-----------------already send") + +class TrioAIAgent(object): + def __init__(self, profile, lang='en-US', rob_gender='female'): + self.__profile = profile + self.__lang = lang + self.__gender = rob_gender + self.__uid = profile['UserId'] + self.__vid = profile['VisitorId'] + self.__ownership = profile['VisitorType'] + self.__chat_host = 'sandbox.sanjiaoshou.net' + self.__chat_url = 'http://sandbox.sanjiaoshou.net/Api/chat?who=demo&userID=imio_111&%s' + self.__cmd_lock_url = 'http://service.sanjiaoshou.net/Locker/index.php?f=locker' + self.__cmd_host = 'service.sanjiaoshou.net' + self.__headers = {'Content-Type': 'application/json',} + self.__session_start = False + return + + def set_userid(self, uid): + self.__uid = uid + + def set_visitor_id(self, vid): + self.__vid = vid + + def set_ownership(self, ownership): + self.__ownership = ownership + + def welcome(self): + entry_msg = self.front_door_text_conv(play=True) + if entry_msg is None: + return None + lock_state = entry_msg[0] + welcome_msg = entry_msg[1] + #print('lock state: ' + lock_state) + #print(welcome_msg) + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + stream = spch.text_to_speech(welcome_msg) + return stream + + def chat(self, query): + params = urlparse.urlencode({'sentence': query.encode('utf-8')}) + try: + url = self.__chat_url % params + conn = httplib.HTTPConnection(self.__chat_host) + #conn = httplib.HTTPSConnection(self.__chat_host) + conn.request("GET", url) + response = conn.getresponse().read() + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + print(data) + conn.close() + return data['reply'] + except Exception as e: + print(e) + return None + + def front_door_text_conv(self, query=None, play=False): + params = self.__profile + if query is not None: + params.update(query) + body = json.dumps(params) + try: + url = self.__cmd_lock_url + conn = httplib.HTTPConnection(self.__cmd_host) + #conn = httplib.HTTPSConnection(self.__cmd_host) + conn.request(method="POST", url=url, body=body, headers=self.__headers) + response = conn.getresponse().read() + print(response) + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + conn.close() + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + spch.text_to_speech(text_in=data['reply'], play=play) + return data['lockStatus'], data['reply'] + except Exception as e: + traceback.print_exc() + print(e) + return None + + +class FrontDoorScene(object): + def __init__(self, lang='en-US', rob_gender='female'): + self.__QoS = 2 + self.__lang = lang + self.__gender = rob_gender + self.__TOPIC = 'visitor_profile' + self.__cli = mqtt.Client() + self.__cli.on_connect = self.__connect_cb + self.__cli.on_message = self.__message_cb + self.__session_start = False + self.__visit_type = "stranger" + + def __connect_cb(self, client, userdata, flags, rc): + self.__cli.subscribe(self.__TOPIC, self.__QoS) + return + + def __message_cb(self, client, data, msg): + if msg.topic == self.__TOPIC: + print('Incoming message!') + payload = msg.payload + print(type(payload)) + raw_msg = payload.decode('utf-8') + print(type(raw_msg)) + print(raw_msg) + if sys.version.startswith('2'): + profile = json.loads(raw_msg).encode("utf-8") + else: + profile = json.loads(raw_msg) + print(profile) + self.__last_vid = profile["VistorId"] + self.__visit_type = profile["VistorType"] + if not self.__session_start: + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + return + + def visit_id(self): + return self.__last_vid + + def visit_type(self): + return self.__visit_type + + def is_session_started(self): + return self.__session_start + + def session_end(self): + self.__session_start = False + + def start(self, blocking=False, profile=None): + ''' + self.__cli.connect(host='mq.imio.io', port=1883) + if blocking: + self.__cli.loop_forever() + else: + self.__cli.loop_start() + ''' + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + + + + def stt(self, wf): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.speech_to_text(wf) + + def tts(self, text, play=False): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.text_to_speech(text_in=text, play=play) + + def ask_and_answer(self, query): + ans = self.__trio_ai.front_door_text_conv(query=query) + if ans is not None: + reply = ans[1] + print(reply) + return reply + else: + return None + + + +def main(): + #libsc = cdll.LoadLibrary(os.getcwd() + '/libmain.so') + os.system('chmod +x *.wav') + print ("Start!") + #my_profile = {"UserId":"10003","VisitorId":"Jim","VisitorType":"host"} + postman_profile = {"UserId":"10001","VisitorId":"unknown","VisitorType":"stranger", + "LockRecogDeliveryFlag": True} + visit = FrontDoorScene(lang='en-GB', rob_gender='male') + #visit.start() + #visit.start(profile=my_profile) + visit.start(profile=postman_profile) + while True: + if visit.is_session_started(): + ''' + #waiting for push the ring button + print ("Waiting the button push!") + #while (0 == libsc.get_button()): + #sleep(0.1) + print ("The button push!") + ring_bell = {'BellRingFlag': True} + visit.tts(visit.ask_and_answer(ring_bell), True) + sleep(0.5) + os.system('chmod +x *.wav') + #wf = open('temp.wav', 'rb') + #spt = visit.stt('temp.wav') + #open_door = {'Text': spt} + #print (spt) + # libsc.thread_rec() + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # open_door = {'Text': spt} + open_door = {'Text': 'Yes, I forgot my password'} + visit.tts(visit.ask_and_answer(open_door), True) + sleep(0.5) + unclocked = {"PasswdValidFlag": True} + visit.tts(visit.ask_and_answer(unclocked), True) + ''' + if visit.visit_type() == "host": + tmp_ = "hosttest" + elif visit.visit_type() == "family": + tmp_ = "familytest" + else: + tmp_ = "strangertest" + + func = ALL_FUNCS.get(tmp_, None) + if func: + func(visit, True) + visit.session_end() + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python-s/s/TrioAIHelper.pyc b/mt7688-alsa/python-s/s/TrioAIHelper.pyc new file mode 100755 index 00000000..141f64c5 Binary files /dev/null and b/mt7688-alsa/python-s/s/TrioAIHelper.pyc differ diff --git a/mt7688-alsa/python-s/s/__init__.py b/mt7688-alsa/python-s/s/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/mt7688-alsa/python-s/s/constants.py b/mt7688-alsa/python-s/s/constants.py new file mode 100755 index 00000000..c8ed8527 --- /dev/null +++ b/mt7688-alsa/python-s/s/constants.py @@ -0,0 +1,8 @@ +APP_ID = '950f8ca2-1b6e-41b3-a90c-c7775997603e' +APP_PWD = 'EWwjGB3hU47BfrqcGfYEKfC' + +MS_COG_HOST = 'westus.api.cognitive.microsoft.com' +COG_FACE_KEY = '0b1e119d7493471fa878f61214c31676' +COG_FACE_KEY_SEC = '5296e25a60b847239404c13e5b905a0a' +COG_SPEEKER_KEY = 'f4573d5f3a69422c828ac6f05bb1b687' +COG_STT_TTS_KEY = '50a64ed5fc0e4e4a999887c43fae9428' diff --git a/mt7688-alsa/python-s/s/constants.pyc b/mt7688-alsa/python-s/s/constants.pyc new file mode 100755 index 00000000..28770893 Binary files /dev/null and b/mt7688-alsa/python-s/s/constants.pyc differ diff --git a/mt7688-alsa/python-s/s/test.wav b/mt7688-alsa/python-s/s/test.wav new file mode 100755 index 00000000..f55cc3a7 Binary files /dev/null and b/mt7688-alsa/python-s/s/test.wav differ diff --git a/mt7688-alsa/python-s/test.wav b/mt7688-alsa/python-s/test.wav new file mode 100755 index 00000000..b01aa804 Binary files /dev/null and b/mt7688-alsa/python-s/test.wav differ diff --git a/mt7688-alsa/python/Makefile b/mt7688-alsa/python/Makefile new file mode 100755 index 00000000..d432fc94 --- /dev/null +++ b/mt7688-alsa/python/Makefile @@ -0,0 +1,10 @@ +BIN_FILE = libmain.so +OBJECTS = main.c record.c key.c oled_iic.c mem_gpio.c +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -shared -fpic -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine -lpthread \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include + +clean : + rm libmain.so *.o diff --git a/mt7688-alsa/python/Makefile2 b/mt7688-alsa/python/Makefile2 new file mode 100755 index 00000000..d432fc94 --- /dev/null +++ b/mt7688-alsa/python/Makefile2 @@ -0,0 +1,10 @@ +BIN_FILE = libmain.so +OBJECTS = main.c record.c key.c oled_iic.c mem_gpio.c +CC = mipsel-openwrt-linux-gcc + +$(BIN_FILE) : $(OBJECTS) + $(CC) -shared -fpic -o $(BIN_FILE) $(OBJECTS) -L /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/ipkg-install/usr/lib -L. -lasound -lm -lmp3lame -lshine -lpthread \ +-I /home/zyc/Documents/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/alsa-lib-1.0.28/include + +clean : + rm libmain.so *.o diff --git a/mt7688-alsa/python/SpeechHelper.py b/mt7688-alsa/python/SpeechHelper.py new file mode 100755 index 00000000..24dabe95 --- /dev/null +++ b/mt7688-alsa/python/SpeechHelper.py @@ -0,0 +1,203 @@ +import sys +import json +import wave +import uuid +import os +import time +from time import time +from os import environ as env +from xml.etree import ElementTree + +if sys.version.startswith('3'): + import http.client as httpclient + import urllib.parse as urllibparse +else: + import httplib as httpclient + import urllib as urllibparse +''' +IMIO_HOME = env.get('IMIO_HOME') +if IMIO_HOME is not None: + sys.path.append(IMIO_HOME) +''' +import constants as const + + +class SpeechHelper(object): + def __init__(self, lang='zh-CN', gender='female'): + self.__lang = lang + self.__gender = gender + self.__apiKey = const.COG_STT_TTS_KEY + self.__req_body = ElementTree.Element('speak', version='1.0') + self.__req_body.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice = ElementTree.SubElement(self.__req_body, 'voice') + self.__voice.set('{http://www.w3.org/XML/1998/namespace}lang', lang) + self.__voice.set('{http://www.w3.org/XML/1998/namespace}gender', gender) + self.__voice.set('name', 'Microsoft Server Speech Text to Speech Voice ' + self.__init_voice_font()) + #for e in self.__voice: + # print(type(e)) + # print(e) + self.__accesstoken = self.__init_access_token() + + def __init_access_token(self): + params = "" + get_token_headers = {"Ocp-Apim-Subscription-Key": self.__apiKey} + # AccessTokenUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; + AccessTokenHost = "api.cognitive.microsoft.com" + path = "/sts/v1.0/issueToken" + # Connect to server to get the Access Token + conn = httpclient.HTTPSConnection(AccessTokenHost) + conn.request("POST", path, params, get_token_headers) + response = conn.getresponse() + # print(response.status, response.reason) + data = response.read() + conn.close() + return data.decode("UTF-8") + + def __init_voice_font(self): + if self.__lang == 'zh-CN': + if self.__gender == 'female': + voicefont = '(zh-CN, Yaoyao, Apollo)' + else: + voicefont = '(zh-CN, Kangkang, Apollo)' + elif self.__lang == 'en-GB': + if self.__gender == 'female': + voicefont = '(en-GB, Susan, Apollo)' + else: + voicefont = '(en-GB, George, Apollo)' + elif self.__lang == 'es-ES': + if self.__gender == 'female': + voicefont = '(es-ES, Laura, Apollo)' + else: + voicefont = '(es-ES, Pablo, Apollo)' + elif self.__lang == 'en-IN': + voicefont = '(en-IN, Ravi, Apollo)' + else: + # default as US english + if self.__gender == 'female': + voicefont = '(en-US, ZiraRUS)' + else: + voicefont = '(en-US, BenjaminRUS)' + #voicefont = '(en-US, Eminem)' + return voicefont + + def text_to_speech(self, text_in, play=False): + """ + Convert input text to speech audio and play on microphone + :param text_in: + :return: + """ + if text_in is None: + return None + if sys.version.startswith('2'): + if not isinstance(text_in, unicode): + self.__voice.text = unicode(text_in, 'utf-8') + else: + self.__voice.text = text_in + else: + self.__voice.text = text_in + headers = {"Content-type": "application/ssml+xml", + "X-Microsoft-OutputFormat": "riff-16khz-16bit-mono-pcm", + "Authorization": "Bearer " + self.__accesstoken, + "X-Search-AppId": "07D3234E49CE426DAA29772419F436CA", + "X-Search-ClientID": "1ECFAE91408841A480F00935DC390960", + "User-Agent": "TTSForPython"} + # Connect to server to synthesize the wave + conn = httpclient.HTTPSConnection("speech.platform.bing.com") + conn.request("POST", "/synthesize", ElementTree.tostring(self.__req_body), headers) + response = conn.getresponse() + data = response.read() + conn.close() + #print('stream is:') + #print(data) + + if play: + ''' + import pyaudio + #print('Playing speech') + p = pyaudio.PyAudio() + stream = p.open(format=pyaudio.paInt16, + channels=1, + rate=16000, + output=True, + frames_per_buffer=1024) + stream.write(data) + stream.close() + ''' + wfname = "test.wav" + wf = wave.open(wfname, 'wb') + wf.setnchannels(1) + wf.setsampwidth(2) + wf.setframerate(16000) + wf.writeframesraw(data) + wf.close() + os.system('chmod +x *.wav') + os.system('aplay ./test.wav') + #os.system('aplay ./what.wav') + #os.system('ls') + + + return data + + def speech_to_text(self, wf): + """ + Convert the speech audio data to text + :param wf: wave file name, or the actual stream data from a wave file + :return: False if MS Cognitive serice returns error, otherwise the resulted texts will be returned + """ + texts = [] + my_uuid = uuid.uuid4() + headers = { + 'Content-type': 'audio/wav', + # 'Content-type': 'application/octet-stream', + 'samplerate': 16000, + 'Authorization': self.__accesstoken, + # 'codec': "audio/pcm", + } + params = urllibparse.urlencode({ + 'version': '3.0', + 'requestid': my_uuid, + 'appid': const.APP_ID, + 'format': 'json', + 'locale': self.__lang, + 'device.os': 'ubuntu', + 'scenarios': 'smd', + 'instanceid': my_uuid + }) + print(type(wf)) + if isinstance(wf, str): + body = open(wf, 'rb').read() + elif isinstance(wf, bytes): + body = wf + else: + return ''.join(texts) + conn = httpclient.HTTPSConnection('speech.platform.bing.com') + conn.request('POST', '/recognize?%s' % params, body, headers) + response = conn.getresponse() + print(response) + data = json.loads(response.read().decode('utf-8')) + result = data['header']['status'] + if result != 'success': + print('INSIDE: STT failed') + return None + else: + outputs = data['results'] + for opt in outputs: + if float(opt['confidence']) > 0.65: + texts.append(opt['name']) + return ''.join(texts) + + +def main(): + wf_name = 'temp.wav' + + spch = SpeechHelper(lang='en-US', gender='male') + + res_text = spch.text_to_speech('Hello world',True) + #print(res_text) + #os.remove(wf_name) + + + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python/SpeechHelper.pyc b/mt7688-alsa/python/SpeechHelper.pyc new file mode 100755 index 00000000..d9d34f7c Binary files /dev/null and b/mt7688-alsa/python/SpeechHelper.pyc differ diff --git a/mt7688-alsa/python/TrioAIHelper.py b/mt7688-alsa/python/TrioAIHelper.py new file mode 100755 index 00000000..468ed545 --- /dev/null +++ b/mt7688-alsa/python/TrioAIHelper.py @@ -0,0 +1,204 @@ +import sys +import json +import traceback +import paho.mqtt.client as mqtt +from time import sleep +from ctypes import * +import os +import time + +try: + import http.client as httplib + import urllib.parse as urlparse +except: + import httplib + import urllib as urlparse + +from SpeechHelper import SpeechHelper + + +class TrioAIAgent(object): + def __init__(self, profile, lang='en-US', rob_gender='female'): + self.__profile = profile + self.__lang = lang + self.__gender = rob_gender + self.__uid = profile['UserId'] + self.__vid = profile['VisitorId'] + self.__ownership = profile['VisitorType'] + self.__chat_host = 'sandbox.sanjiaoshou.net' + self.__chat_url = 'http://sandbox.sanjiaoshou.net/Api/chat?who=demo&userID=imio_111&%s' + self.__cmd_lock_url = 'http://service.sanjiaoshou.net/Locker/index.php?f=locker' + self.__cmd_host = 'service.sanjiaoshou.net' + self.__headers = {'Content-Type': 'application/json',} + self.__session_start = False + return + + def set_userid(self, uid): + self.__uid = uid + + def set_visitor_id(self, vid): + self.__vid = vid + + def set_ownership(self, ownership): + self.__ownership = ownership + + def welcome(self): + entry_msg = self.front_door_text_conv(play=True) + if entry_msg is None: + return None + lock_state = entry_msg[0] + welcome_msg = entry_msg[1] + #print('lock state: ' + lock_state) + #print(welcome_msg) + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + stream = spch.text_to_speech(welcome_msg) + return stream + + def chat(self, query): + params = urlparse.urlencode({'sentence': query.encode('utf-8')}) + try: + url = self.__chat_url % params + conn = httplib.HTTPConnection(self.__chat_host) + conn.request("GET", url) + response = conn.getresponse().read() + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + print(data) + conn.close() + return data['reply'] + except Exception as e: + print(e) + return None + + def front_door_text_conv(self, query=None, play=False): + params = self.__profile + if query is not None: + params.update(query) + body = json.dumps(params) + try: + url = self.__cmd_lock_url + conn = httplib.HTTPConnection(self.__cmd_host) + conn.request(method="POST", url=url, body=body, headers=self.__headers) + response = conn.getresponse().read() + print(response) + if response is None or len(response) == 0: + return None + data = json.loads(response.decode('utf-8')) + conn.close() + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + spch.text_to_speech(text_in=data['reply'], play=play) + return data['lockStatus'], data['reply'] + except Exception as e: + traceback.print_exc() + print(e) + return None + + +class FrontDoorScene(object): + def __init__(self, lang='en-US', rob_gender='female'): + self.__QoS = 2 + self.__lang = lang + self.__gender = rob_gender + self.__TOPIC = 'visitor_profile' + self.__cli = mqtt.Client() + self.__cli.on_connect = self.__connect_cb + self.__cli.on_message = self.__message_cb + self.__session_start = False + + def __connect_cb(self, client, userdata, flags, rc): + self.__cli.subscribe(self.__TOPIC, self.__QoS) + return + + def __message_cb(self, client, data, msg): + if msg.topic == self.__TOPIC: + print('Incoming message!') + payload = msg.payload + print(type(payload)) + raw_msg = payload.decode('utf-8') + print(type(raw_msg)) + print(raw_msg) + profile = json.loads(raw_msg) + print(profile) + if not self.__session_start: + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + return + + def is_session_started(self): + return self.__session_start + + def session_end(self): + self.__session_start = False + + def start(self, blocking=False, profile=None): + ''' + self.__cli.connect(host='mq.imio.io', port=1883) + if blocking: + self.__cli.loop_forever() + else: + self.__cli.loop_start() + ''' + self.__trio_ai = TrioAIAgent(profile, lang=self.__lang, rob_gender=self.__gender) + self.__trio_ai.welcome() + self.__session_start = True + + + + def stt(self, wf): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.speech_to_text(wf) + + def tts(self, text, play=False): + spch = SpeechHelper(lang=self.__lang, gender=self.__gender) + return spch.text_to_speech(text_in=text, play=play) + + def ask_and_answer(self, query): + ans = self.__trio_ai.front_door_text_conv(query=query) + if ans is not None: + reply = ans[1] + print(reply) + return reply + else: + return None + + +def main(): + #libsc = cdll.LoadLibrary(os.getcwd() + '/libmain.so') + + print ("Start!") + my_profile = {"UserId":"10003","VisitorId":"Jim","VisitorType":"host"} + visit = FrontDoorScene(lang='en-GB', rob_gender='male') + #visit.start() + visit.start(profile=my_profile) + sleep(0.5) + while True: + if visit.is_session_started(): + #waiting for push the ring button + print ("Waiting the button push!") + # while (0 == libsc.get_button()): + # sleep(0.1) + print ("The button push!") + ring_bell = {'BellRingFlag': True} + visit.tts(visit.ask_and_answer(ring_bell), True) + sleep(0.5) + # os.system('chmod +x *.wav') + # wf = open('temp.wav', 'rb') + # spt = visit.stt('temp.wav') + # open_door = {'Text': spt} + print (spt) + # libsc.thread_rec() + # wf = open('test.wav', 'rb') + # spt = visit.stt('test.wav') + # open_door = {'Text': spt} + open_door = {'Text': 'Yes, I forgot my password'} + visit.tts(visit.ask_and_answer(open_door), True) + sleep(0.5) + unclocked = {"PasswdValidFlag": True} + visit.tts(visit.ask_and_answer(unclocked), True) + visit.session_end() + + +if __name__ == '__main__': + main() diff --git a/mt7688-alsa/python/__init__.py b/mt7688-alsa/python/__init__.py new file mode 100755 index 00000000..e69de29b diff --git a/mt7688-alsa/python/__pycache__/SpeechHelper.cpython-35.pyc b/mt7688-alsa/python/__pycache__/SpeechHelper.cpython-35.pyc new file mode 100644 index 00000000..38207562 Binary files /dev/null and b/mt7688-alsa/python/__pycache__/SpeechHelper.cpython-35.pyc differ diff --git a/mt7688-alsa/python/__pycache__/constants.cpython-35.pyc b/mt7688-alsa/python/__pycache__/constants.cpython-35.pyc new file mode 100644 index 00000000..4909ab50 Binary files /dev/null and b/mt7688-alsa/python/__pycache__/constants.cpython-35.pyc differ diff --git a/mt7688-alsa/python/big_or_little.c b/mt7688-alsa/python/big_or_little.c new file mode 100755 index 00000000..c4255bd2 --- /dev/null +++ b/mt7688-alsa/python/big_or_little.c @@ -0,0 +1,21 @@ +#include +//жϲϵͳǴ˻С +bool IsBig_Edian() +{ + union my + { + int a; + char b; +int c; + }; + union my t; + t.a=0x12345678;//union÷ʱ + if(t.c==0x78){ + return 1; + } +} +int main() +{ + printf("%d\n",IsBig_Edian()); + return 0; +} \ No newline at end of file diff --git a/mt7688-alsa/python/codetab.h b/mt7688-alsa/python/codetab.h new file mode 100755 index 00000000..297e9f01 --- /dev/null +++ b/mt7688-alsa/python/codetab.h @@ -0,0 +1,490 @@ +#ifndef _CODETAB_H_ +#define _CODETAB_H_ + +/***************************16*16*********/ +unsigned char F16x16[] = +{ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ + +0x00,0x02,0x02,0xFA,0xFA,0xAA,0xAA,0xFF,0xFF,0xAA,0xAA,0xFA,0xFA,0x02,0x02,0x00, +0x00,0x42,0x72,0x72,0x3A,0x7A,0x42,0x4B,0x5B,0x52,0x62,0x62,0x13,0x77,0x66,0x00,/*"",1*/ + +0x20,0x3C,0x1C,0xFF,0xFF,0xB0,0xB4,0x24,0x24,0x3F,0x3F,0xE4,0xE4,0x24,0x24,0x20, +0x02,0x02,0x03,0xFF,0xFF,0x00,0x01,0x05,0x1D,0x59,0xC1,0xFF,0x7F,0x01,0x01,0x01,/*"",2*/ + +0x00,0x00,0x00,0xF8,0xF8,0x48,0x4C,0x4F,0x4B,0x4A,0x48,0x48,0xF8,0xF8,0x00,0x00, +0x00,0x00,0x00,0xFF,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0xFF,0x00,0x00,/*"",3*/ + +0x20,0x24,0x24,0xE4,0xE4,0x24,0x24,0x24,0x30,0x10,0xFF,0xFF,0x10,0xF0,0xF0,0x00, +0x08,0x1C,0x1F,0x0B,0x0C,0x0D,0x4F,0x6E,0x34,0x1C,0x0F,0x23,0x60,0x7F,0x3F,0x00,/*"",4*/ + +0x80,0xC0,0x60,0xF8,0xFF,0x07,0x02,0x00,0xFF,0xFF,0xE0,0x70,0x3C,0x1C,0x08,0x00, +0x00,0x00,0x00,0x7F,0x7F,0x04,0x06,0x03,0x3F,0x7F,0x40,0x40,0x40,0x78,0x78,0x00,/*"",5*/ + +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",7*/ + + +0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, +0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00,/*"",8*/ +0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, +0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00,/*"",9*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",10*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",11*/ +0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00, +0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00,/*"",12*/ +0x00,0x04,0x74,0xD4,0xFF,0xD4,0x74,0x04,0x10,0x0C,0xB7,0x44,0xB4,0x0C,0x04,0x00, +0x00,0x42,0x43,0x7A,0x43,0x42,0x43,0x7E,0x4B,0x4B,0x4A,0x4A,0x42,0x43,0x01,0x00,/*"",13*/ +0x08,0x08,0x08,0x08,0x08,0x08,0xF9,0x4A,0x4C,0x48,0x48,0xC8,0x08,0x08,0x08,0x00, +0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,/*"",14*/ +0x00,0x20,0x2C,0x24,0x64,0x74,0xAD,0xA6,0xE4,0x34,0x24,0x24,0x2C,0x24,0x00,0x00, +0x00,0x24,0x24,0x25,0x15,0x15,0x0D,0xFE,0x04,0x0D,0x17,0x14,0x24,0x64,0x24,0x00,/*"",15*/ + + +0x00,0x00,0x00,0xF8,0x48,0x48,0x4C,0x4B,0x4A,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x00,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,/*"",16*/ +0x20,0x24,0x24,0xE4,0x24,0x24,0x24,0x20,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00, +0x08,0x1C,0x0B,0x08,0x0C,0x05,0x4E,0x24,0x10,0x0C,0x03,0x20,0x40,0x3F,0x00,0x00,/*"",17*/ +0x08,0x08,0x08,0xFF,0x88,0x48,0x00,0x98,0x48,0x28,0x0A,0x2C,0x48,0xD8,0x08,0x00, +0x02,0x42,0x81,0x7F,0x00,0x00,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00,/*"",18*/ +0x00,0x50,0x4F,0x4A,0x48,0xFF,0x48,0x48,0x48,0x00,0xFC,0x00,0x00,0xFF,0x00,0x00, +0x00,0x00,0x3F,0x01,0x01,0xFF,0x21,0x61,0x3F,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,/*"",19*/ +0x08,0x07,0xFA,0xAA,0xAE,0xAA,0xAA,0xA8,0xAC,0xAB,0xAA,0xFE,0x0A,0x02,0x02,0x00, +0x08,0x08,0x8B,0x6A,0x1E,0x0A,0x0A,0x0A,0x0A,0xFE,0x0A,0x0B,0x08,0x08,0x08,0x00,/*"",20*/ +0x10,0x60,0x01,0xC6,0x30,0x00,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x04,0x04,0xFE,0x01,0x00,0x41,0x61,0x51,0x4D,0x43,0x41,0x41,0x51,0xE1,0x01,0x00,/*"",21*/ +0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00, +0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,/*"",22*/ +0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00, +0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"",23*/ + + +0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, +0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,/*"",24*/ +0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00, +0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"",25*/ +0x00,0x20,0x20,0x22,0x22,0xE2,0x22,0x22,0x22,0xE2,0x22,0x22,0x22,0x20,0x20,0x00, +0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,/*"Ԫ",26*/ +0x40,0x20,0xF8,0x0F,0x82,0x60,0x1E,0x14,0x10,0xFF,0x10,0x10,0x10,0x10,0x00,0x00, +0x00,0x00,0xFF,0x00,0x01,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x01,0x00,/*"",27*/ +0x00,0x00,0x00,0x00,0x7E,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0xCC,0x08,0x00, +0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x24,0x46,0x44,0x20,0x1F,0x00,0x00,/*"",28*/ +0x84,0x94,0x94,0xFF,0x94,0x94,0x80,0x24,0x24,0x24,0xFC,0x12,0x13,0x12,0x00,0x00, +0x20,0x18,0x06,0xFF,0x02,0x1C,0x0A,0x02,0x02,0x02,0x3F,0x41,0x41,0x41,0x71,0x00,/*"",29*/ +0x10,0x10,0xD0,0xFE,0x50,0x90,0x00,0x10,0x10,0x10,0xD0,0xFE,0x10,0x10,0x10,0x00, +0x08,0x06,0x01,0xFF,0x00,0x01,0x10,0x08,0x04,0x43,0x80,0x7F,0x00,0x00,0x00,0x00,/*"",30*/ +0x90,0x88,0xA7,0xA2,0xA6,0xBA,0xA2,0xF8,0xA7,0xA2,0xA6,0xBA,0xA2,0x82,0x80,0x00, +0x00,0x04,0x04,0x04,0x04,0x0C,0x34,0x04,0x44,0x84,0x7F,0x04,0x04,0x04,0x00,0x00,/*"",31*/ +}; + +/************************************6*8************************************/ +const unsigned char F6x8[][6] = +{ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp +0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! +0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " +0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # +0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ +0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % +0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & +0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' +0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( +0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) +0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * +0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + +0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , +0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - +0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . +0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / +0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 +0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 +0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 +0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 +0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 +0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 +0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 +0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 +0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 +0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 +0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : +0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; +0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < +0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = +0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > +0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? +0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ +0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A +0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B +0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C +0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D +0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E +0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F +0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G +0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H +0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I +0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J +0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K +0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L +0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M +0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N +0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O +0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P +0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q +0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R +0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S +0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T +0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U +0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V +0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W +0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X +0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y +0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z +0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ +0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 +0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] +0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ +0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ +0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' +0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a +0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b +0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c +0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d +0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e +0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f +0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g +0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h +0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i +0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j +0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k +0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l +0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m +0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n +0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o +0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p +0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q +0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r +0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s +0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t +0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u +0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v +0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w +0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x +0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y +0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z +0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +}; + +/****************************************8*16ĵ************************************/ +const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; + +unsigned char BMP1[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xC7,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00, + 0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x40,0x40, + 0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00, + 0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB,0xDB,0xDB,0xDB,0x00,0x00,0xDB,0xDB, + 0xDB,0xDB,0xDB,0x00,0x00,0xDA,0xDA,0xDA,0xDA,0xDA,0x00,0x00,0xD8,0xD8,0xD8,0xD8, + 0xD8,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00, + 0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06, + 0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0xE6,0x66,0x20,0x00,0x06,0x06,0x86,0x06, + 0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x86,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00, + 0x00,0x86,0x86,0x86,0x86,0x86,0x80,0x80,0x86,0x86,0x06,0x86,0x86,0xC0,0xC0,0x86, + 0x86,0x86,0x06,0x06,0xD0,0x30,0x76,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06, + 0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x06,0x06,0x06,0x06,0x06, + 0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x1C,0x00,0xFE,0x00,0x01, + 0x02,0x00,0xC4,0x18,0x20,0x02,0x9E,0x63,0xB2,0x0E,0x00,0xFF,0x81,0x81,0xFF,0x00, + 0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0xFF,0x00,0x23,0xEA,0xAA,0xBF,0xAA, + 0xEA,0x03,0x3F,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0C,0x08,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x81,0x80,0x80,0x81,0x80, + 0x81,0x80,0x80,0x80,0x80,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, + 0x01,0x00,0x01,0x01,0x09,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0, + 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00, + 0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E,0x00,0x1E,0x21,0x40,0x40,0x50,0x21,0x5E, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xC1,0xC1,0xFF, + 0xFF,0xC1,0xC1,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0xFC,0xF3,0xEF,0xF3,0xFC, + 0x80,0xFF,0x80,0xEE,0xEE,0xEE,0xF5,0xFB,0xFF,0x9C,0xBE,0xB6,0xB6,0x88,0xFF,0x00,/*"D:\DreamSpark\OLED\MP3_UI.bmp",0*/ +}; + +unsigned char BMP2[] = +{ + 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, + 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D, + 0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8, + 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0xF8,0x18,0x60,0x80,0x00,0x00,0x00,0x80, + 0x60,0x18,0xF8,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0xE0, + 0x10,0x08,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x20,0x20,0xF8,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x88,0x68, + 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F, + 0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06,0x01, + 0x00,0x00,0x7F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x00,0x1F, + 0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00, + 0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x06,0x01,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0xE0,0x20,0x20,0x20, + 0xE0,0x00,0x00,0x00,0x40,0xE0,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x20,0xE0,0x00, + 0x00,0x00,0x00,0x00,0xE0,0x20,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20, + 0x20,0x20,0xC0,0x00,0x00,0x40,0x20,0x20,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x0F,0x08,0x08,0x08, + 0x0F,0x00,0x00,0x00,0x08,0x0F,0x08,0x00,0x00,0x00,0x0C,0x08,0x09,0x09,0x0E,0x00, + 0x00,0x0C,0x00,0x00,0x0F,0x09,0x09,0x09,0x0F,0x00,0x00,0x0C,0x00,0x00,0x0C,0x0A, + 0x0A,0x09,0x0C,0x00,0x00,0x0C,0x0A,0x0A,0x09,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80, + 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00, + 0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA, + 0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F, + 0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00, +}; + +unsigned char BMP3[] = { + 0x08,0x08,0x08,0x08,0x1C,0x1C,0x1C,0x1C,0x3E,0x3E,0x3E,0x3E,0x7F,0x7F,0x3E,0x3E, + 0x3E,0x3E,0x1C,0x1C,0x1C,0x1C,0x08,0x08,0x08,0x08,/*"C:\Users\zyc\Documents\flash.BMP",0*/ +}; + +unsigned char BMP4[] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xE0,0xE0 , + 0xE0,0xE0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x03,0x03,0x03,0x03,0x07,0x07,0x03,0x03 , + 0x03,0x03,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 , + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,/*"C:\Users\zyc\Documents\flash.BMP",0*/ +}; + +#endif diff --git a/mt7688-alsa/python/constants.py b/mt7688-alsa/python/constants.py new file mode 100755 index 00000000..c8ed8527 --- /dev/null +++ b/mt7688-alsa/python/constants.py @@ -0,0 +1,8 @@ +APP_ID = '950f8ca2-1b6e-41b3-a90c-c7775997603e' +APP_PWD = 'EWwjGB3hU47BfrqcGfYEKfC' + +MS_COG_HOST = 'westus.api.cognitive.microsoft.com' +COG_FACE_KEY = '0b1e119d7493471fa878f61214c31676' +COG_FACE_KEY_SEC = '5296e25a60b847239404c13e5b905a0a' +COG_SPEEKER_KEY = 'f4573d5f3a69422c828ac6f05bb1b687' +COG_STT_TTS_KEY = '50a64ed5fc0e4e4a999887c43fae9428' diff --git a/mt7688-alsa/python/constants.pyc b/mt7688-alsa/python/constants.pyc new file mode 100755 index 00000000..87463ef3 Binary files /dev/null and b/mt7688-alsa/python/constants.pyc differ diff --git a/mt7688-alsa/python/key.c b/mt7688-alsa/python/key.c new file mode 100755 index 00000000..1b669d1d --- /dev/null +++ b/mt7688-alsa/python/key.c @@ -0,0 +1,39 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include "mem_gpio.h" +#include "key.h" + + +//init GPIO port +void init_button_gpio() +{ + if (gpio_mmap()) + printf("gpio_mmap() error!\n"); + + //printf("set pin BUTTON input 0\n"); + //mt76x8_gpio_set_pin_direction(BUTTON, 1); + //mt76x8_gpio_set_pin_value(BUTTON, 0); + + mt76x8_gpio_set_pin_direction(BUTTON, 0); + //printf("get pin BUTTON input %d\n", mt76x8_gpio_get_pin(BUTTON)); +} + +int read_button() +{ + if (0 == mt76x8_gpio_get_pin(BUTTON)) + { + return 0; + } + else if (1 == mt76x8_gpio_get_pin(BUTTON)) + { + return 1; + } + //close(gpio_mmap_fd); + + return 0; +} + diff --git a/mt7688-alsa/python/key.h b/mt7688-alsa/python/key.h new file mode 100755 index 00000000..d35d7e7c --- /dev/null +++ b/mt7688-alsa/python/key.h @@ -0,0 +1,16 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _KEY_H_ +#define _KEY_H_ + + +#define BUTTON 40 + + +void init_button_gpio(); +int read_button(); + +#endif diff --git a/mt7688-alsa/python/libasound.so b/mt7688-alsa/python/libasound.so new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/python/libasound.so differ diff --git a/mt7688-alsa/python/libasound.so.2 b/mt7688-alsa/python/libasound.so.2 new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/python/libasound.so.2 differ diff --git a/mt7688-alsa/python/libasound.so.2.0.0 b/mt7688-alsa/python/libasound.so.2.0.0 new file mode 100755 index 00000000..2d7690bb Binary files /dev/null and b/mt7688-alsa/python/libasound.so.2.0.0 differ diff --git a/mt7688-alsa/python/libmain.so b/mt7688-alsa/python/libmain.so new file mode 100755 index 00000000..e697951e Binary files /dev/null and b/mt7688-alsa/python/libmain.so differ diff --git a/mt7688-alsa/python/libmp3lame.so b/mt7688-alsa/python/libmp3lame.so new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/python/libmp3lame.so differ diff --git a/mt7688-alsa/python/libmp3lame.so.0 b/mt7688-alsa/python/libmp3lame.so.0 new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/python/libmp3lame.so.0 differ diff --git a/mt7688-alsa/python/libmp3lame.so.0.0.0 b/mt7688-alsa/python/libmp3lame.so.0.0.0 new file mode 100755 index 00000000..5c91e77d Binary files /dev/null and b/mt7688-alsa/python/libmp3lame.so.0.0.0 differ diff --git a/mt7688-alsa/python/main b/mt7688-alsa/python/main new file mode 100755 index 00000000..f4788ebd Binary files /dev/null and b/mt7688-alsa/python/main differ diff --git a/mt7688-alsa/python/main-back.c b/mt7688-alsa/python/main-back.c new file mode 100755 index 00000000..f9413973 --- /dev/null +++ b/mt7688-alsa/python/main-back.c @@ -0,0 +1,249 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include +#include +#include "mem_gpio.h" +#include "key.h" +#include "oled_iic.h" +#include "record.h" +#include "cJSON.h" +#include "call_python.h" + + +//extern oled_iic.c variable +extern unsigned char BMP1[]; +extern unsigned char BMP2[]; +extern unsigned char BMP3[]; +extern unsigned char BMP4[]; + +int scan_button = 1; +int key_num = 1; + +/*************************************************************** +* test c +***************************************************************/ +void test_button() +{ + init_button_gpio(); + + while (1) + { + if (0 == read_button()) + { + printf("Button not push ! \n"); + } + if (1 == read_button()) + { + printf("Button push! \n"); + } + sleep(2); + } + + close_gpio(); +} + +void test_oled() +{ + unsigned char i; + + init_gpio(); + OLED_Init(); //OLED init + + // OLED_Fill(0xff); // + // sleep(5); + // OLED_Fill(0x00); // + // sleep(5); + + while (1) + { + printf("Begin! \n"); + OLED_P16x16Ch(24,0,1); + OLED_P16x16Ch(40,0,2); + OLED_P16x16Ch(57,0,3); + OLED_P16x16Ch(74,0,4); + OLED_P16x16Ch(91,0,5); + for(i=0; i<8; i++)// + { +// OLED_P16x16Ch(i*16,0,i); + OLED_P16x16Ch(i*16,2,i+8); + OLED_P16x16Ch(i*16,4,i+16); + OLED_P16x16Ch(i*16,6,i+24); + } + sleep(4); + OLED_CLS();// + + OLED_P8x16Str(0,0,"HelTec");//delay + OLED_P8x16Str(0,2,"OLED Display"); + OLED_P8x16Str(0,4,"www.heltec.cn"); + OLED_P6x8Str(0,6,"cn.heltec@gmail.com"); + OLED_P6x8Str(0,7,"heltec.taobao.com"); + sleep(4); + OLED_CLS(); + + Draw_BMP(0,0,128,8,BMP1); // + sleep(8); + Draw_BMP(0,0,128,8,BMP2); + sleep(8); + OLED_CLS(); + } + + close_gpio(); +} + +void test_cjson() +{ + char *product_id = "mt7687_a"; + char *dev_id = "zhuyunchun-1a"; + char *dev_key = "b23c34bacedd3548435d92d405a88afb"; + char *out; + + cJSON *root_reg; + cJSON *signup_req; + root_reg = cJSON_CreateObject(); + cJSON_AddItemToObject(root_reg, "signin_req", signup_req = cJSON_CreateObject()); + cJSON_AddStringToObject(signup_req, "product_id", product_id); + cJSON_AddStringToObject(signup_req, "dev_id", dev_id); + cJSON_AddStringToObject(signup_req, "dev_key", dev_key); + out = cJSON_Print(root_reg); /* Print to text */ + cJSON_Delete(root_reg); /* Delete the cJSON object */ + printf("The json date out = %s\n", out); +} + +void display_oled() +{ + unsigned char i; + + OLED_P8x16Str(0,0,"Processing...");//delay + + while (key_num) + { + //printf("Begin! \n"); + for (i = 0; i < 102; i += 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + //OLED_CLS(); + } + for (i = 102; i > 0; i -= 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + //OLED_CLS(); + } + //key_num--; + } + + OLED_CLS(); + key_num = 1; + scan_button = 1; + pthread_exit(0); + //close_gpio(); +} + +void thread_rec() +{ + record_main(); + //sleep(4); //rec + key_num = 0; + printf("thread_rec() finish ! \n"); + + pthread_exit(0); +} + +void thread_key() +{ + pthread_t id_dis, id_rec; + int ret_dis, ret_rec; + + while (1) + { + if(scan_button) + { + if (0 == read_button()) + { + //printf("Button not push ! \n"); + OLED_CLS(); + //sleep(2); + } + else if (1 == read_button()) + { + printf("Button push ! \n"); + scan_button = 0; + ret_dis = pthread_create(&id_dis, NULL, (void *)display_oled, NULL); + if (ret_dis != 0) + { + printf("Create the pthread_dis error!\n"); + } + ret_rec = pthread_create(&id_rec, NULL, (void *)thread_rec, NULL); + if (ret_rec != 0) + { + printf("Create the pthread_rec error!\n"); + } + } + } + //printf("thread_key()\n"); + usleep(20000);//sleep 20ms + } + + pthread_exit(0); +} + +void thread_ai() +{ + int call_ret; + sleep(3); + + //while (1) + //{ + printf("thread_ai()\n"); + call_ret = call_main("getContext", "getSentences", "test.wav", "10"); + printf("call_ret = %d\n", call_ret); + if (call_ret < 0) + { + printf("call python error!\n"); + } + //sleep(30);//sleep 30s + //} + + pthread_exit(0); +} + +/*========================= MAIN ====================================*/ +int main(int argc, char* argv[]) +{ + pthread_t id_key, id_ai; + int ret_key, ret_ai; + + //init func + init_gpio(); + init_button_gpio(); + OLED_Init(); //OLED init + OLED_CLS();// + + ret_ai = pthread_create(&id_ai, NULL, (void *)thread_ai, NULL); + if (ret_ai != 0) + { + printf("Create the pthread_ai error!\n"); + } + + ret_key = pthread_create(&id_key, NULL, (void *)thread_key, NULL); + if (ret_key != 0) + { + printf("Create the pthread_key error!\n"); + } + + while(1) + { + sleep(2); + printf("I am main thread!\n"); + } + + + + return 0; +} diff --git a/mt7688-alsa/python/main.c b/mt7688-alsa/python/main.c new file mode 100755 index 00000000..70f8d8d2 --- /dev/null +++ b/mt7688-alsa/python/main.c @@ -0,0 +1,164 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include +#include +#include +#include "main.h" +#include "mem_gpio.h" +#include "key.h" +#include "oled_iic.h" +#include "record.h" + + +//extern oled_iic.c variable +extern unsigned char BMP1[]; +extern unsigned char BMP2[]; +extern unsigned char BMP3[]; +extern unsigned char BMP4[]; + +int display_time; + +/***************************************************************/ +int get_button() +{ + int ret; + init_button_gpio(); + + if (0 == read_button()) + { + printf("Button not push ! \n"); + ret = 0; + } + if (1 == read_button()) + { + printf("Button push! \n"); + ret = 1; + } + + //close_gpio(); + + return ret; +} + +void clear_display() +{ + init_gpio(); + OLED_Init(); + OLED_CLS(); + OLED_CLS(); +} + +void display_oled_string() +{ + init_gpio(); + OLED_Init(); + OLED_CLS(); + OLED_P8x16Str(0,0,"Processing...");//delay +} + +int test_display_oled() +{ + int num = 3; + unsigned char i; + + init_gpio(); + OLED_Init(); + OLED_P8x16Str(0,0,"Listening...");//delay + + while (num--) + { + for (i = 0; i < 102; i += 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + } + for (i = 102; i > 0; i -= 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + } + //sleep(1); + } + + OLED_CLS(); + //close_gpio(); + + return 1; +} + +int display_oled() +{ + unsigned char i; + int num; + + init_gpio(); + OLED_Init(); + OLED_P8x16Str(0,0,"Listening...");//delay + + while (display_time) + { + for (i = 0; i < 102; i += 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + } + for (i = 102; i > 0; i -= 2) //26 128 + { + Draw_BMP(i, 4, 128 + i, 5, BMP3); //64 8*8 + usleep(20000);//20ms + } + //sleep(1); + } + + OLED_CLS(); + //close_gpio(); + + pthread_exit(0); + //return 1; +} + +int thread_rec() +{ + pthread_t id_dis; + int ret, ret_dis; + + display_time = 1; + printf("thread_rec() begin ! \n"); + + ret_dis = pthread_create(&id_dis, NULL, (void *)display_oled, NULL); + if (ret_dis != 0) + { + printf("Create the pthread_dis error!\n"); + } + + ret = record_main(); + if (ret < 0) + { + printf("record_main() error ! \n"); + return 0; + } + display_time = 0; + //sleep(1); + printf("thread_rec() finish ! \n"); + + return 1; +} + +/*========================= MAIN ====================================*/ +int main(int argc, char* argv[]) +{ + + test_display_oled(); + + while(1) + { + sleep(2); + printf("I am main thread!\n"); + } + + return 0; +} diff --git a/mt7688-alsa/python/main.h b/mt7688-alsa/python/main.h new file mode 100755 index 00000000..5dfceb88 --- /dev/null +++ b/mt7688-alsa/python/main.h @@ -0,0 +1,21 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _MAIN_H_ +#define _MAIN_H_ + + +//extern int display_time; +//./config --prefix=/home/zyc/Documents/openssl-1.1.0e/build --cross-compile-prefix=mipsel-openwrt-linux-uclibc- shared no-asm +//------------------- functions declaration ---------------------- +int get_button(); +void clear_display(); +int test_display_oled(); +int display_oled(); +int thread_rec(); +void clear_display(); +void display_oled_string(); + +#endif \ No newline at end of file diff --git a/mt7688-alsa/python/mem_gpio.c b/mt7688-alsa/python/mem_gpio.c new file mode 100755 index 00000000..a3f4ae62 --- /dev/null +++ b/mt7688-alsa/python/mem_gpio.c @@ -0,0 +1,157 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include "mem_gpio.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +uint8_t* gpio_mmap_reg = NULL; +int gpio_mmap_fd = 0; + + +/** + * mem remap + * @return + */ +int gpio_mmap(void) +{ + if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) + { + fprintf(stderr, "unable to open mmap file"); + return -1; + } + + gpio_mmap_reg = (uint8_t *) mmap(NULL, 1024, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, gpio_mmap_fd, 0x10000000); + if (gpio_mmap_reg == MAP_FAILED) + { + perror("foo"); + fprintf(stderr, "failed to mmap"); + gpio_mmap_reg = NULL; + close(gpio_mmap_fd); + return -1; + } + + return 0; +} + +/** + * read pin input value + * @param pin + * @return + */ +int mt76x8_gpio_get_pin(int pin) +{ + uint32_t tmp = 0; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODATA); + tmp = (tmp >> pin) & 1u; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DATA); + tmp = (tmp >> (pin-32)) & 1u; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DATA); + tmp = (tmp >> (pin-64)) & 1u; + tmp = (tmp >> (pin-24)) & 1u; + } + return tmp; +} + +/** + * set gpio pin direction + * @param pin number + * @param is_output 1 == output, 0 == input + */ +void mt76x8_gpio_set_pin_direction(int pin, int is_output) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR); + if (is_output) + tmp |= (1u << pin); + else + tmp &= ~(1u << pin); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIODIR) = tmp; + } + else if (pin <= 63) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR); + if (is_output) + tmp |= (1u << (pin-32)); + else + tmp &= ~(1u << (pin-32)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332DIR) = tmp; + } + else if (pin <= 95) + { + tmp = *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR); + if (is_output) + tmp |= (1u << (pin-64)); + else + tmp &= ~(1u << (pin-64)); + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564DIR) = tmp; + } +} + + +/** + * set gpio value + * @param pin gpio number + * @param value value, 1 == high, 0 == low + */ +void mt76x8_gpio_set_pin_value(int pin, int value) +{ + uint32_t tmp; + + /* MT7621, MT7628 */ + if (pin <= 31) + { + tmp = (1u << pin); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIOSET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIORESET) = tmp; + } + else if (pin <= 63) + { + tmp = (1u << (pin-32)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO6332RESET) = tmp; + } + else if (pin <= 95) + { + tmp = (1u << (pin-64)); + if (value) + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564SET) = tmp; + else + *(volatile uint32_t *)(gpio_mmap_reg + RALINK_REG_PIO9564RESET) = tmp; + } +} + +void close_gpio() +{ + close(gpio_mmap_fd); +} + diff --git a/mt7688-alsa/python/mem_gpio.h b/mt7688-alsa/python/mem_gpio.h new file mode 100755 index 00000000..6647345f --- /dev/null +++ b/mt7688-alsa/python/mem_gpio.h @@ -0,0 +1,57 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _MEM_GPIO_H_ +#define _MEM_GPIO_H_ + + +#define MMAP_PATH "/dev/mem" + +#define RALINK_GPIO_DIR_IN 0 +#define RALINK_GPIO_DIR_OUT 1 + +#define RALINK_REG_PIOINT 0x690 +#define RALINK_REG_PIOEDGE 0x6A0 +#define RALINK_REG_PIORENA 0x650 +#define RALINK_REG_PIOFENA 0x660 +#define RALINK_REG_PIODATA 0x620 +#define RALINK_REG_PIODIR 0x600 +#define RALINK_REG_PIOSET 0x630 +#define RALINK_REG_PIORESET 0x640 + +#define RALINK_REG_PIO6332INT 0x694 +#define RALINK_REG_PIO6332EDGE 0x6A4 +#define RALINK_REG_PIO6332RENA 0x654 +#define RALINK_REG_PIO6332FENA 0x664 +#define RALINK_REG_PIO6332DATA 0x624 +#define RALINK_REG_PIO6332DIR 0x604 +#define RALINK_REG_PIO6332SET 0x634 +#define RALINK_REG_PIO6332RESET 0x644 + +#define RALINK_REG_PIO9564INT 0x698 +#define RALINK_REG_PIO9564EDGE 0x6A8 +#define RALINK_REG_PIO9564RENA 0x658 +#define RALINK_REG_PIO9564FENA 0x668 +#define RALINK_REG_PIO9564DATA 0x628 +#define RALINK_REG_PIO9564DIR 0x608 +#define RALINK_REG_PIO9564SET 0x638 +#define RALINK_REG_PIO9564RESET 0x648 + + +#define GPIO1_MODE 0x60 + + +// extern uint8_t* gpio_mmap_reg = NULL; +// extern int gpio_mmap_fd = 0; + + +int gpio_mmap(void); +int mt76x8_gpio_get_pin(int); +void mt76x8_gpio_set_pin_direction(int, int); +void mt76x8_gpio_set_pin_value(int, int); +void close_gpio(); + + +#endif diff --git a/mt7688-alsa/python/oled_iic.c b/mt7688-alsa/python/oled_iic.c new file mode 100755 index 00000000..b33ae333 --- /dev/null +++ b/mt7688-alsa/python/oled_iic.c @@ -0,0 +1,261 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#include +#include "oled_iic.h" +#include "mem_gpio.h" +#include "codetab.h" + + +//init GPIO port +void init_gpio() +{ + if (gpio_mmap()) + printf("gpio_mmap() error!\n"); + + //printf("get pin SCL input %d\n", mt76x8_gpio_get_pin(SCL)); + //printf("get pin SDA input %d\n", mt76x8_gpio_get_pin(SDA)); + + //printf("set pin SCL output 0\n"); + mt76x8_gpio_set_pin_direction(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); + //printf("set pin SDA output 0\n"); + mt76x8_gpio_set_pin_direction(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); +} + + +/********************************************** +//IIC Start +**********************************************/ +void IIC_Start() +{ + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +//IIC Stop +**********************************************/ +void IIC_Stop() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SDA, 1); +} + +void IIC_Ack() +{ + mt76x8_gpio_set_pin_value(SCL, 0); + mt76x8_gpio_set_pin_value(SDA, 0); + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 0); +} + +/********************************************** +// iic bus write a byte +**********************************************/ +void Write_IIC_Byte(unsigned char IIC_Byte) +{ + unsigned char t; + mt76x8_gpio_set_pin_value(SCL, 0); + + for (t = 0; t < 8; t++) + { + mt76x8_gpio_set_pin_value(SDA, (IIC_Byte&0x80)>>7); + IIC_Byte<<=1; + mt76x8_gpio_set_pin_value(SCL, 1); + mt76x8_gpio_set_pin_value(SCL, 1);//!!! Import Here + //usleep(1); + mt76x8_gpio_set_pin_value(SCL, 0); + } +} + +/*********************OLED write date************************************/ +void OLED_WrDat(unsigned char IIC_Data) +{ + IIC_Start(); + Write_IIC_Byte(0x78); + IIC_Ack(); + Write_IIC_Byte(0x40); //write data + IIC_Ack(); + Write_IIC_Byte(IIC_Data); + IIC_Ack(); + IIC_Stop(); +} +/*********************OLED write command*********************************/ +void OLED_WrCmd(unsigned char IIC_Command) +{ + IIC_Start(); + Write_IIC_Byte(0x78); //Slave address,SA0=0 + IIC_Ack(); + Write_IIC_Byte(0x00); //write command + IIC_Ack(); + Write_IIC_Byte(IIC_Command); + IIC_Ack(); + IIC_Stop(); +} + +/*********************OLED set postion************************************/ +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WrCmd(0xb0+y); + OLED_WrCmd(((x&0xf0)>>4)|0x10); + OLED_WrCmd((x&0x0f)|0x02); //!!! Note Here 01 cannot dispaly perfact !!! +} + +/*********************OLED fill screen************************************/ +void OLED_Fill(unsigned char bmp_dat) +{ + unsigned char y,x; + for(y=0;y<8;y++) + { + OLED_WrCmd(0xb0+y); + OLED_WrCmd(0x02);//low column start address //!!! Note Here 01 cannot dispaly perfact !!! + OLED_WrCmd(0x10);//high column start address + for(x=0;x 0xa1 normal + OLED_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0 0xc8 normal + OLED_WrCmd(0xa6);//--set normal display + OLED_WrCmd(0xa8);//--set multiplex ratio(1 to 64) + OLED_WrCmd(0x3f);//--1/64 duty + OLED_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F) + OLED_WrCmd(0x00);//-not offset + OLED_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency + OLED_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec + OLED_WrCmd(0xd9);//--set pre-charge period + OLED_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock + OLED_WrCmd(0xda);//--set com pins hardware configuration + OLED_WrCmd(0x12); + OLED_WrCmd(0xdb);//--set vcomh + OLED_WrCmd(0x40);//Set VCOM Deselect Level + OLED_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02) + OLED_WrCmd(0x02);// + OLED_WrCmd(0x8d);//--set Charge Pump enable/disable + OLED_WrCmd(0x14);//--set(0x10) disable + OLED_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5) + OLED_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) + OLED_WrCmd(0xaf);//--turn on oled panel + OLED_Fill(0x00); //clear + OLED_Set_Pos(0,0); +} + +/***************display a 6*8 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P6x8Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>126) {x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<6;i++) + { + OLED_WrDat(F6x8[c][i]); + } + x+=6; + j++; + } +} + +/*******************display a 8*16 ASCII charactertic postion x,y y 0-7****************/ +void OLED_P8x16Str(unsigned char x, unsigned char y,unsigned char ch[]) +{ + unsigned char c=0,i=0,j=0; + + while (ch[j]!='\0') + { + c =ch[j]-32; + if(x>120){x=0;y++;} + OLED_Set_Pos(x,y); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i]); + } + OLED_Set_Pos(x,y+1); + for(i=0;i<8;i++) + { + OLED_WrDat(F8X16[c*16+i+8]); + } + x+=8; + j++; + } +} +/*****************display a 16*16 ASCII charactertic postion x,y y 0-7****************************/ +void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char N) +{ + unsigned char wm=0; + unsigned int adder=32*N; + OLED_Set_Pos(x , y); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } + OLED_Set_Pos(x,y + 1); + for(wm = 0;wm < 16;wm++) + { + OLED_WrDat(F16x16[adder]); + adder += 1; + } +} + +/***********display a BMP 128*64 (x,y), x 0-127 y 0-7*****************/ +void Draw_BMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1,unsigned char BMP[]) +{ + unsigned int j=0; + unsigned char x,y; + + if(y1%8==0) + y=y1/8; + else + y=y1/8+1; + for(y=y0;y +#include +#include + +//int simplest_pcm16le_to_wave(const char *pcmpath,const char *wavepath,int channels,int sample_rate, unsigned long size) +int simplest_pcm16le_to_wave(const unsigned char *pcm,const char *wavepath,int channels,int sample_rate, unsigned long pcm_size) +{ + + typedef struct WAVE_HEADER{ + char fccID[4]; + unsigned long dwSize; + char fccType[4]; + }WAVE_HEADER; + + typedef struct WAVE_FMT{ + char fccID[4]; + unsigned long dwSize; + unsigned short wFormatTag; + unsigned short wChannels; + unsigned long dwSamplesPerSec; + unsigned long dwAvgBytesPerSec; + unsigned short wBlockAlign; + unsigned short uiBitsPerSample; + }WAVE_FMT; + + typedef struct WAVE_DATA{ + char fccID[4]; + unsigned long dwSize; + }WAVE_DATA; + + + if(channels==0||sample_rate==0){ + channels = 2; + sample_rate = 44100; + } + //---sample depth + int bits = 16; + + + WAVE_HEADER pcmHEADER; + WAVE_FMT pcmFMT; + WAVE_DATA pcmDATA; + + unsigned short m_pcmData; + FILE *fpout; + + fpout=fopen(wavepath, "wb+"); + if(fpout == NULL) { + printf("create wav file error\n"); + return -1; + } + + //WAVE_HEADER + memcpy(pcmHEADER.fccID,"RIFF",strlen("RIFF")); + memcpy(pcmHEADER.fccType,"WAVE",strlen("WAVE")); + pcmHEADER.dwSize=44+pcm_size; + fwrite(&pcmHEADER,sizeof(WAVE_HEADER),1,fpout); + + //WAVE_FMT + pcmFMT.dwSamplesPerSec=sample_rate; + pcmFMT.dwAvgBytesPerSec=pcmFMT.dwSamplesPerSec*sizeof(m_pcmData); + pcmFMT.uiBitsPerSample=bits; + memcpy(pcmFMT.fccID,"fmt ",strlen("fmt ")); + pcmFMT.dwSize=16; + pcmFMT.wBlockAlign=2; + pcmFMT.wChannels=channels; + pcmFMT.wFormatTag=1; + fwrite(&pcmFMT,sizeof(WAVE_FMT),1,fpout); + + //WAVE_DATA; + memcpy(pcmDATA.fccID,"data",strlen("data")); + pcmDATA.dwSize=pcm_size; + fwrite(&pcmDATA,sizeof(WAVE_DATA),1,fpout); + + //write PCM DATA + fwrite(pcm,pcm_size,1,fpout); + + fclose(fpout); + + return 0; +} + +#endif diff --git a/mt7688-alsa/python/record b/mt7688-alsa/python/record new file mode 100755 index 00000000..5aba2b00 Binary files /dev/null and b/mt7688-alsa/python/record differ diff --git a/mt7688-alsa/python/record.c b/mt7688-alsa/python/record.c new file mode 100755 index 00000000..8be18b2b --- /dev/null +++ b/mt7688-alsa/python/record.c @@ -0,0 +1,439 @@ +/*-------------------------------------------------- +ALSA auto. record and play test +Quote from: http://blog.csdn.net/ljclx1748/article/details/8606831 + +!!! Sample rate=8k is OK, while sample rate=48k will make it too sensitive !!! + +Usage: ./autorecord +1.It will monitor surrounding sound wave and trigger 60s recording if loud voice is sensed, + then it will playback. The sound will also be saved to a raw file. +2. Ensure there are no other active/pausing applications which may use ALSA simutaneously when you run the program, + sometimes it will make noise to the CAPUTRUE. + If PLAYBACK starts while Mplayer is playing, then sounds from Mplayer will totally disappear. + However if Mplayer starts later than PLAYBACK, two streams of sounds will be mixed. +3. use alsamixer to adjust Capture and ADC PCM value + ADC PCM 0-255 + Capture 0-63 +4. some explanation: + sample: usually 8bits or 16bits, one sample data width. + channel: 1-Mono. 2-Stereo + frame: sizeof(one sample)*channels + rate: frames per second + period: Max. frame numbers hard ware can be handled each time. (different value for PLAYBACK and CAPTURE!!) + chunk: frames receive from/send to hard ware each time. + buffer: N*periods + interleaved mode:record period data frame by frame, such as frame1(Left sample,Right sample),frame2(), ...... + uninterleaved mode: record period data channel by channel, such as period(Left sample,Left ,left...),period(right,right...),period()... +3. lib: lasound + +Make for Widora-neo +midas-zhou +--------------------------------------------------*/ +#include "record.h" +#include +#include +#include +#include "pcm2wav.h"//save as .wav + + +#define CHECK_FREQ 125 //-- use average energy in 1/CHECK_FREQ (s) to indicate noise level +#define SAMPLE_RATE 8000 //--4k also OK +#define CHECK_AVERG 2400 //--threshold value of wave amplitude to trigger record +#define KEEP_AVERG 2200 //--threshold value of wave amplitude for keeping recording +#define DELAY_TIME 5 //seconds -- recording time after one trigger +#define MAX_RECORD_TIME 4 //seconds --max. record time in seconds +#define MIN_SAVE_TIME 2 //seconds --min. recording time for saving, short time recording will be discarded. + +bool SAVE_WAVE_FILE = true; // save to .wav file + +snd_pcm_t *pcm_handle; +snd_pcm_hw_params_t *params; +snd_pcm_format_t format_val; +char *wave_buf; //---pointer to wave buffer +int wave_buf_len; //---wave buffer length in bytes +int wave_buf_used=0; //---used wave buf length in bytes +int bit_per_sample; +snd_pcm_uframes_t frames; +snd_pcm_uframes_t period_size; //length of period (max. numbers of frames that hw can handle each time) +snd_pcm_uframes_t chunk_size=32;//numbers of frames read/write to hard ware each time +int chunk_byte; //length of chunk (period) (in bytes) +unsigned int chanl_val,rate_val; +int dir; + +//------------ time struct --------------- +struct timeval t_start,t_end; +long cost_timeus=0; +long cost_times=0; +char str_time[20]={0}; +time_t timep; +struct tm *p_tm; + +//------------------- functions declaration ---------------------- +bool device_open(int mode); +bool device_setparams(); +bool device_capture(); +bool device_play(); +bool device_check_voice(); + +/*========================= MAIN ====================================*/ +//int main(int argc,char* argv[]) +int record_main() +{ +int fd; +int rc; +int ret=0; +char str_file[50]={0}; //---directory of save_file + + +//-------- set recording volume ------- +system("amixer set Capture 55"); +system("amixer set 'ADC PCM' 241"); // adjust sensitivity, or your can use alsamxier to adjust in realtime. + + +while(1) +{ +//--------¼ beware of if...if...if...if...expressions +if (!device_open(SND_PCM_STREAM_CAPTURE )){ + ret=1; + goto OPEN_STREAM_CAPTURE_ERR; + } +//printf("---device_open()\n"); +if (!device_setparams(1,SAMPLE_RATE)){ + ret=2; + goto SET_CAPTURE_PARAMS_ERR; + } +//printf("---device_setparams()\n"); + +//---------- allocate mem. for buffering raw data +//---------- The values of rate_val,chanl_val and bit_per_sample are set in device_setparams() function + printf("rate_val=%d, chanl_val=%d, bit_per_sample=%d\n",rate_val,chanl_val,bit_per_sample); + wave_buf_len=MAX_RECORD_TIME*rate_val*bit_per_sample*chanl_val/8; + + //-----checking voice wave amplitude, and start to record if it exceeds preset threshold value,or it will loop checking ... + if(!device_check_voice()){ //--device_check_voice() has a loop inside, it will jump out and return -1 only if there is an error. + goto LOOPEND; + } + +wave_buf=(char *)malloc(wave_buf_len); //----allocate mem... + +printf("start recording...\n"); +if (!device_capture()){ + ret=3; + goto DEVICE_CAPTURE_ERR; +} + //printf("-----device_capture()\n"); +snd_pcm_close( pcm_handle ); + printf("record finish!\n"); + + +//------------save to file +timep=time(NULL);// get CUT time,seconds from Epoch, long type indeed +p_tm=localtime(&timep);// convert to local time in struct tm +strftime(str_time,sizeof(str_time),"%Y-%m-%d-%H:%M:%S",p_tm); +printf("record at: %s\n",str_time); + +if(wave_buf_used >= (MIN_SAVE_TIME*rate_val*bit_per_sample*chanl_val/8)) // save to file only if recording time is great than 20s. +{ + system("rm test.wav"); + // ---------- save to wav file ------------ + if (SAVE_WAVE_FILE) + { + //sprintf(str_file,"/tmp/%s.wav",str_time); + sprintf(str_file,"/root/%s.wav","test"); + simplest_pcm16le_to_wave(wave_buf,str_file,chanl_val,SAMPLE_RATE, wave_buf_used); + printf("save to %s \n",str_file); + } + else + { + sprintf(str_file,"/root/%s.raw","test"); + fd=open(str_file,O_WRONLY|O_CREAT|O_TRUNC); + rc=write(fd,wave_buf,wave_buf_used); + printf("write to record.raw %d bytes\n",rc); + close(fd); //though kernel will close it automatically + } + system("chmod +x test.wav"); +} + +return 0; + +//-------- +if (!device_open(SND_PCM_STREAM_PLAYBACK)){ + ret=4; + goto OPEN_STREAM_PLAYBACK_ERR; + } +//printf("-----PLAY: device_open() finish\n"); +if (!device_setparams(1,SAMPLE_RATE)){ + ret=5; + goto SET_PLAYBACK_PARAMS_ERR; + } +//printf("-----PLAY: device_setarams() finish\n"); +printf("start playback...\n"); +if (!device_play()){ + ret=6; + goto DEVICE_PLAYBACK_ERR; //... contiue to loop +} +//if (!device_play()) goto LOOPEND; + +printf("finish playback.\n\n\n"); +//snd_pcm_drain( pcm_handle );//PALYBACK pcm_handle!! to allow any pending sound samples to be transferred. + + +LOOPEND: + snd_pcm_close( pcm_handle );//CAPTURE or PLAYBACK pcm_handle!! + //printf("-----PLAY: snd_pcm_close() ----\n"); + wave_buf_used=0; + free(wave_buf); //--wave_buf mem. to be allocated in device_capture() and played in device_play(); + continue; + +OPEN_STREAM_CAPTURE_ERR: + printf("Open PCM stream CAPTURE error!\n"); + return ret; +SET_CAPTURE_PARAMS_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; +DEVICE_CAPTURE_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; +OPEN_STREAM_PLAYBACK_ERR: + printf("Open PCM stream PLAYBACK error!\n"); + return ret; +SET_PLAYBACK_PARAMS_ERR: + printf("Set PLAYBACK parameters error!\n"); + return ret; +DEVICE_PLAYBACK_ERR: + printf("device_play() error! start a new loop...\n"); + goto LOOPEND; + +}//while() + +return ret; + + + +} + + +//ǷװһƵ豸ĺ +//snd_pcm_t *pcm_handle; + +bool device_open(int mode){ +if(snd_pcm_open (&pcm_handle,"default",mode,0) < 0) + { + printf("snd_pcm_open() fail!\n"); + return false; + } + printf("snd_pcm_open() succeed!\n"); + return true; +} + +/*-------------------- set and prepare parameters ------------------*/ +bool device_setparams(int nchanl,int rate) + { +unsigned int val; +int dir; +int rc; +snd_pcm_hw_params_t *hw_params; + +//------ beware of following if..if...if..if...if...expressions ---------- +if(snd_pcm_hw_params_malloc (&hw_params) < 0)return false; //Ϊռ +// printf("---- snd_pcm_hw_params_malloc(&hw_params) ----\n"); +if(snd_pcm_hw_params_malloc (¶ms) < 0)return false; +// printf("----snd_pcm_hw_params_malloc(¶ms) ----\n"); +if(snd_pcm_hw_params_any (pcm_handle, hw_params) < 0)return false; //ʼ +// printf("----snd_pcm_hw_params_any(pcm_handle,hw_params)----\n"); +if(snd_pcm_hw_params_set_access (pcm_handle, hw_params,SND_PCM_ACCESS_RW_INTERLEAVED) < 0)return false; //Ϊģʽ +// printf("----snd_pcm_hw_params_set_access()----\n"); +if(snd_pcm_hw_params_set_format( pcm_handle, hw_params, SND_PCM_FORMAT_S16_LE) < 0)return false; //ʹ16λ +// printf("----snd_pmc_hw_params_set_format()-----\n"); +val=rate;//8000; +if(snd_pcm_hw_params_set_rate_near( pcm_handle, hw_params,&val,0) < 0)return false; //ò +// printf("----snd_pcm_hw_params_set_rate_near() val=%d----\n",val); +if(snd_pcm_hw_params_set_channels( pcm_handle, hw_params, nchanl) < 0)return false; //Ϊor Mono. +// printf("----snd_pcm_hw_params_set_channels()-----\n"); +frames=32; +if(snd_pcm_hw_params_set_period_size_near(pcm_handle,hw_params,&chunk_size,&dir) < 0 )return false; +// printf("----snd_pcm_hw_params_set_period_size_near() chunk_size=%d----\n",chunk_size); +if(snd_pcm_hw_params_get_period_size( hw_params, &period_size,0) < 0)return false; //ȡڳ + printf("----snd_pcm_hw_get_period_size(): %d frames----\n",(int)period_size); +if(snd_pcm_hw_params_get_format(hw_params,&format_val) < 0)return false; +// printf("----snd_pcm_hw_params_get_format()----\n"); +bit_per_sample = snd_pcm_format_width((snd_pcm_format_t)format_val); +//printf("---bit_per_sample=%d snd_pcm_format_width()----\n",bit_per_sample); +//ȡ +snd_pcm_hw_params_get_channels(hw_params,&chanl_val); +//printf("----snd_pcm_hw_params_get_channels %d---\n",chanl_val); +chunk_byte = period_size*bit_per_sample*chanl_val/8; // this is the Max chunk byte size +//chunk_size = frames;//period_size; //frames +//ڳȣֽ(bytes) = ÿڵ * (bit) * ͨ / 8 +snd_pcm_hw_params_get_rate(hw_params,&rate_val,&dir); +snd_pcm_hw_params_get_channels(hw_params,&chanl_val); + +rc=snd_pcm_hw_params( pcm_handle, hw_params); //ò +if(rc<0){ +printf("unable to set hw parameters:%s\n",snd_strerror(rc)); +exit(1); +} +printf("finish setting sound hw parameters\n"); +params = hw_params; //Ժʹ +snd_pcm_hw_params_free( hw_params); //ͷŲռ +//printf("----snd_pcm_hw_params_free()----\n"); +return true; + +} +//ʹAlsaṩһϵsnd_pcm_hw_params_set_Ϊֵ +//ͨsnd_pcm_hw_paramsݸ豸 +//Ҫ˵ʽĿҪʧܵΪʾδǡ +//úòԿʼ¼ˡ¼ʵϾǴƵ豸жȡϢ档 + + +//------------------- record sound ------------------------------------// + bool device_capture( ){ + int i; + int r = 0; + int total=0; + int averg=0; + char *data=wave_buf; // pointer to wave_buf position + int16_t *pv; //pointer to current data + // int CN=7; //chunk_size=2^CN + // chunk_size=(2<0 ) { + pv=(int16_t *)data; //--get pointer for chunk data + data += chunk_byte;//--move current buffer position pointer, short run is NOT considered!!! + //------------ checker timer, return when DELAY_TIME used up ---------------- + gettimeofday(&t_end,NULL); + cost_times=t_end.tv_sec-t_start.tv_sec; + if(cost_times >= DELAY_TIME){ + wave_buf_used=data-wave_buf; + return true; + } + //----------- check sound wave amplitude ----------------- + averg=0;total=0; + for(i=0;i>CN); + averg=(total/chunk_size); + //printf("averg=%d\n",averg); + if(averg >= KEEP_AVERG){ + gettimeofday(&t_start,NULL); // reset timer, add one more DELAY_TIME for recording. + printf("averg=%d\n",averg); + printf("loud noise sensed!\n"); + } + + } +/* + else //if(r<0) + { + + wave_buf_used=data-wave_buf; + return false; + } +*/ + } // end of while() + +wave_buf_used=data-wave_buf; //--short run is not considered!!! +return true; +} + +//βdtimeȷ¼ʱ䣬¼ʱݿռ䣬ٵsnd_pcm_readiƵ豸ȡƵݣŵwave_bufС +//ͬԭһźƵ豸дݣ + +bool device_play(){ + char *data = wave_buf; + int r = 0; + chunk_size=32; + chunk_byte=chunk_size*bit_per_sample*chanl_val/8; + while ( (data-wave_buf) <= (wave_buf_used-chunk_byte)){ + r = snd_pcm_writei( pcm_handle, data , chunk_size); //chunk_size = frames + if(r == -EAGAIN)continue; + if(r < 0){ + printf("write error: %s\n",snd_strerror(r)); + //exit(EXIT_FAILURE); //ocassionally, it will exit here! + return false; + } + //printf("----- writei() r=%d -----\n ",r); + if ( r>0 ) data += chunk_byte; + else + return false; + } + return true; + +} + + +bool device_check_voice(void ) +{ + int i; + int r = 0; + int count=0; + int total=0; + int averg=0;//average of sample values in one chunk. + int CN=5; + chunk_size= SAMPLE_RATE/CHECK_FREQ; //--how many frames to be checked for specified CHECK_FREQ,one channel + //chunk_size=(2<=0 ) { + //printf(" r= %d \n ",r); + data=buf; + averg=0;total=0; + for(i=0;i>CN); + averg=(total/chunk_size); + //printf("averg=%d\n",averg); + if(averg >= CHECK_AVERG){ + printf("loud noise sensed! averg =%d chunk_size=%d\n",averg,chunk_size); + free(buf); + return true; + } + +// usleep(20000); // +// snd_pcm_prepare(pcm_handle); + //usleep(10000); //---you cann't sleep here, + }//if + else + { + printf(" r= %d \n ",r); + free(buf); + return false; + } + } //while(1) + +free(buf); +return true; + +} diff --git a/mt7688-alsa/python/record.h b/mt7688-alsa/python/record.h new file mode 100755 index 00000000..39d9f8d1 --- /dev/null +++ b/mt7688-alsa/python/record.h @@ -0,0 +1,22 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _RECORD_H_ +#define _RECORD_H_ + + +#include + + +//------------------- functions declaration ---------------------- +bool device_open(int mode); +bool device_setparams(); +bool device_capture(); +bool device_play(); +bool device_check_voice(); +int record_main(); + + +#endif diff --git a/mt7688-alsa/python/temp.wav b/mt7688-alsa/python/temp.wav new file mode 100755 index 00000000..de060926 Binary files /dev/null and b/mt7688-alsa/python/temp.wav differ diff --git a/mt7688-alsa/python/test.wav b/mt7688-alsa/python/test.wav new file mode 100755 index 00000000..454b99df Binary files /dev/null and b/mt7688-alsa/python/test.wav differ diff --git a/mt7688-alsa/python/testlibmian.py b/mt7688-alsa/python/testlibmian.py new file mode 100755 index 00000000..4129e60e --- /dev/null +++ b/mt7688-alsa/python/testlibmian.py @@ -0,0 +1,9 @@ +from ctypes import * +import os +import time + +libsc = cdll.LoadLibrary(os.getcwd() + '/libmain.so') +#print libsc.get_button() +print libsc.thread_rec() +time.sleep(1); +libsc.clear_display() \ No newline at end of file diff --git a/mt7688-alsa/record.c b/mt7688-alsa/record.c new file mode 100755 index 00000000..e971011b --- /dev/null +++ b/mt7688-alsa/record.c @@ -0,0 +1,461 @@ +/*---------------------------------------------------------------------------------------------------------------------------------------- +* ALSA record and play +!!! Sample rate=8k is OK, while sample rate=48k will make it too sensitive !!! +* +*Usage: ./record_control +1. It will monitor surrounding sound wave and trigger 60s recording if loud voice is sensed, + then it will playback. The sound will also be saved to a raw file. +2. Ensure there are no other active/pausing applications which may use ALSA simutaneously when you run the program, + sometimes it will make noise to the CAPUTRUE. + If PLAYBACK starts while Mplayer is playing, then sounds from Mplayer will totally disappear. + However if Mplayer starts later than PLAYBACK, two streams of sounds will be mixed. +3. use alsamixer to adjust Capture and ADC PCM value + ADC PCM 0-255 + Capture 0-63 +4. some explanation: + sample: usually 8bits or 16bits, one sample data width. + channel: 1-Mono. 2-Stereo + frame: sizeof(one sample)*channels + rate: frames per second + period: Max. frame numbers hard ware can be handled each time. (different value for PLAYBACK and CAPTURE!!) + chunk: frames receive from/send to hard ware each time. + buffer: N*periods + interleaved mode:record period data frame by frame, such as frame1(Left sample,Right sample),frame2(), ...... + uninterleaved mode: record period data channel by channel, such as period(Left sample,Left ,left...),period(right,right...),period()... +3. lib: lasound +* +*Make for Widora-neo +* +* IMIO Inc +* Author: zyc +* Date : 2017-04-12 +-----------------------------------------------------------------------------------------------------------------------------------------*/ +#include "record.h" +#include +#include +#include +#include + + +//------------ gobal variable -------------------------------- +snd_pcm_t *pcm_handle; +snd_pcm_hw_params_t *params; +snd_pcm_format_t format_val; +char *wave_buf; //---pointer to wave buffer +int wave_buf_len; //---wave buffer length in bytes +int wave_buf_used = 0; //---used wave buf length in bytes +int bit_per_sample;//simple bit +snd_pcm_uframes_t frames; +snd_pcm_uframes_t period_size; //length of period (max. numbers of frames that hw can handle each time) +snd_pcm_uframes_t chunk_size = 32;//numbers of frames read/write to hard ware each time +int chunk_byte; //length of chunk (period) (in bytes) +unsigned int chanl_val,rate_val; +int dir; + +//------------ time struct --------------------------------------- +struct timeval t_start,t_end; +long cost_timeus=0; +long cost_times=0; +char str_time[20]={0}; +time_t timep; +struct tm *p_tm; + + + +/*========================= FUNC ====================================*/ +//snd_pcm_t *pcm_handle; + +//use a func to open sound device +bool device_open(int mode) +{ + if (snd_pcm_open(&pcm_handle, "default", mode, 0) < 0) + { + printf("snd_pcm_open() fail!\n"); + return false; + } + printf("snd_pcm_open() succeed!\n"); + return true; +} + +/*-------------------- set and prepare parameters ------------------*/ +bool device_setparams(int nchanl,int rate) +{ + unsigned int val; + int dir; + int rc; + snd_pcm_hw_params_t *hw_params; + + //------ beware of following if..if...if..if...if...expressions ---------- + if(snd_pcm_hw_params_malloc (&hw_params ) < 0) + return false; //Ϊռ + // printf("---- snd_pcm_hw_params_malloc(&hw_params) ----\n"); + if(snd_pcm_hw_params_malloc (¶ms) < 0) + return false; + // printf("----snd_pcm_hw_params_malloc(¶ms) ----\n"); + if(snd_pcm_hw_params_any (pcm_handle, hw_params) < 0) + return false; //ʼ + // printf("----snd_pcm_hw_params_any(pcm_handle,hw_params)----\n"); + if(snd_pcm_hw_params_set_access (pcm_handle, hw_params,SND_PCM_ACCESS_RW_INTERLEAVED) < 0) + return false; //Ϊģʽ + // printf("----snd_pcm_hw_params_set_access()----\n"); + if(snd_pcm_hw_params_set_format( pcm_handle, hw_params, SND_PCM_FORMAT_S16_LE) < 0) + return false; //ʹ16λ + // printf("----snd_pmc_hw_params_set_format()-----\n"); + + val = rate;//8000; + if(snd_pcm_hw_params_set_rate_near(pcm_handle, hw_params,&val,0) < 0) + return false; //ò + // printf("----snd_pcm_hw_params_set_rate_near() val=%d----\n",val); + if(snd_pcm_hw_params_set_channels( pcm_handle, hw_params, nchanl) < 0) + return false; //Ϊor Mono. + // printf("----snd_pcm_hw_params_set_channels()-----\n"); + + frames = 32; + if(snd_pcm_hw_params_set_period_size_near(pcm_handle,hw_params,&chunk_size,&dir ) < 0 ) + return false; + // printf("----snd_pcm_hw_params_set_period_size_near() chunk_size=%d----\n",chunk_size); + if(snd_pcm_hw_params_get_period_size( hw_params, &period_size,0) < 0) + return false; //ȡڳ1536 + printf("----snd_pcm_hw_get_period_size(): %d frames----\n",(int) period_size ); + if(snd_pcm_hw_params_get_format(hw_params,&format_val ) < 0) + return false; + // printf("----snd_pcm_hw_params_get_format()----\n"); + + bit_per_sample = snd_pcm_format_width((snd_pcm_format_t) format_val ); + //printf("---bit_per_sample=%d snd_pcm_format_width()----\n",bit_per_sample); + //ȡ + snd_pcm_hw_params_get_channels(hw_params,&chanl_val ); + //printf("----snd_pcm_hw_params_get_channels %d---\n",chanl_val); + chunk_byte = period_size*bit_per_sample*chanl_val/8; //3072 this is the Max chunk byte size + //chunk_size = frames;//period_size; //frames + //ڳȣֽ(bytes) = ÿڵ * (bit) * ͨ / 8 + snd_pcm_hw_params_get_rate(hw_params,&rate_val,&dir); + snd_pcm_hw_params_get_channels(hw_params,&chanl_val); + + rc = snd_pcm_hw_params( pcm_handle, hw_params); //ò + if (rc < 0) + { + printf("unable to set hw parameters:%s\n",snd_strerror(rc)); + exit(1); + } + printf("finish setting sound hw parameters\n"); + params = hw_params; //Ժʹ + snd_pcm_hw_params_free( hw_params); //ͷŲռ + //printf("----snd_pcm_hw_params_free()----\n"); + + return true; +} +//ʹAlsaṩһϵ snd_pcm_hw_params_set_ Ϊֵ +//ͨ snd_pcm_hw_params ݸ豸 +//Ҫ˵ʽĿҪʧܵΪʾδǡ +//úòԿʼ¼ˡ¼ʵϾǴƵ豸жȡϢ档 + + +//------------------- record sound ------------------------------------// + bool device_capture() + { + int i; + int r = 0; + int total = 0; + int averg = 0; + char *data = wave_buf; // pointer to wave_buf position + int16_t *pv; //pointer to current data + //int CN = 7; //chunk_size = 2^CN + + //chunk_size = (2 << CN); //=frames + chunk_size = SAMPLE_RATE/CHECK_FREQ; //--how many frames to be checked for specified CHECK_FREQ,one channel + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + //printf("chunk_byte=%d\n",chunk_byte); + + //------------------ get start time ------------------ + gettimeofday(&t_start, NULL); + printf("Start Time: %lds + %ldus \n",t_start.tv_sec,t_start.tv_usec); + + while ((data-wave_buf) <= (wave_buf_len-chunk_byte)) + { //chunk_size*bit_per_sample*chanl_val)){ + r = snd_pcm_readi( pcm_handle,data,chunk_size); //chunk_size*bit_per_sample*read interleaved frames from a PCM + if(r == -EPIPE) + { + /* EPIPE means overrun */ + fprintf(stderr,"overrun occurred!\n"); + snd_pcm_prepare(pcm_handle);//try to recover. to put the stream in PREPARED state so it can start again next time. + } + else if (r < 0) + { + fprintf(stderr,"error from read:%s\n",snd_strerror(r)); + } + else if (r != chunk_size) + { + fprintf(stderr,"short read, read %d frames\n",r); + } + if (r > 0) + { + pv = (int16_t *)data; //--get pointer for chunk data + data += chunk_byte;//--move current buffer position pointer, short run is NOT considered!!! + //------------ checker timer, return when DELAY_TIME used up ---------------- + gettimeofday(&t_end,NULL); + cost_times = t_end.tv_sec-t_start.tv_sec; + if(cost_times >= DELAY_TIME) + { + wave_buf_used = data-wave_buf; + return true; + } + //----------- check sound wave amplitude ----------------- + averg = 0; + total = 0; + for (i = 0; i < r; i++) + { //r -- chunk_size,16bits each frame. + total += abs(*pv); // !!!!!! + pv += 1; + } + //printf("total = %d\n", total); + //averg = (total >> CN); + averg = (total/chunk_size); + //printf("averg = %d\n",averg); + if(averg >= KEEP_AVERG) + { + gettimeofday(&t_start,NULL); // reset timer, add one more DELAY_TIME for recording. + printf("averg = %d\n",averg); + printf("loud noise sensed!\n"); + } + } + /* + else //if(r<0) + { + wave_buf_used=data-wave_buf; + return false; + } + */ + } // end of while() + + wave_buf_used = data-wave_buf; //--short run is not considered!!! + + return true; +} + +//βdtimeȷ¼ʱ䣬¼ʱݿռ䣬ٵsnd_pcm_readiƵ豸ȡƵݣŵwave_bufС +//ͬԭһźƵ豸дݣ + +bool device_play() +{ + char *data = wave_buf; + int r = 0; + chunk_size = 32; + + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + while ((data-wave_buf) <= (wave_buf_used-chunk_byte)) + { + r = snd_pcm_writei(pcm_handle, data , chunk_size); //chunk_size = frames + if(r == -EAGAIN) + continue; + if(r < 0) + { + printf("write error: %s\n",snd_strerror(r)); + //exit(EXIT_FAILURE); //ocassionally, it will exit here! + return false; + } + //printf("----- writei() r=%d -----\n ",r); + if ( r > 0 ) + data += chunk_byte; + else + return false; + } + + return true; +} + +bool device_check_voice(void) +{ + int i; + int r = 0; + int count = 0; + int total = 0; + int averg = 0;//average of sample values in one chunk. + int CN = 5; + + chunk_size = SAMPLE_RATE/CHECK_FREQ; //64--how many frames to be checked for specified CHECK_FREQ,one channel + //chunk_size = (2 << CN); //--frames each time + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; //---128 bytes + int16_t *buf = (int16_t *)malloc(chunk_byte); //--sample width 16bits + int16_t *data = buf; + + printf("listening and checking any voice......\n"); + while(1) + { + r = snd_pcm_readi(pcm_handle, (char *) buf, chunk_size); //chunk_size*bit_per_sample*read interleaved rames from a PCM + + if(r == -EAGAIN) + continue; + if (r >= 0) + { + //printf(" r= %d \n ",r); + data = buf; + averg = 0; + total = 0; + for(i = 0; i < r; i++) + { + total += abs(*data); // !!!!!! + data += 1; + } + //printf("total=%d\n",total); + //averg=(total >> CN); + averg = (total/chunk_size); + //printf("averg=%d\n",averg); + if(averg >= CHECK_AVERG ) + { + printf("loud noise sensed! averg = %d chunk_size = %d\n", averg, chunk_size); + free(buf); + return true; + } + //usleep(20000); // + //snd_pcm_prepare(pcm_handle); + //usleep(10000); //---you cann't sleep here, + }//if + else + { + printf(" r = %d \n ",r); + free(buf); + return false; + } + } //while(1) + + free(buf); + + return true; +} + + + +/*========================= MAIN ====================================*/ +int record_main() +{ + int fd; + int rc; + int ret = 0; + char str_file[50] = {0};//---directory of save_file + + //-------- set recording volume ------- + system("amixer set Capture 55"); + system("amixer set 'ADC PCM' 241"); // adjust sensitivity, or your can use alsamxier to adjust in realtime. + + while(1) + { + //--------sound recording beware of if...if...if...if...expressions + if (!device_open(SND_PCM_STREAM_CAPTURE )) + { + ret = 1; + goto OPEN_STREAM_CAPTURE_ERR; + } + //printf("---device_open()\n"); + if (!device_setparams(1,SAMPLE_RATE)){ + ret=2; + goto SET_CAPTURE_PARAMS_ERR; + } + //printf("---device_setparams()\n"); + + //---------- allocate mem. for buffering raw data + //---------- The values of rate_val,chanl_val and bit_per_sample are set in device_setparams() function + printf("rate_val = %d, chanl_val = %d, bit_per_sample = %d\n",rate_val,chanl_val,bit_per_sample); + wave_buf_len = MAX_RECORD_TIME*rate_val*bit_per_sample*chanl_val/8; + + //-----checking voice wave amplitude, and start to record if it exceeds preset threshold value,or it will loop checking ... + if(!device_check_voice()) + { //--device_check_voice() has a loop inside, it will jump out and return -1 only if there is an error. + goto LOOPEND; + } + + wave_buf = (char *)malloc(wave_buf_len ); //----allocate mem... + + //----------------recording + printf("start recording...\n"); + if (!device_capture()) + { + ret = 3; + goto DEVICE_CAPTURE_ERR; + } + //printf("-----device_capture()\n"); + snd_pcm_close( pcm_handle ); + printf("record finish!\n"); + + //------------save to file + timep = time(NULL);// get CUT time,seconds from Epoch, long type indeed + p_tm = localtime(&timep);// convert to local time in struct tm + strftime(str_time,sizeof(str_time),"%Y-%m-%d-%H:%M:%S",p_tm); + printf("record at: %s\n",str_time); + + if(wave_buf_used >= (MIN_SAVE_TIME*rate_val*bit_per_sample*chanl_val/8)) // save to file only if recording time is great than 20s. + { + sprintf(str_file,"/tmp/%s.raw",str_time); + //sprintf(str_file,"./%s.raw","test"); + fd = open(str_file,O_WRONLY|O_CREAT|O_TRUNC); + rc = write(fd,wave_buf,wave_buf_used); + printf("write to record.raw %d bytes\n",rc); + close(fd); //though kernel will close it automatically + } + + //finish here + return 0; + + //-------- + if (!device_open(SND_PCM_STREAM_PLAYBACK)) + { + ret = 4; + goto OPEN_STREAM_PLAYBACK_ERR; + } + //printf("-----PLAY: device_open() finish\n"); + if (!device_setparams(1,SAMPLE_RATE)) + { + ret = 5; + goto SET_PLAYBACK_PARAMS_ERR; + } + //printf("-----PLAY: device_setarams() finish\n"); + printf("start playback...\n"); + if (!device_play()) + { + ret = 6; + goto DEVICE_PLAYBACK_ERR; //... contiue to loop + } + //if (!device_play()) goto LOOPEND; + + printf("finish playback.\n\n\n"); + //snd_pcm_drain( pcm_handle );//PALYBACK pcm_handle!! to allow any pending sound samples to be transferred. + + return 0; + +LOOPEND: + snd_pcm_close(pcm_handle);//CAPTURE or PLAYBACK pcm_handle!! + //printf("-----PLAY: snd_pcm_close() ----\n"); + wave_buf_used = 0; + free(wave_buf); //--wave_buf mem. to be allocated in device_capture() and played in device_play(); + continue; + +OPEN_STREAM_CAPTURE_ERR: + printf("Open PCM stream CAPTURE error!\n"); + return ret; + +SET_CAPTURE_PARAMS_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +DEVICE_CAPTURE_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +OPEN_STREAM_PLAYBACK_ERR: + printf("Open PCM stream PLAYBACK error!\n"); + return ret; + +SET_PLAYBACK_PARAMS_ERR: + printf("Set PLAYBACK parameters error!\n"); + return ret; + +DEVICE_PLAYBACK_ERR: + printf("device_play() error! start a new loop...\n"); + goto LOOPEND; + + }//while() + + return ret; +} + + diff --git a/mt7688-alsa/record.h b/mt7688-alsa/record.h new file mode 100755 index 00000000..e3b1d244 --- /dev/null +++ b/mt7688-alsa/record.h @@ -0,0 +1,30 @@ +/* It's a test for control the GPIO output & input, then use IIC control +* IMIO Inc +* Author : zyc +* Date : 2017-04-11 +*/ +#ifndef _RECORD_H_ +#define _RECORD_H_ + + +#include + +#define CHECK_FREQ 125 //-- use average energy in 1/CHECK_FREQ (s) to indicate noise level +#define SAMPLE_RATE 8000 //--4k also OK +#define CHECK_AVERG 2000 //--threshold value of wave amplitude to trigger record +#define KEEP_AVERG 1800 //--threshold value of wave amplitude for keeping recording +#define DELAY_TIME 5 //seconds -- recording time after one trigger +#define MAX_RECORD_TIME 20 //seconds --max. record time in seconds +#define MIN_SAVE_TIME 10 //seconds --min. recording time for saving, short time recording will be discarded. + + +//------------------- functions declaration ---------------------- +bool device_open(int mode); +bool device_setparams(); +bool device_capture(); +bool device_play(); +bool device_check_voice(); +int record_main(); + + +#endif diff --git a/mt7688-alsa/record.o b/mt7688-alsa/record.o new file mode 100755 index 00000000..8cd7655b Binary files /dev/null and b/mt7688-alsa/record.o differ diff --git a/mt7688-alsa/record_control.c b/mt7688-alsa/record_control.c new file mode 100755 index 00000000..f6603b11 --- /dev/null +++ b/mt7688-alsa/record_control.c @@ -0,0 +1,474 @@ +/* --------------------------------------------------------------------------- +* ALSA record and play +!!! Sample rate=8k is OK, while sample rate=48k will make it too sensitive !!! +* +*Usage: ./record_control +1. It will monitor surrounding sound wave and trigger 60s recording if loud voice is sensed, + then it will playback. The sound will also be saved to a raw file. +2. Ensure there are no other active/pausing applications which may use ALSA simutaneously when you run the program, + sometimes it will make noise to the CAPUTRUE. + If PLAYBACK starts while Mplayer is playing, then sounds from Mplayer will totally disappear. + However if Mplayer starts later than PLAYBACK, two streams of sounds will be mixed. +3. use alsamixer to adjust Capture and ADC PCM value + ADC PCM 0-255 + Capture 0-63 +4. some explanation: + sample: usually 8bits or 16bits, one sample data width. + channel: 1-Mono. 2-Stereo + frame: sizeof(one sample)*channels + rate: frames per second + period: Max. frame numbers hard ware can be handled each time. (different value for PLAYBACK and CAPTURE!!) + chunk: frames receive from/send to hard ware each time. + buffer: N*periods + interleaved mode:record period data frame by frame, such as frame1(Left sample,Right sample),frame2(), ...... + uninterleaved mode: record period data channel by channel, such as period(Left sample,Left ,left...),period(right,right...),period()... +3. lib: lasound +* +*Make for Widora-neo +* +* IMIO Inc +* Author: zyc +* Date : 2017-04-12 +------------------------------------------------------------------------------*/ +#include +#include +#include +#include + + +#define CHECK_FREQ 125 //-- use average energy in 1/CHECK_FREQ (s) to indicate noise level +#define SAMPLE_RATE 8000 //--4k also OK +#define CHECK_AVERG 2000 //--threshold value of wave amplitude to trigger record +#define KEEP_AVERG 1800 //--threshold value of wave amplitude for keeping recording +#define DELAY_TIME 5 //seconds -- recording time after one trigger +#define MAX_RECORD_TIME 20 //seconds --max. record time in seconds +#define MIN_SAVE_TIME 10 //seconds --min. recording time for saving, short time recording will be discarded. + + +//------------ gobal variable -------------------------------- +snd_pcm_t *pcm_handle; +snd_pcm_hw_params_t *params; +snd_pcm_format_t format_val; +char *wave_buf; //---pointer to wave buffer +int wave_buf_len; //---wave buffer length in bytes +int wave_buf_used = 0; //---used wave buf length in bytes +int bit_per_sample;//simple bit +snd_pcm_uframes_t frames; +snd_pcm_uframes_t period_size; //length of period (max. numbers of frames that hw can handle each time) +snd_pcm_uframes_t chunk_size = 32;//numbers of frames read/write to hard ware each time +int chunk_byte; //length of chunk (period) (in bytes) +unsigned int chanl_val,rate_val; +int dir; + +//------------ time struct --------------------------------------- +struct timeval t_start,t_end; +long cost_timeus=0; +long cost_times=0; +char str_time[20]={0}; +time_t timep; +struct tm *p_tm; + +//------------------- functions declaration ---------------------- +bool device_open(int mode); +bool device_setparams(); +bool device_capture(); +bool device_play(); +bool device_check_voice(); + + +/*========================= MAIN ====================================*/ +int main(int argc, char* argv[]) +{ + int fd; + int rc; + int ret = 0; + char str_file[50] = {0};//---directory of save_file + + //-------- set recording volume ------- + system("amixer set Capture 55"); + system("amixer set 'ADC PCM' 241"); // adjust sensitivity, or your can use alsamxier to adjust in realtime. + + while(1) + { + //--------sound recording beware of if...if...if...if...expressions + if (!device_open(SND_PCM_STREAM_CAPTURE )) + { + ret = 1; + goto OPEN_STREAM_CAPTURE_ERR; + } + //printf("---device_open()\n"); + if (!device_setparams(1,SAMPLE_RATE)){ + ret=2; + goto SET_CAPTURE_PARAMS_ERR; + } + //printf("---device_setparams()\n"); + + //---------- allocate mem. for buffering raw data + //---------- The values of rate_val,chanl_val and bit_per_sample are set in device_setparams() function + printf("rate_val = %d, chanl_val = %d, bit_per_sample = %d\n",rate_val,chanl_val,bit_per_sample); + wave_buf_len = MAX_RECORD_TIME*rate_val*bit_per_sample*chanl_val/8; + + //-----checking voice wave amplitude, and start to record if it exceeds preset threshold value,or it will loop checking ... + if(!device_check_voice()) + { //--device_check_voice() has a loop inside, it will jump out and return -1 only if there is an error. + goto LOOPEND; + } + + wave_buf = (char *)malloc(wave_buf_len ); //----allocate mem... + + //----------------recording + printf("start recording...\n"); + if (!device_capture()) + { + ret = 3; + goto DEVICE_CAPTURE_ERR; + } + //printf("-----device_capture()\n"); + snd_pcm_close( pcm_handle ); + printf("record finish!\n"); + + //------------save to file + timep = time(NULL);// get CUT time,seconds from Epoch, long type indeed + p_tm = localtime(&timep);// convert to local time in struct tm + strftime(str_time,sizeof(str_time),"%Y-%m-%d-%H:%M:%S",p_tm); + printf("record at: %s\n",str_time); + + if(wave_buf_used >= (MIN_SAVE_TIME*rate_val*bit_per_sample*chanl_val/8)) // save to file only if recording time is great than 20s. + { + sprintf(str_file,"/tmp/%s.raw",str_time); + fd = open(str_file,O_WRONLY|O_CREAT|O_TRUNC); + rc = write(fd,wave_buf,wave_buf_used); + printf("write to record.raw %d bytes\n",rc); + close(fd); //though kernel will close it automatically + } + + //-------- + if (!device_open(SND_PCM_STREAM_PLAYBACK)) + { + ret = 4; + goto OPEN_STREAM_PLAYBACK_ERR; + } + //printf("-----PLAY: device_open() finish\n"); + if (!device_setparams(1,SAMPLE_RATE)) + { + ret = 5; + goto SET_PLAYBACK_PARAMS_ERR; + } + //printf("-----PLAY: device_setarams() finish\n"); + printf("start playback...\n"); + if (!device_play()) + { + ret = 6; + goto DEVICE_PLAYBACK_ERR; //... contiue to loop + } + //if (!device_play()) goto LOOPEND; + + printf("finish playback.\n\n\n"); + //snd_pcm_drain( pcm_handle );//PALYBACK pcm_handle!! to allow any pending sound samples to be transferred. + + return 0; + +LOOPEND: + snd_pcm_close(pcm_handle);//CAPTURE or PLAYBACK pcm_handle!! + //printf("-----PLAY: snd_pcm_close() ----\n"); + wave_buf_used = 0; + free(wave_buf); //--wave_buf mem. to be allocated in device_capture() and played in device_play(); + continue; + +OPEN_STREAM_CAPTURE_ERR: + printf("Open PCM stream CAPTURE error!\n"); + return ret; + +SET_CAPTURE_PARAMS_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +DEVICE_CAPTURE_ERR: + printf("Set CAPTURE parameters error!\n"); + return ret; + +OPEN_STREAM_PLAYBACK_ERR: + printf("Open PCM stream PLAYBACK error!\n"); + return ret; + +SET_PLAYBACK_PARAMS_ERR: + printf("Set PLAYBACK parameters error!\n"); + return ret; + +DEVICE_PLAYBACK_ERR: + printf("device_play() error! start a new loop...\n"); + goto LOOPEND; + + }//while() + + return ret; +} + + +/*========================= FUNC ====================================*/ +//snd_pcm_t *pcm_handle; + +//use a func to open sound device +bool device_open(int mode) +{ + if (snd_pcm_open(&pcm_handle, "default", mode, 0) < 0) + { + printf("snd_pcm_open() fail!\n"); + return false; + } + printf("snd_pcm_open() succeed!\n"); + return true; +} + +/*-------------------- set and prepare parameters ------------------*/ +bool device_setparams(int nchanl,int rate) +{ + unsigned int val; + int dir; + int rc; + snd_pcm_hw_params_t *hw_params; + + //------ beware of following if..if...if..if...if...expressions ---------- + if(snd_pcm_hw_params_malloc (&hw_params ) < 0) + return false; //Ϊռ + // printf("---- snd_pcm_hw_params_malloc(&hw_params) ----\n"); + if(snd_pcm_hw_params_malloc (¶ms) < 0) + return false; + // printf("----snd_pcm_hw_params_malloc(¶ms) ----\n"); + if(snd_pcm_hw_params_any (pcm_handle, hw_params) < 0) + return false; //ʼ + // printf("----snd_pcm_hw_params_any(pcm_handle,hw_params)----\n"); + if(snd_pcm_hw_params_set_access (pcm_handle, hw_params,SND_PCM_ACCESS_RW_INTERLEAVED) < 0) + return false; //Ϊģʽ + // printf("----snd_pcm_hw_params_set_access()----\n"); + if(snd_pcm_hw_params_set_format( pcm_handle, hw_params, SND_PCM_FORMAT_S16_LE) < 0) + return false; //ʹ16λ + // printf("----snd_pmc_hw_params_set_format()-----\n"); + + val = rate;//8000; + if(snd_pcm_hw_params_set_rate_near(pcm_handle, hw_params,&val,0) < 0) + return false; //ò + // printf("----snd_pcm_hw_params_set_rate_near() val=%d----\n",val); + if(snd_pcm_hw_params_set_channels( pcm_handle, hw_params, nchanl) < 0) + return false; //Ϊor Mono. + // printf("----snd_pcm_hw_params_set_channels()-----\n"); + + frames = 32; + if(snd_pcm_hw_params_set_period_size_near(pcm_handle,hw_params,&chunk_size,&dir ) < 0 ) + return false; + // printf("----snd_pcm_hw_params_set_period_size_near() chunk_size=%d----\n",chunk_size); + if(snd_pcm_hw_params_get_period_size( hw_params, &period_size,0) < 0) + return false; //ȡڳ1536 + printf("----snd_pcm_hw_get_period_size(): %d frames----\n",(int) period_size ); + if(snd_pcm_hw_params_get_format(hw_params,&format_val ) < 0) + return false; + // printf("----snd_pcm_hw_params_get_format()----\n"); + + bit_per_sample = snd_pcm_format_width((snd_pcm_format_t) format_val ); + //printf("---bit_per_sample=%d snd_pcm_format_width()----\n",bit_per_sample); + //ȡ + snd_pcm_hw_params_get_channels(hw_params,&chanl_val ); + //printf("----snd_pcm_hw_params_get_channels %d---\n",chanl_val); + chunk_byte = period_size*bit_per_sample*chanl_val/8; //3072 this is the Max chunk byte size + //chunk_size = frames;//period_size; //frames + //ڳȣֽ(bytes) = ÿڵ * (bit) * ͨ / 8 + snd_pcm_hw_params_get_rate(hw_params,&rate_val,&dir); + snd_pcm_hw_params_get_channels(hw_params,&chanl_val); + + rc = snd_pcm_hw_params( pcm_handle, hw_params); //ò + if (rc < 0) + { + printf("unable to set hw parameters:%s\n",snd_strerror(rc)); + exit(1); + } + printf("finish setting sound hw parameters\n"); + params = hw_params; //Ժʹ + snd_pcm_hw_params_free( hw_params); //ͷŲռ + //printf("----snd_pcm_hw_params_free()----\n"); + + return true; +} +//ʹAlsaṩһϵ snd_pcm_hw_params_set_ Ϊֵ +//ͨ snd_pcm_hw_params ݸ豸 +//Ҫ˵ʽĿҪʧܵΪʾδǡ +//úòԿʼ¼ˡ¼ʵϾǴƵ豸жȡϢ档 + + +//------------------- record sound ------------------------------------// + bool device_capture() + { + int i; + int r = 0; + int total = 0; + int averg = 0; + char *data = wave_buf; // pointer to wave_buf position + int16_t *pv; //pointer to current data + //int CN = 7; //chunk_size = 2^CN + + //chunk_size = (2 << CN); //=frames + chunk_size = SAMPLE_RATE/CHECK_FREQ; //--how many frames to be checked for specified CHECK_FREQ,one channel + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + //printf("chunk_byte=%d\n",chunk_byte); + + //------------------ get start time ------------------ + gettimeofday(&t_start, NULL); + printf("Start Time: %lds + %ldus \n",t_start.tv_sec,t_start.tv_usec); + + while ((data-wave_buf) <= (wave_buf_len-chunk_byte)) + { //chunk_size*bit_per_sample*chanl_val)){ + r = snd_pcm_readi( pcm_handle,data,chunk_size); //chunk_size*bit_per_sample*read interleaved frames from a PCM + if(r == -EPIPE) + { + /* EPIPE means overrun */ + fprintf(stderr,"overrun occurred!\n"); + snd_pcm_prepare(pcm_handle);//try to recover. to put the stream in PREPARED state so it can start again next time. + } + else if (r < 0) + { + fprintf(stderr,"error from read:%s\n",snd_strerror(r)); + } + else if (r != chunk_size) + { + fprintf(stderr,"short read, read %d frames\n",r); + } + if (r > 0) + { + pv = (int16_t *)data; //--get pointer for chunk data + data += chunk_byte;//--move current buffer position pointer, short run is NOT considered!!! + //------------ checker timer, return when DELAY_TIME used up ---------------- + gettimeofday(&t_end,NULL); + cost_times = t_end.tv_sec-t_start.tv_sec; + if(cost_times >= DELAY_TIME) + { + wave_buf_used = data-wave_buf; + return true; + } + //----------- check sound wave amplitude ----------------- + averg = 0; + total = 0; + for (i = 0; i < r; i++) + { //r -- chunk_size,16bits each frame. + total += abs(*pv); // !!!!!! + pv += 1; + } + //printf("total = %d\n", total); + //averg = (total >> CN); + averg = (total/chunk_size); + //printf("averg = %d\n",averg); + if(averg >= KEEP_AVERG) + { + gettimeofday(&t_start,NULL); // reset timer, add one more DELAY_TIME for recording. + printf("averg = %d\n",averg); + printf("loud noise sensed!\n"); + } + } + /* + else //if(r<0) + { + wave_buf_used=data-wave_buf; + return false; + } + */ + } // end of while() + + wave_buf_used = data-wave_buf; //--short run is not considered!!! + + return true; +} + +//βdtimeȷ¼ʱ䣬¼ʱݿռ䣬ٵsnd_pcm_readiƵ豸ȡƵݣŵwave_bufС +//ͬԭһźƵ豸дݣ + +bool device_play() +{ + char *data = wave_buf; + int r = 0; + chunk_size = 32; + + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; + while ((data-wave_buf) <= (wave_buf_used-chunk_byte)) + { + r = snd_pcm_writei(pcm_handle, data , chunk_size); //chunk_size = frames + if(r == -EAGAIN) + continue; + if(r < 0) + { + printf("write error: %s\n",snd_strerror(r)); + //exit(EXIT_FAILURE); //ocassionally, it will exit here! + return false; + } + //printf("----- writei() r=%d -----\n ",r); + if ( r > 0 ) + data += chunk_byte; + else + return false; + } + + return true; +} + +bool device_check_voice(void) +{ + int i; + int r = 0; + int count = 0; + int total = 0; + int averg = 0;//average of sample values in one chunk. + int CN = 5; + + chunk_size = SAMPLE_RATE/CHECK_FREQ; //64--how many frames to be checked for specified CHECK_FREQ,one channel + //chunk_size = (2 << CN); //--frames each time + chunk_byte = chunk_size*bit_per_sample*chanl_val/8; //---128 bytes + int16_t *buf = (int16_t *)malloc(chunk_byte); //--sample width 16bits + int16_t *data = buf; + + printf("listening and checking any voice......\n"); + while(1) + { + r = snd_pcm_readi(pcm_handle, (char *) buf, chunk_size); //chunk_size*bit_per_sample*read interleaved rames from a PCM + + if(r == -EAGAIN) + continue; + if (r >= 0) + { + //printf(" r= %d \n ",r); + data = buf; + averg = 0; + total = 0; + for(i = 0; i < r; i++) + { + total += abs(*data); // !!!!!! + data += 1; + } + //printf("total=%d\n",total); + //averg=(total >> CN); + averg = (total/chunk_size); + //printf("averg=%d\n",averg); + if(averg >= CHECK_AVERG ) + { + printf("loud noise sensed! averg = %d chunk_size = %d\n", averg, chunk_size); + free(buf); + return true; + } + //usleep(20000); // + //snd_pcm_prepare(pcm_handle); + //usleep(10000); //---you cann't sleep here, + }//if + else + { + printf(" r = %d \n ",r); + free(buf); + return false; + } + } //while(1) + + free(buf); + + return true; +} + + + + + + diff --git a/mt7688-alsa/test.wav b/mt7688-alsa/test.wav new file mode 100755 index 00000000..557f7951 Binary files /dev/null and b/mt7688-alsa/test.wav differ diff --git a/oled b/oled new file mode 100755 index 00000000..45bcdb4e Binary files /dev/null and b/oled differ diff --git a/oled.c b/oled.c new file mode 100755 index 00000000..ba255272 --- /dev/null +++ b/oled.c @@ -0,0 +1,318 @@ +/*--------------------------------------------------------------- + use MRAA c lib to set and control I2C + compile with lib: gcc -L./ -lmraa oled.c +------------------------------------------------------------------*/ +#include "oled.h" +#include "oledfont.h" +#include "./include/mraa.h" + +#define I2C_0 0 + +//char str_dev = "/dev/i2c-0"; + +mraa_result_t res; +mraa_i2c_context i2c0; + +//Initialise i2c context, i2c bus to use +void init_i2c0() +{ + mraa_init(); + printf("Begin oled...\n"); + i2c0 = mraa_i2c_init(0x00); + //i2c0 = mraa_i2c_init_raw(I2C_0); + mraa_i2c_address(i2c0, 0x01); + //printf(".....%s\n", i2c0); + usleep(1000); + res = mraa_i2c_write_byte(i2c0, 0); + //printf(".....%s\n", i2c0); + //mraa_i2c_stop(i2c0); +} + +void IIC_Wait_Ack() +{ + //OLED_SCLK_Set() ; + //OLED_SCLK_Clr(); +} + +/********************************************** +// IIC Write Command +**********************************************/ +void Write_IIC_Command(unsigned char IIC_Command) +{ + mraa_i2c_write_byte(i2c0, 0x78); + IIC_Wait_Ack(); + mraa_i2c_write_byte(i2c0, 0x00); + IIC_Wait_Ack(); + mraa_i2c_write_byte(i2c0, IIC_Command); + IIC_Wait_Ack(); +} + +/********************************************** +// IIC Write Data +**********************************************/ +void Write_IIC_Data(unsigned char IIC_Data) +{ + mraa_i2c_write_byte(i2c0, 0x78); + IIC_Wait_Ack(); + mraa_i2c_write_byte(i2c0, 0x40); + IIC_Wait_Ack(); + mraa_i2c_write_byte(i2c0, IIC_Data); + IIC_Wait_Ack(); +} + +void OLED_WR_Byte(unsigned dat,unsigned cmd) +{ + if(cmd) + { + Write_IIC_Data(dat); + } + else + { + Write_IIC_Command(dat); + } +} + +/******************************************** +// fill_Picture +********************************************/ +void fill_picture(unsigned char fill_Data) +{ + unsigned char m,n; + for(m=0;m<8;m++) + { + OLED_WR_Byte(0xb0+m,0); //page0-page1 + OLED_WR_Byte(0x00,0); //low column start address + OLED_WR_Byte(0x10,0); //high column start address + for(n=0;n<128;n++) + { + OLED_WR_Byte(fill_Data,1); + } + } +} + +//set postion +void OLED_Set_Pos(unsigned char x, unsigned char y) +{ + OLED_WR_Byte(0xb0+y,OLED_CMD); + OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD); + OLED_WR_Byte((x&0x0f),OLED_CMD); +} + +//open oled display +void OLED_Display_On(void) +{ + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC commond + OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON + OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON +} + +//off oled display +void OLED_Display_Off(void) +{ + OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC commond + OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF + OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF +} + +//clear oled screen, after clear screen black +void OLED_Clear(void) +{ + u8 i,n; + for(i=0;i<8;i++) + { + OLED_WR_Byte (0xb0+i,OLED_CMD); //set page address (0-7) + OLED_WR_Byte (0x00,OLED_CMD); // + OLED_WR_Byte (0x10,OLED_CMD); // + for(n=0;n<128;n++) + OLED_WR_Byte(0,OLED_DATA); + } // +} + +void OLED_On(void) +{ + u8 i,n; + for(i=0;i<8;i++) + { + OLED_WR_Byte (0xb0+i,OLED_CMD); + OLED_WR_Byte (0x00,OLED_CMD); // + OLED_WR_Byte (0x10,OLED_CMD); // + for(n=0;n<128;n++) + OLED_WR_Byte(1,OLED_DATA); + } +} + +//display a char on use point +//x:0~127 +//y:0~63 +//mode:0,-;1,normal +//size:size 16/12 +void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size) +{ + unsigned char c=0,i=0; + c=chr-' ';// + if(x>Max_Column-1){x=0;y=y+2;} + if(Char_Size ==16) + { + OLED_Set_Pos(x,y); + for(i=0;i<8;i++) + OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); + OLED_Set_Pos(x,y+1); + for(i=0;i<8;i++) + OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); + } + else + { + OLED_Set_Pos(x,y); + for(i=0;i<6;i++) + OLED_WR_Byte(F6x8[c][i],OLED_DATA); + } +} + +//m^n function +u32 oled_pow(u8 m,u8 n) +{ + u32 result=1; + while(n--)result*=m; + return result; +} + +//display two number +//x,y :Begin point +//len :number of line +//size:front size +//mode:0 fill 1 +//num:value(0~4294967295); +void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2) +{ + u8 t,temp; + u8 enshow=0; + for(t=0;t120) + { + x=0; + y+=2; + } + j++; + } +} + +//display Chinese +void OLED_ShowCHinese(u8 x,u8 y,u8 no) +{ + u8 t,adder=0; + OLED_Set_Pos(x,y); + for(t=0;t<16;t++) + { + OLED_WR_Byte(Hzk[2*no][t],OLED_DATA); + adder+=1; + } + OLED_Set_Pos(x,y+1); + for(t=0;t<16;t++) + { + OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA); + adder+=1; + } +} + +/***********display BMP 128*64 (x,y) *****************/ +void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]) +{ + unsigned int j=0; + unsigned char x,y; + + if(y1%8==0) y=y1/8; + else y=y1/8+1; + for(y=y0;y +// #include +// #include +// #include +// #include +// #include + +//#define I2C_SCL I2C_SCLK; +//#define I2C_SDA I2C_SD; + +#define u8 unsigned char +#define u32 unsigned int +#define OLED_CMD 0 +#define OLED_DATA 1 + +#define SIZE 16 +#define XLevelL 0x02 +#define XLevelH 0x10 +#define Max_Column 128 +#define Max_Row 64 +#define Brightness 0xFF +#define X_WIDTH 128 +#define Y_WIDTH 64 + +//OLED +void OLED_WR_Byte(unsigned dat,unsigned cmd); +void OLED_Display_On(void); +void OLED_Display_Off(void); +void OLED_Init(void); +void OLED_Clear(void); +void OLED_DrawPoint(u8 x,u8 y,u8 t); +void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot); +void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size); +void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size); +void OLED_ShowString(u8 x,u8 y, u8 *p,u8 Char_Size); +void OLED_Set_Pos(unsigned char x, unsigned char y); +void OLED_ShowCHinese(u8 x,u8 y,u8 no); +void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[]); +void fill_picture(unsigned char fill_Data); +void Picture(); +//void IIC_Start(); +//void IIC_Stop(); +void Write_IIC_Command(unsigned char IIC_Command); +void Write_IIC_Data(unsigned char IIC_Data); +void Write_IIC_Byte(unsigned char IIC_Byte); +void IIC_Wait_Ack(); + +#endif diff --git a/oled_gpio b/oled_gpio new file mode 100755 index 00000000..0b38a5bc Binary files /dev/null and b/oled_gpio differ diff --git a/oled_gpio.c b/oled_gpio.c new file mode 100755 index 00000000..d0694384 --- /dev/null +++ b/oled_gpio.c @@ -0,0 +1,132 @@ +/************************************************************************************ +* Copyright (c), 2017, IMIO co.,LTD. +* All rights reserved. +* Author : zyc +* Version: 1.00 +* Date : 2017.4.10 +*************************************************************************************/ +#include "./include/mraa.h" +#include +#include + +// ------------------------------------------------------------ +// IO IIC +// SCL GPIO41 +// SDA GPIO42 +// ------------------------------------------------------------ +#define SCL 41 +#define SDA 42 + +#define high 1 +#define low 0 + +#define Brightness 0xCF +#define X_WIDTH 128 +#define Y_WIDTH 64 + +mraa_gpio_context gpio0; +mraa_gpio_context gpio1; + +void GPIO_Init() +{ + gpio0 = mraa_gpio_init(SCL); + gpio1 = mraa_gpio_init(SDA); + mraa_gpio_edge_mode(gpio0, MRAA_GPIO_EDGE_NONE); + mraa_gpio_edge_mode(gpio1, MRAA_GPIO_EDGE_NONE); + mraa_gpio_mode(gpio0, MRAA_GPIO_STRONG); + mraa_gpio_mode(gpio1, MRAA_GPIO_STRONG); + mraa_gpio_dir(gpio0, MRAA_GPIO_OUT); + mraa_gpio_dir(gpio1, MRAA_GPIO_OUT); +} + +/********************************************** +//IIC Start +**********************************************/ +void IIC_Start() +{ + mraa_gpio_write(gpio0, 1); + mraa_gpio_write(gpio1, 1); + mraa_gpio_write(gpio1, 0); + mraa_gpio_write(gpio0, 0); +} + +/********************************************** +//IIC Stop +**********************************************/ +void IIC_Stop() +{ + mraa_gpio_write(gpio0, 0); + mraa_gpio_write(gpio1, 0); + mraa_gpio_write(gpio0, 1); + mraa_gpio_write(gpio1, 1); +} + +/********************************************** +// 1yI2C??D䨰????? +**********************************************/ +void Write_IIC_Byte(unsigned char IIC_Byte) +{ + unsigned char i; + for(i=0;i<8;i++) + { + if(IIC_Byte & 0x80) + mraa_gpio_write(gpio1, 1); + else + mraa_gpio_write(gpio1, 0); + mraa_gpio_write(gpio0, 1); + mraa_gpio_write(gpio0, 0); + IIC_Byte<<=1; + } + mraa_gpio_write(gpio1, 1); + mraa_gpio_write(gpio0, 1); + mraa_gpio_write(gpio0, 0); +} + +/*********************OLEDD䨺y?Y************************************/ +void OLED_WrDat(unsigned char IIC_Data) +{ + IIC_Start(); + Write_IIC_Byte(0x78); + Write_IIC_Byte(0x40); //write data + Write_IIC_Byte(IIC_Data); + IIC_Stop(); +} +/*********************OLEDD??************************************/ +void OLED_WrCmd(unsigned char IIC_Command) +{ + IIC_Start(); + Write_IIC_Byte(0x78); //Slave address,SA0=0 + Write_IIC_Byte(0x00); //write command + Write_IIC_Byte(IIC_Command); + IIC_Stop(); +} + +int main() +{ + mraa_init(); + printf("1\n"); + gpio0 = mraa_gpio_init(SCL); + gpio1 = mraa_gpio_init(SDA); + printf("2\n"); + mraa_gpio_edge_mode(gpio0, MRAA_GPIO_EDGE_NONE); + mraa_gpio_edge_mode(gpio1, MRAA_GPIO_EDGE_NONE); + printf("3\n"); + mraa_gpio_mode(gpio0, MRAA_GPIO_STRONG); + mraa_gpio_mode(gpio1, MRAA_GPIO_STRONG); + printf("4\n"); + mraa_gpio_dir(gpio0, MRAA_GPIO_OUT); + mraa_gpio_dir(gpio1, MRAA_GPIO_OUT); + printf("5\n"); + + while(1) + { + mraa_gpio_write(gpio0, 1); + mraa_gpio_write(gpio1, 1); + sleep(3); + mraa_gpio_write(gpio1, 0); + mraa_gpio_write(gpio0, 0); + } + + return 0; +} + diff --git a/oledfont.h b/oledfont.h new file mode 100755 index 00000000..2b11a815 --- /dev/null +++ b/oledfont.h @@ -0,0 +1,230 @@ +#ifndef __OLEDFONT_H +#define __OLEDFONT_H +//ASCII +//ƫ32 +//ASCIIַ +//ƫ32 +//С:12*6 +/************************************6*8ĵ************************************/ +const unsigned char F6x8[][6] = +{ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp +0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// ! +0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// " +0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// # +0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $ +0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// % +0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// & +0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ' +0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// ( +0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// ) +0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// * +0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// + +0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// , +0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// - +0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// . +0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// / +0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 +0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 +0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2 +0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 +0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 +0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5 +0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 +0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7 +0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8 +0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 +0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// : +0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ; +0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// < +0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// = +0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// > +0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ? +0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @ +0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A +0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B +0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C +0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D +0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E +0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F +0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G +0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H +0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I +0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J +0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K +0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L +0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M +0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N +0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O +0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P +0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q +0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R +0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S +0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T +0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U +0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V +0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W +0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X +0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y +0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z +0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [ +0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55 +0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ] +0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^ +0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _ +0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// ' +0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a +0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b +0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c +0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d +0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e +0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f +0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g +0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h +0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i +0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j +0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k +0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l +0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m +0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n +0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o +0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p +0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q +0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r +0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s +0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t +0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u +0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v +0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w +0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x +0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y +0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z +0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines +}; +/****************************************8*16ĵ************************************/ +const unsigned char F8X16[]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; +unsigned char Hzk[][32]={ + +{0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00}, +{0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00},/*"",0*/ + +{0x40,0x40,0x40,0x5F,0x55,0x55,0x55,0x75,0x55,0x55,0x55,0x5F,0x40,0x40,0x40,0x00}, +{0x00,0x40,0x20,0x0F,0x09,0x49,0x89,0x79,0x09,0x09,0x09,0x0F,0x20,0x40,0x00,0x00},/*"",1*/ + +{0x00,0xFE,0x02,0x42,0x4A,0xCA,0x4A,0x4A,0xCA,0x4A,0x4A,0x42,0x02,0xFE,0x00,0x00}, +{0x00,0xFF,0x40,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0xFF,0x00,0x00},/*"԰",2*/ + +{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00}, +{0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"",3*/ + +{0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"",4*/ + +{0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00}, +{0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00},/*"",5*/ + +{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00}, +{0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"",6*/ + +}; + +#endif + + diff --git a/openwrt-gcc b/openwrt-gcc deleted file mode 120000 index cc71956e..00000000 --- a/openwrt-gcc +++ /dev/null @@ -1 +0,0 @@ -/home/midas/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc \ No newline at end of file diff --git a/openwrt-gcc b/openwrt-gcc new file mode 100755 index 00000000..a1c86192 --- /dev/null +++ b/openwrt-gcc @@ -0,0 +1 @@ +/home/zyc/Documents/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc \ No newline at end of file diff --git a/pwm_test b/pwm_test deleted file mode 100755 index 0c0f2380..00000000 Binary files a/pwm_test and /dev/null differ diff --git a/pwmclose b/pwmclose index 5e24bae7..d98fa37b 100755 Binary files a/pwmclose and b/pwmclose differ diff --git a/pwmtest b/pwmtest index ecf29942..c5a4f829 100755 Binary files a/pwmtest and b/pwmtest differ diff --git a/pwmtest.c b/pwmtest.c index 2b414ea8..96692199 100755 --- a/pwmtest.c +++ b/pwmtest.c @@ -1,79 +1,87 @@ -/*--------------------------------------------------------------- - use MRAA c lib to set and control PWM - compile with lib: gcc -L./ -lmraa pwmtest.c -------------------------------------------------------------------*/ -#include "./include/mraa.h" -#include -#include - -typedef enum { // pin number 18,19,20,21 - GPIO18=18, - GPIO19=19, - GPIO20=20, - GPIO21=21} GPIO_pin; - -int main(int argc,char* argv[]) -{ - - int perus=1000;// period us - float pers; // period s - float tmp_duty=0; - float duty=0.5; // duty percentage - GPIO_pin pin=20; - int temp; - int Max_Period_Us,Min_Period_Us; - - printf("Please enter:\n GPIO number----(18,19,20,21 defaul=20)\ - \n period----(us, default=1000us)\n Duty----(0~1, default=0.5)!\n"); - printf("Periods 1us ~ 26999us \n"); - - if(argc>1) - { - temp=atoi(argv[1]); - if(temp<18 || temp>21) - printf("GPIO number error!"); - else - pin=temp; - } - - if(argc>2) - perus=atoi(argv[2]); - - if(argc>3) - tmp_duty=atof(argv[3]); - - if(tmp_duty>=0 && tmp_duty<=1) - duty=tmp_duty; - - mraa_result_t res; - mraa_pwm_context pwm; - - pwm=mraa_pwm_init(pin); - mraa_pwm_owner(pwm,1); - mraa_pwm_enable(pwm,1); - mraa_pwm_write(pwm,0); //---set duty to 0 first - - if(perus<=1000) - res=mraa_pwm_period_us(pwm,perus); //-- us MAX 26214us - if(perus>=20000) - { - pers=perus/1000000.0; - printf("pers=%9.6f\n",pers); - res=mraa_pwm_period(pwm,pers); //-- s - } - if(perus>1000 && perus<20000) - res=mraa_pwm_period_ms(pwm,perus/1000); //-- ms MAX 26ms - - if(res!=0) - printf("Period set fail!\n"); - else - printf("Period:%dus set succeed!\n",perus); - - res=mraa_pwm_write(pwm,duty); - if(res!=0) - printf("Duty set fail!\n"); - else - printf("Duty:%4.3f set succeedy!\n",duty); - - return 0; -} +/*--------------------------------------------------------------- + use MRAA c lib to set and control PWM + compile with lib: gcc -L./ -lmraa pwmtest.c +------------------------------------------------------------------*/ +#include "./include/mraa.h" +#include +#include + +typedef enum { // pin number 18,19,20,21 + GPIO18=18, + GPIO19=19, + GPIO20=20, + GPIO21=21} GPIO_pin; + +int main(int argc,char* argv[]) +{ + + int perus=1000;// period us + float pers; // period s + float tmp_duty=0; + float duty=0.5; // duty percentage + GPIO_pin pin=20; + int temp; + int Max_Period_Us,Min_Period_Us; + + printf("Please enter:\n GPIO number----(18,19,20,21 defaul=20)\ + \n period----(us, default=1000us)\n Duty----(0~1, default=0.5)!\n"); + printf("Periods 1us ~ 26999us \n"); + + if(argc>1) + { + temp=atoi(argv[1]); + if(temp<18 || temp>21) + printf("GPIO number error!"); + else + pin=temp; + } + + if(argc>2) + perus=atoi(argv[2]); + + if(argc>3) + tmp_duty=atof(argv[3]); + + if(tmp_duty>=0 && tmp_duty<=1) + duty=tmp_duty; + + printf("1...\n"); + mraa_result_t res; + mraa_pwm_context pwm; + + pwm=mraa_pwm_init(19); + if (pwm == NULL) + { + printf("2...init failed!\n"); + } + res = mraa_pwm_owner(pwm,1); + printf("3...%d\n",res); + res = mraa_pwm_enable(pwm,1); + printf("4....%d\n",res); + mraa_pwm_write(pwm,0); //---set duty to 0 first + printf("5...\n"); + + if(perus<=1000) + res=mraa_pwm_period_us(pwm,perus); //-- us MAX 26214us + if(perus>=20000) + { + pers=perus/1000000.0; + printf("pers=%9.6f\n",pers); + res=mraa_pwm_period(pwm,pers); //-- s + } + if(perus>1000 && perus<20000) + res=mraa_pwm_period_ms(pwm,perus/1000); //-- ms MAX 26ms + + if(res!=0) + printf("Period set fail!\n"); + else + printf("Period:%dus set succeed!\n",perus); + + res=mraa_pwm_write(pwm,duty); + if(res!=0) + printf("Duty set fail!\n"); + else + printf("Duty:%4.3f set succeedy!\n",duty); + + return 0; +} diff --git a/test b/test index 136217de..2c16a1aa 100755 Binary files a/test and b/test differ