void LCD_Low_Level::sendData(uint8_t value, uint8_t rs_bit) {
  
	writeControl(rs_bit, 0);
	
	if (_display_function & LCD_8BitMode) {
		write8bits(value);
	} else {
		write4bits((value & 0xF0)>>4);
		write4bits(value & 0x0F);
	}
}
Exemple #2
0
//Initializes the LCD as described in the HD44780 datasheet.
//Normally called only by the initialize() function in utility.c.
void lcdInit()
{
	//configure LCD E (Enable) control pin as an output
	sbi(DDRD, 6);
	//configure LCD RS (Register Select) control pin as an output
	sbi(DDRD, 7);
	//set LCD E (Enable) line low inititally, so it can rise later
	cbi(PORTD, 6);

	//wait 15ms after power on
	delayMs(15);

	//Issue 'Function Set' commands to initialize LCD for 8-bit interface mode
	writeControl(0x38);
	delayUs(4900); //+100us in writeControl = 5000us or 5ms total
	writeControl(0x38);
	delayUs(50); //+100us in writeControl = 150us total
	writeControl(0x38);

	//Function Set command to specify 2 display lines and character font
	writeControl(0x38);

	//Display off
	lcdOff();

	//Clear display
	clearScreen();

	//Set entry mode
	writeControl(0x06);

	//Display on
	lcdOn();
}
void Intel8255::writeByPort(uint8_t p03,uint8_t data) {
    switch (p03) {
        case 0: writePortA(data);   break;
        case 1: writePortB(data);   break;
        case 2: writePortC(data);   break;
        case 3: writeControl(data); break;
    }
}
Exemple #4
0
//
// send a heartbeat and record time
// The "last heartbeat" time is recorded in a global variable
// such that the service thread can decice whether a new
// heartbeat is due.
//
static void heartbeat()
{
    unsigned char seq[2];

    seq[0] = 0x7e;
    seq[1] = 0xfe;
    writeControl(seq, 2);
    lastbeat = time(NULL);
}
void Intel8255::reset(void) {
    IBF_A  = IBF_B =  0;
    OBF_A  = OBF_B =  0;
    INTE_A = INTE_B = 0;
    INTE_1 = INTE_2 = 0;
    INTR_A = INTR_B = 0;
    writeControl(0x9B); /* default: port A input, port B input, port C input mode 0 mode 0 */
    latchOutPortA = 0;
    latchOutPortB = 0;
    latchOutPortC = 0;
}
Exemple #6
0
//
// Number of stop bits must be 1 or 2.
// Number of data bits can be 5,6,7,8
// Hardware handshake (rtscts) can be on of off.
// microHam devices ALWAY use "no parity".
//
int uh_open_radio(int baud, int databits, int stopbits, int rtscts)
{
    unsigned char string[5];
    int baudrateConst;

    if (!uh_is_initialized)
    {
        start_thread();
    }

    if (!uh_is_initialized)
    {
        return -1;
    }

    baudrateConst = 11059200 / baud ;
    string[0] = 0x01;
    string[1] = baudrateConst & 0xff ;
    string[2] = baudrateConst / 256 ;

    switch (stopbits)
    {
    case 1:  string[3] = 0x00; break;

    case 2:  string[3] = 0x40; break;

    default: return -1;
    }

    if (rtscts)
    {
        string[3] |= 0x10;
    }

    switch (databits)
    {
    case 5: break;

    case 6: string[3] |= 0x20; break;

    case 7: string[3] |= 0x40; break;

    case 8: string[3] |= 0x60; break;

    default: return -1;
    }

    string[4] = 0x81;
    writeControl(string, 5);

    uh_radio_in_use = 1;
    return uh_radio_pair[1];
}
uint8_t LCD_Low_Level::receive(uint8_t rs_bit) {
	
	writeControl(rs_bit, 1);
	
	int data = 0;
	
	if (_display_function & LCD_8BitMode) {
		data = read8bits();
	} else {
		data = (read4bits() & 0x0F) << 4;
		data = data | (read4bits() & 0x0F);
	}
	return data;
}
Exemple #8
0
void Motor::setPitch(int pitch)
	{
	/* Limit the pitch value to valid interval to prevent motor breakage: */
	if(pitch<-35)
		pitch=-35;
	if(pitch>55)
		pitch=55;
	
	/* Convert the pitch value to unsigned int: */
	if(pitch<0)
		pitch+=65536;
	
	/* Write a pitch control message: */
	writeControl(0x40,0x31,pitch,0x0000,0,0);
	}
Exemple #9
0
/**
 * Set register value
 * @param name - register name
 * @param val - new value
 */
void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) {
    scpi_bool_t srq = FALSE;
    scpi_reg_val_t mask;
    scpi_reg_val_t old_val;

    if ((name >= SCPI_REG_COUNT) || (context->registers == NULL)) {
        return;
    }
    
    /* store old register value */
    old_val = context->registers[name];

    /* set register value */
    context->registers[name] = val;

    /** @TODO: remove recutsion */
    switch (name) {
        case SCPI_REG_STB:
            mask = SCPI_RegGet(context, SCPI_REG_SRE);
            mask &= ~STB_SRQ;
            if (val & mask) {
                val |= STB_SRQ;
                /* avoid sending SRQ if nothing has changed */
                if (old_val != val) {
                    srq = TRUE;
                }
            } else {
                val &= ~STB_SRQ;
            }
            break;
        case SCPI_REG_SRE:
            regUpdate(context, SCPI_REG_STB);
            break;
        case SCPI_REG_ESR:
            regUpdateSTB(context, val, SCPI_REG_ESE, STB_ESR);
            break;
        case SCPI_REG_ESE:
            regUpdate(context, SCPI_REG_ESR);
            break;
        case SCPI_REG_QUES:
            regUpdateSTB(context, val, SCPI_REG_QUESE, STB_QES);
            break;
        case SCPI_REG_QUESE:
            regUpdate(context, SCPI_REG_QUES);
            break;
        case SCPI_REG_OPER:
            regUpdateSTB(context, val, SCPI_REG_OPERE, STB_OPS);
            break;
        case SCPI_REG_OPERE:
            regUpdate(context, SCPI_REG_OPER);
            break;
            
            
        case SCPI_REG_COUNT:
            /* nothing to do */
            break;
    }

    /* set updated register value */
    context->registers[name] = val;

    if (srq) {
        writeControl(context, SCPI_CTRL_SRQ, SCPI_RegGet(context, SCPI_REG_STB));
    }
}
Exemple #10
0
void Motor::setLED(Motor::LEDState newLEDState)
	{
	/* Write an LED control message: */
	writeControl(0x40,0x06,newLEDState,0x0000,0,0);
	}
Exemple #11
0
//Hides the characters on the screen. Can be unhidden again with lcdOn().
void lcdOff()
{
	writeControl(0x08);
}
Exemple #12
0
//Shows the characters on the screen.
void lcdOn()
{
	writeControl(0x0C);
}
Exemple #13
0
//Clears all characters on the display and resets the cursor to the home position.
void clearScreen()
{
	writeControl(0x01);
	delayUs(3300);
}
bool TinyAmixerControl::accessHW(bool receive, std::string &error)
{
    CAutoLog autoLog(getConfigurableElement(), "ALSA", isDebugEnabled());

    // Mixer handle
    struct mixer *mixer;
    // Mixer control handle
    struct mixer_ctl *mixerControl;
    uint32_t elementCount;
    std::string controlName = getControlName();

    // Debug conditionnaly enabled in XML
    logControlInfo(receive);

    // Check parameter type is ok (deferred error, no exceptions available :-()
    if (!isTypeSupported()) {

        error = "Parameter type not supported.";
        return false;
    }

    // Check card number
    int32_t cardIndex = getCardNumber();
    if (cardIndex < 0) {

        error = "Card " + getCardName() + " not found. Error: " + strerror(-cardIndex);
        return false;
    }

    // Open alsa mixer
    // getMixerHandle is non-const; we need to forcefully remove the constness
    // then, we need to cast the generic subsystem into a TinyAlsaSubsystem.
    mixer = static_cast<TinyAlsaSubsystem *>(
        const_cast<CSubsystem *>(getSubsystem()))->getMixerHandle(cardIndex);

    if (!mixer) {

        error = "Failed to open mixer for card: " + getCardName();
        return false;
    }

    // Get control handle
    if (isdigit(controlName[0])) {

        mixerControl = mixer_get_ctl(mixer, asInteger(controlName));
    } else {

        mixerControl = mixer_get_ctl_by_name(mixer, controlName.c_str());
    }

    // Check control has been found
    if (!mixerControl) {
        error = "Failed to open mixer control: " + controlName;

        return false;
    }

    // Get element count
    elementCount = getNumValues(mixerControl);

    uint32_t scalarSize = getScalarSize();

    // Check available size
    if (elementCount * scalarSize != getSize()) {

        error = "ALSA: Control element count (" + asString(elementCount) +
                ") and configurable scalar element count (" +
                asString(getSize() / scalarSize) + ") mismatch";

        return false;
    }

    // Read/Write element
    bool success;
    if (receive) {

        success = readControl(mixerControl, elementCount, error);

    } else {

        success = writeControl(mixerControl, elementCount, error);

    }

    return success;
}
Exemple #15
0
/*
 * If we do not have pthreads, we cannot use the microham device.
 * This is so because we have to digest unsolicited messages
 * (e.g. voltage change) and since we have to send periodic
 * heartbeats.
 * Nevertheless, the program should compile well even we we do not
 * have pthreads, in this case start_thread is a dummy since uh_is_initialized
 * is never set.
 *
 * If we do not have socketpair(), the same thing applies.
 *
 * If we do not have select(), then the read thread cannot work so we
 * do not spawn it.
 */
static void start_thread()
{
#if defined(HAVE_PTHREAD) && defined(HAVE_SOCKETPAIR) && defined(HAVE_SELECT)
    /*
     * Find a microHam device and open serial port to it.
     * If successful, create sockets for doing I/O from within hamlib
     * and start a thread to listen to the "other ends" of the sockets
     */
    int ret, fail;
    unsigned char buf[4];
    pthread_attr_t attr;

    if (uh_is_initialized)
    {
        return;  // PARANOIA: this should not happen
    }

    finddevices();

    if (uh_device_fd  < 0)
    {
        MYERROR("Could not open any microHam device.\n");
        return;
    }

    // Create socket pairs
    if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_radio_pair)  < 0)
    {
        perror("RadioPair:");
        return;
    }

    if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_ptt_pair)    < 0)
    {
        perror("PTTPair:");
        return;
    }

    if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_wkey_pair) < 0)
    {
        perror("WkeyPair:");
        return;
    }

    DEBUG("RADIO  sockets: server=%d  client=%d\n", uh_radio_pair[0],
          uh_radio_pair[1]);
    DEBUG("PTT    sockets: server=%d  client=%d\n", uh_ptt_pair[0], uh_ptt_pair[1]);
    DEBUG("WinKey sockets: server=%d  client=%d\n", uh_wkey_pair[0],
          uh_wkey_pair[1]);

    //
    // Make the sockets nonblocking
    // First try if we can set flags, then do set the flags
    //

    fail = 0;

    ret = fcntl(uh_radio_pair[0], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_radio_pair[0], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    ret = fcntl(uh_ptt_pair[0], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_ptt_pair[0], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    ret = fcntl(uh_wkey_pair[0], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_wkey_pair[0], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    ret = fcntl(uh_radio_pair[1], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_radio_pair[1], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    ret = fcntl(uh_ptt_pair[1], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_ptt_pair[1], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    ret = fcntl(uh_wkey_pair[1], F_GETFL, 0);

    if (ret != -1)
    {
        ret = fcntl(uh_wkey_pair[1], F_SETFL, ret | O_NONBLOCK);
    }

    if (ret == -1)
    {
        fail = 1;
    }

    //
    // If something went wrong, close everything and return
    //
    if (fail)
    {
        close_all_files();
        return;
    }

    // drain input from microHam device
    while (read(uh_device_fd, buf, 1) > 0)
    {
        // do_nothing
    }

    uh_is_initialized = 1;
    starttime = time(NULL);

    // Do some heartbeats to sync-in
    heartbeat();
    heartbeat();
    heartbeat();

    // Set keyer mode to DIGITAL
    buf[0] = 0x0A; buf[1] = 0x03; buf[2] = 0x8a; writeControl(buf, 3);

    // Start background thread reading the microham device and the sockets
    pthread_attr_init(&attr);
    ret = pthread_create(&readthread, &attr, read_device, NULL);

    if (ret != 0)
    {
        MYERROR("Could not start read_device thread\n");
        close_all_files();
        uh_is_initialized = 0;
        return;
    }

    TRACE("Started daemonized thread reading microHam\n");
#endif
// if we do not have pthreads, this function does nothing.
}
Exemple #16
0
//Moves the LCD cursor to the beginning of the second line of the display (row 1).
void lowerLine(void)
{
	writeControl(SECOND_LINE);
}