Example #1
0
/* Logical LCD operations */
void Nokia1202::begin(boolean useCursor, uint8_t contrast, uint8_t tabSpacing)
{
  uint16_t i;

  _contrast = contrast;
  _useCursor = useCursor;
  _tabSpacing = tabSpacing;

  digitalWrite(_csPin, HIGH);
  pinMode(_csPin, OUTPUT);
  delay(1);

  issuecmd(STE2007_CMD_RESET, 0, STE2007_MASK_RESET);  // Soft RESET
  issuecmd(STE2007_CMD_DPYALLPTS, 0, STE2007_MASK_DPYALLPTS); // Powersave ALLPOINTS-ON mode turned OFF
  issuecmd(STE2007_CMD_PWRCTL, 7, STE2007_MASK_PWRCTL); // Power control set to max
  issuecmd(STE2007_CMD_ONOFF, 1, STE2007_MASK_ONOFF); // Display ON
  issuecmd(STE2007_CMD_COMDIR, 0, STE2007_MASK_COMDIR); // Display common driver = NORMAL
  issuecmd(STE2007_CMD_SEGMENTDIR, 0, STE2007_MASK_SEGMENTDIR); // Lines start at the left
  issuecmd(STE2007_CMD_ELECTVOL, _contrast, STE2007_MASK_ELECTVOL); // Electronic volume set to user specified contrast

  clear();

  issue_compoundcmd(STE2007_CMD_REFRESHRATE, 3, STE2007_MASK_REFRESHRATE); // Refresh rate = 65Hz
  issue_compoundcmd(STE2007_CMD_CHARGEPUMP, 0, STE2007_MASK_CHARGEPUMP); // Charge Pump multiply factor = 5x
  issuecmd(STE2007_CMD_SETBIAS, 6, STE2007_MASK_SETBIAS); // Bias ratio = 1/4
  issue_compoundcmd(STE2007_CMD_VOP, 0, STE2007_MASK_VOP);
  issuecmd(STE2007_CMD_DPYREV, 0, STE2007_MASK_DPYREV); // Display normal (not inverted)
}
bool PWSRun::runcmd(const StringX &run_command, const bool &bAutotype) const
{
  // Get first parameter either enclosed by quotes or delimited by a space
  StringX full_string(run_command), first_part(_T("")), the_rest(_T(""));
  StringX env_var, sx_temp(_T(""));
  StringX::size_type end_delim;
  bool bfound(true);

  TrimLeft(full_string, _T(" "));
  if (full_string.c_str()[0] == _T('"')) {
    end_delim = full_string.find(_T('"'), 1);
    first_part = full_string.substr(1, end_delim - 1);
    the_rest = full_string.substr(end_delim + 1);
  } else {
    end_delim = full_string.find(_T(' '));
    if (end_delim != StringX::npos) {
      first_part = full_string.substr(0, end_delim);
      the_rest = full_string.substr(end_delim + 1);
    } else
      first_part = full_string;
  }

  // tokenize into separate elements using % as the field separator.
  // If this corresponds to a set envrionmental variable - replace it
  // and rebuild the command
  for (StringX::size_type st_startpos = 0;
       st_startpos < first_part.size();
       /* st_startpos advanced in body */) {
    StringX::size_type st_next = first_part.find(_T('%'), st_startpos);
    if (st_next == StringX::npos) {
      sx_temp += first_part.substr(st_startpos);
      break;
    }
    if (st_next > 0) {
      env_var = first_part.substr(st_startpos, st_next - st_startpos);
      size_t mblen = pws_os::wcstombs(NULL, 0, env_var.c_str(), size_t(-1), false);
      unsigned char * mbtemp = new unsigned char[mblen + 1];
      // Finally get result
      size_t tmplen = pws_os::wcstombs((char *)mbtemp, mblen, env_var.c_str(),
                                       size_t(-1), false);
      if (tmplen != mblen) {
        return false;
      }
      mbtemp[mblen - 1] = '\0';
      StringX envar = (pws_os::getenv((char *)mbtemp, false)).c_str();
      if (!envar.empty()) {
        sx_temp += envar;
      } else {
        sx_temp += StringX(_T("%")) + env_var + StringX(_T("%"));
      }
    }
    st_startpos = st_next + 1; // too complex for for statement
  } // tokenization for loop

  // Replace string by rebuilt string
  first_part = sx_temp;

  first_part = getruncmd(first_part, bfound);

  bool rc;
  if (bfound)
    rc = issuecmd(first_part, the_rest, bAutotype);
  else
    rc = issuecmd(full_string, _T(""), bAutotype);

  return rc;
}
Example #3
0
/* Set contrast; val is a scale from 0-31 and configures the Electronic Volume setting.
 * 16 is the default.
 */
void Nokia1202::contrast(uint8_t val)
{
  if (val > 31)  // Input validation
    val = 31;
  issuecmd(STE2007_CMD_ELECTVOL, val, STE2007_MASK_ELECTVOL);
}
Example #4
0
/* STE2007 datasheet lists ONOFF=0, DPYALLPTS=1 as a "Power saver" mode. */
void Nokia1202::powersave(boolean onoff)  // 1 = power-saver mode, 0 = normal mode
{
  issuecmd(STE2007_CMD_DPYALLPTS, onoff, STE2007_MASK_DPYALLPTS);
  issuecmd(STE2007_CMD_ONOFF, !onoff, STE2007_MASK_ONOFF);
}
Example #5
0
/* Just for fun... */
void Nokia1202::invert(boolean onoff)
{
  issuecmd(STE2007_CMD_DPYREV, onoff, STE2007_MASK_DPYREV);
}
Example #6
0
/* Set DDRAM cursor */
void Nokia1202::setxy(uint8_t x, uint8_t y)
{
  issuecmd(STE2007_CMD_LINE, y, STE2007_MASK_LINE);
  issuecmd(STE2007_CMD_COLMSB, x >> 4, STE2007_MASK_COLMSB);
  issuecmd(STE2007_CMD_COLLSB, x, STE2007_MASK_COLLSB);
}