Skip to content
Browse files

added playback, added init API

  • Loading branch information...
1 parent f31e462 commit a96dff9622f0e9560bb488613b53d6947475a084 Tobias Bielohlawek committed
Showing with 89 additions and 40 deletions.
  1. +18 −0 bytecode/lib/init.mtl
  2. +63 −31 bytecode/lib/playback.mtl
  3. +7 −8 bytecode/main.mtl
  4. +1 −1 lib/nabaztag_hack_kit/message/helper.rb
View
18 bytecode/lib/init.mtl
@@ -0,0 +1,18 @@
+//###############################################
+//------------------ INIT ----------------------
+
+var inited = 0;;
+
+fun initUrl =
+ strcatlist confGetServerUrl::apiPath::"/init.jsp?"::nil;;
+
+//-------------------------------------------------------------
+
+fun initCheck=
+ if inited == 0 then
+ (
+ httprequest "GET" initUrl "" #_cbHttp HTTP_NORMAL;
+ set inited = 1
+ )
+;;
+
View
94 bytecode/lib/playback.mtl
@@ -10,55 +10,87 @@ fun playbackLoadFinishedUrl =
fun streamUrl filename=
strcatlist confGetServerUrl::"/streams/"::filename::nil;;
-var wav_http;;
-var playback_fifo;;
+const PLAY_IDLE = 0;;
+const PLAY_RUN = 1;;
+//const WAV_EOF=2;;
+
+//var wav_http;;
+var playback_fifo = nil;;
+var playback_load_fifo;;
var playback_state = 0;;
+var play_index = 0;;
-// fun playbackStart =
-// ;;
+//wat is this for!??
+var wav_zeros;;
+fun wavgetzeros=
+ if wav_zeros==nil then
+ (
+ set wav_zeros=strnew 2048;
+ for i=0;i<2048 do strset wav_zeros i 0
+ );
+ wav_zeros;;
-// fun playbackStop =
-// ;;
fun playbackStop =
- if playback_state != WAV_IDLE then
+ if playback_state != PLAY_IDLE then
(
playStop;
- if wav_http != nil then httpabort wav_http;
- set wav_http = nil;
- set wav_buffering = 0;
- set playback_state = WAV_IDLE
- );;
+ // if wav_http != nil then httpabort wav_http;
+ // set wav_http = nil;
+ // set wav_buffering = 0;
+ set playback_state = PLAY_IDLE
+ );
+0;;
-fun _playbackStart =
- set wav_index = 0;
- set wav_buffering = 1;
- set wav_buffering_since = time_ms;
- playStart 1024 #_wavplaycb;;
+// fun _playbackStart =
+// set wav_index = 0;
+// set wav_buffering = 1;
+// set wav_buffering_since = time_ms;
+// playStart 1024 #_wavplaycb;
+// 0;;
-fun _playbackStart l timeout=
+fun _playbackCB i=
+ let hd playback_fifo -> sample in
+ let strlen sample -> len in
+ (
+ if play_index < len then (
+ // send some bytes to the VM buffer.
+ let (playFeed sample play_index nil) -> pushedbytes in
+ (
+ // this is how many bytes we sent.
+ set play_index = play_index + pushedbytes
+ )
+ )
+ );
+0;;
+
+fun _playbackStart play_data=
playbackStop;
- set wav_end_timeout = timeout;
- set wav_fifo = conc l (wavgetzeros)::nil;
- set playback_state = WAV_EOF;
- set wav_lasttime = time_ms;
- set wav_http = nil;
- _wavstartnow
- ;;
+ //set wav_end_timeout = timeout;
+ set playback_fifo = conc play_data wavgetzeros::nil;
+ playStart 1024 #_playbackCB;
+ // set playback_state = WAV_EOF;
+ // set wav_lasttime = time_ms;
+ // set wav_http = nil;
+ set play_index = 0;
+ // set wav_buffering=1;
+ // set wav_buffering_since = time_ms;
+0;;
-fun playbackStart l=
- _playbackStart l WAV_END_TIMEOUT;;
+fun playbackStart =
+ _playbackStart playback_load_fifo;;
+//-------------- LOAD
fun _playbackLoadCB httpreq req=
if req != nil then
(
- set playback_fifo = conc playback_fifo req::nil
+ set playback_load_fifo = conc playback_load_fifo req::nil
);
0;;
fun playbackLoad val=
- set playback_fifo = nil;
- set wav_http = httprequest "GET" (streamUrl val) nil #_playbackLoadCB HTTP_STREAM;
- 0;;
+ set playback_load_fifo = nil;
+ httprequest "GET" (streamUrl val) nil #_playbackLoadCB HTTP_NORMAL;
+0;;
// fun playbackStream val=
View
15 bytecode/main.mtl
@@ -107,26 +107,23 @@ fun evalTrame res=
// play start
else if code == 60 then
(
- wavstartlocal playback_fifo;
- // playbackStart;
- 0
+ playbackStart
)
// play stop
else if code == 61 then
(
- // playbackStop;
- 0
+ playbackStop
)
// play load
else if code == 62 then
(
- playbackLoad val;
- 0
+ playbackLoad val
)
// play stream
else if code == 63 then
(
// playbackStream val;
+ wavstarthttp (streamUrl val) nil;
0
)
)
@@ -136,6 +133,8 @@ fun evalTrame res=
//###############################################
//-------------------- LOOP ---------------------
fun loop=
+ initCheck;
+
wifiRun;
wifiCheck;
@@ -147,7 +146,7 @@ fun loop=
earRead 1;
pingCheck;
- wavtime;
+ //wavtime;
recordingCheck;
0;;
View
2 lib/nabaztag_hack_kit/message/helper.rb
@@ -38,7 +38,7 @@ def fire(color = 0x110000, led1 = LED_L1, led2 = LED_L2, led3 = LED_L3)
}
end
- def wink(s = 1, e = 4, times = 5)
+ def wink(s = 1, e = 4, times = 3)
{
EAR_L => ([s,e] * times) + [s],
EAR_R => [s] + ([s,e] * times)

0 comments on commit a96dff9

Please sign in to comment.
Something went wrong with that request. Please try again.