[1d4b9c]: cmd.c Maximize Restore History

Download this file

cmd.c    185 lines (150 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
******************************************************************************
* @file cmd.c
* @brief CMD-Handler for STM8.
* Application example.
* @author Georg Ottinger
* @version V0.0.2
* @date 10-APR-2012
******************************************************************************
Copyright (C) 2011 Georg Ottinger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Includes ------------------------------------------------------------------*/
#include "includes.h"
unsigned char state = STATE_IDLE;
void cmd_stm(void)
{
switch(state)
{
case STATE_IDLE:
leds_left = 0;
leds_right = 0;
break;
case STATE_STARTSTREAMING:
write_state_eeprom(1);
InitVS1053();
VS1063StartOgg();
state = STATE_STREAMING;
break;
case STATE_STREAMING:
VS1053StreamOgg();
VS1063DispVUMeter();
break;
case STATE_STOPSTREAMING_STAGE1:
write_state_eeprom(0);
VS1063StopStreaming();
state = STATE_STOPSTREAMING_STAGE2;
break;
case STATE_STOPSTREAMING_STAGE2:
VS1053StreamOgg();
if(VS1063HasStopped())
{
VS1063StreamOggClose();
state = STATE_IDLE;
}
break;
case STATE_STARTVUONLY:
InitVS1053();
VS1063StartOgg();
state = STATE_VUONLY;
break;
case STATE_VUONLY:
VS1063DispVUMeter();
break;
case STATE_STOPVUONLY_STAGE1:
VS1063StopStreaming();
state = STATE_STOPVUONLY_STAGE2;
break;
case STATE_STOPVUONLY_STAGE2:
if(VS1063HasStopped())
{
state = STATE_IDLE;
}
break;
default:
break;
}
}
void process_cmd(void)
{
unsigned char cmd;
unsigned char arg;
cmd = RXBuffer_ReadBytes();
arg = cmd & 0xf;
cmd &= 0xf0;
switch(cmd)
{
case CMD_CTRL:
switch(arg)
{
case ARG_CTRL_STARTSTREAM:
state=STATE_STARTSTREAMING;
break;
case ARG_CTRL_VUONLY:
state=STATE_STARTVUONLY;
break;
case ARG_CTRL_STOPSTREAM:
state = STATE_STOPSTREAMING_STAGE1;
break;
case ARG_CTRL_STOPVUONLY:
state=STATE_STOPVUONLY_STAGE1;
default:
break;
}
break;
case CMD_ONAIR:
SetOnAirLED(arg,0);
break;
case CMD_ONAIRBLINK:
SetOnAirLED(1,arg);
break;
case CMD_SET_QUALITY:
if(arg <= 10)
{
vs1063_options.quality = arg;
vs1063_options.bitratemode = 0;
}
break;
case CMD_SET_BITRATE:
vs1063_options.kbitrate = 32 + (unsigned short)arg * 16;
vs1063_options.bitratemode = 1;
break;
case CMD_STATUSLED_LEFT:
leds_status &= 0x0f;
leds_status |= arg << 4;
break;
case CMD_STATUSLED_RIGHT:
leds_status &= 0xf0;
leds_status |= (arg&0x4) >> 2 | (arg&0x2) | (arg&0x1) << 2;
break;
case CMD_SAMPLERATE:
if(arg < (sizeof(vs1063_samplerate)/2))
vs1063_options.samplerate=vs1063_samplerate[arg];
break;
case CMD_GETSTATUS:
switch(arg)
{
case ARG_GETSTATUS_UID:
send_uid();
break;
case ARG_GETSTATUS_EEPROMSTATE:
UART2_WaitTX();
UART2_SendData8(eepromstate.last_state);
break;
default:
break;
}
default:
break;
}
}